我需要帮助来重构此代码示例的某些部分,if (_obj is Application)
因此这将是通用的。
public override void Body(object _obj, object _objInPreviousState)
{
if (_obj != null)
{
string Message = "";
string Subject = "";
if (_objInPreviousState == null)
{
var emailParams = this.Param as Dictionary<string, string>;
if (emailParams != null)
{
Message = emailParams["Message"];
Subject = emailParams["Subject"];
}
}
var emails = userRepository().GetForRoles("RM").Select(c => c.Email);
if (_obj is Application)
{
var app = (Application)_obj;
var appInPreviousState = _objInPreviousState as Application;
if (appInPreviousState == null)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), Message, Subject);
}
else if (app.ApplicationStatus != appInPreviousState.ApplicationStatus)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), "Application: " + app.ID + " changed decision status: " + Enum.GetName(typeof(AppStatus), app.ApplicationStatus), "Check following application: " + app.ID);
}
}
else if (_obj is Product)
{
var product = (Product)_obj;
var prodInPreviousState = _objInPreviousState as Product;
if (prodInPreviousState == null)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), Message, Subject);
}
else if (product.ProductStatusType != prodInPreviousState.ProductStatusType)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), "Product: " + product.ID + " for application " + product.ApplicationID + " changed decision status: " + Enum.GetName(typeof(AppStatus), product.ProductStatusType), "Check following application: " + product.ApplicationID);
}
}
else if (_obj is CES)
{
var ces = (CES)_obj;
var cesInPreviousState = _objInPreviousState as CES;
if (cesInPreviousState == null)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), Message, Subject);
}
else if (ces.Status != cesInPreviousState.Status)
{
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), "CES for application " + ces.ApplicationID + " changed decision status: " + Enum.GetName(typeof(CesStatuses), ces.Status), "Check following application: " + ces.ApplicationID);
}
}
else if (_obj is Comment)
{
var comment = (Comment)_obj;
emailService().SendEmails("aps@somedomain.com", emails.ToArray(), "Comment for the following application: " + comment.ApplicationID + " with message: " + comment.Message + " on date: " + comment.CreatedDate, "Comment for the following application: " + comment.ApplicationID);
}
mLog.InfoLine("Sendet Email");
}
}