Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:37:21+00:00 2026-06-02T14:37:21+00:00

I need help to refactor some parts of this code example from where if

  • 0

I need help to refactor some parts of this code example from where if (_obj is Application) so this will be generic.

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");
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:37:22+00:00Added an answer on June 2, 2026 at 2:37 pm

    You should probably use some interfaces, I’ve not given you the full code but a pattern to follow.

    interface IStatusItem
    {
       void SendEmails(EmailService service);
    }
    
    public class Product : IStatusItem
    {
       public void SendEmails(EmailService service)
       {
          // Send Email
       }
    }
    
    public class Application : IStatusItem
    {
       public void SendEmails(EmailService service)
       {
          // Send Email
       }
    }
    

    Then your main code doesn’t need all the if blocks. It just calls through to the implementation on the instance of the IStatusItem. Obviously you need to add the previous state in there.

    override void Body(object _obj, object _objInPreviousState)
    {
       IStatusItem sItem = obj as IStatusItem;
       if(sItem != null)
          sItem.SendEmails(emailService());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help to convert code from asp control to input type to fetch file
Need help with deleting call log from multi numbers, using the following code i
Need help on this following code. the problem is it only trigger the last
Need help writing a script downloads data from google insight using c# this is
I need help with some programming logic... I need to loop this method to
need help regarding USSD Gateway. I have to develop an app, which will directly
I need help with a function so that I can upload a picture from
I'm a newbie to programming and need some help with the set of fixers
Please help me to refactore this Javascript code. There is big form for scheduled
Need help. I have Graph API code that uses an auth token with offline

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.