private void SendApprovalRejectionEmailForCommissionRequest(CommissionRequestModel model)
        {
            var emailModel = new SendEmailApprovalModel();

            emailModel.HelpLink = "mailto:[email protected]";

            emailModel.Subject = string.Format("The status of a DPO Commission request has changed");

            emailModel.Reason       = model.ResponseNotes;
            emailModel.ProjectId    = model.ProjectId;
            emailModel.ProjectName  = model.Project.Name;
            emailModel.QuoteTitle   = model.Quote.Title;
            emailModel.TotalNet     = model.Quote.TotalNet;
            emailModel.Approved     = (model.CommissionRequestStatusTypeId == (byte)CommissionRequestStatusTypeEnum.Approved);
            emailModel.ModifierName = model.CommissionRequestStatusModifiedBy;


            UserSessionModel user = new UserSessionModel();

            if (model.ProjectOwnerId != null)
            {
                user = new AccountServices().GetUserSessionModel(model.ProjectOwnerId.Value).Model as UserSessionModel;
            }
            else
            {
                user = new AccountServices().GetUserSessionModel(model.Project.OwnerId.Value).Model as UserSessionModel;
            }

            emailModel.ProjectOwnerName = user.FirstName + " " + user.LastName;
            emailModel.ProjectDate      = model.Project.ProjectDate;

            var business = new BusinessServices().GetBusinessModel(user, user.BusinessId, false).Model as BusinessModel;

            emailModel.BusinessName                  = business.BusinessName;
            emailModel.RequestedCommission           = model.RequestedCommissionTotal;
            emailModel.ApprovedCommission            = model.ApprovedCommissionTotal;
            emailModel.ApprovedTotalCommission       = model.ApprovedCommissionPercentage;
            emailModel.RequestedCommissionPercentage = model.RequestedCommissionPercentage;
            emailModel.ApprovedCommissionPercentage  = model.ApprovedCommissionPercentage;
            emailModel.RequestedMultiplier           = model.RequestedMultiplier;
            emailModel.ApprovedMultiplier            = model.ApprovedMultiplier;
            emailModel.ApprovedTotalNet              = model.TotalRevised;
            emailModel.TotalNet  = model.Quote.TotalNet;
            emailModel.TotalList = model.Quote.TotalList;

            emailModel.From = new MailAddress(Utilities.Config("dpo.sys.email.commissionrequest"), "DPO Project Desk");

            if (model.ShouldSendEmail == true)
            {
                emailModel.To.Add(new MailAddress(user.Email, user.DisplayName));
            }

            emailModel.To.Add(emailModel.From);

            if (!string.IsNullOrEmpty(business.AccountManagerEmail))
            {
                emailModel.To.Add(new MailAddress(business.AccountManagerEmail));
            }

            if (!string.IsNullOrEmpty(business.AccountOwnerEmail))
            {
                emailModel.To.Add(new MailAddress(business.AccountOwnerEmail));
            }

            List <string> emailsList = new List <string>();

            if (model.EmailsList != null && model.EmailsList.Length > 0)
            {
                emailsList = model.EmailsList.ToString().Split(',', ';').ToList();
            }

            foreach (string email in emailsList)
            {
                if (String.IsNullOrWhiteSpace(email))
                {
                    continue;
                }
                emailModel.To.Add(new MailAddress(email.Trim()));
            }

            emailModel.RenderTextVersion = true;
            emailModel.BodyTextVersion   = RenderView(this, "SendEmailCommissionRequestApproval", emailModel);

            emailModel.RenderTextVersion = false;
            emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailCommissionRequestApproval", emailModel);

            new EmailServices().SendEmail(emailModel);
        }
Exemple #2
0
        private void SendApprovalRejectionEmail(OrderViewModelLight orderVMLight)
        {
            UserServices userSerivce = new UserServices();

            var user = new UserSessionModel();

            #pragma warning disable CS0472 // The result of the expression is always 'true' since a value of type 'long' is never equal to 'null' of type 'long?'
            if (orderVMLight.ProjectOwnerId != null)
            #pragma warning restore CS0472 // The result of the expression is always 'true' since a value of type 'long' is never equal to 'null' of type 'long?'
            {
                user = new AccountServices().GetUserSessionModel(orderVMLight.ProjectOwnerId).Model as UserSessionModel;
            }

            var orderEmailModel = new SendEmailApprovalModel();
            orderEmailModel.HelpLink = "mailto:[email protected]";

            orderEmailModel.Subject = string.Format("The status of an Order request has changed");

            orderEmailModel.Reason           = orderVMLight.Comments;
            orderEmailModel.ProjectId        = orderVMLight.ProjectId;
            orderEmailModel.ProjectName      = orderVMLight.ProjectName;
            orderEmailModel.QuoteTitle       = orderVMLight.QuoteTitle;
            orderEmailModel.ERPOrderNumber   = (orderVMLight.ERPOrderNumber != null) ? orderVMLight.ERPOrderNumber : string.Empty;
            orderEmailModel.ERPInvoiceNumber = (orderVMLight.ERPInvoiceNumber != null) ? orderVMLight.ERPInvoiceNumber : string.Empty;
            orderEmailModel.ERPPOKey         = (orderVMLight.ERPPOKey != null) ? orderVMLight.ERPPOKey.Value : 0;
            orderEmailModel.ERPInvoiceDate   = (orderVMLight.ERPInvoiceDate != null) ? orderVMLight.ERPInvoiceDate.Value : DateTime.Now;
            orderEmailModel.ERPOrderDate     = (orderVMLight.ERPOrderDate != null) ? orderVMLight.ERPOrderDate.Value : DateTime.Now;
            #pragma warning disable CS0472 // The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
            orderEmailModel.TotalNet = (orderVMLight.TotalNetPrice != null) ? orderVMLight.TotalNetPrice : 0;
            #pragma warning restore CS0472 // The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
            orderEmailModel.Approved     = (orderVMLight.OrderStatusTypeId == OrderStatusTypeEnum.InProcess);
            orderEmailModel.ModifierName = (user != null) ? user.FirstName + " " + user.LastName : orderVMLight.UpdatedByUserIdStr;

            orderEmailModel.ProjectOwnerName = (orderVMLight.ProjectOwner != null) ? orderVMLight.ProjectOwner : user.FirstName + " " + user.LastName;
            orderEmailModel.ProjectDate      = (orderVMLight.ProjectDate != null) ? orderVMLight.ProjectDate : DateTime.Now;

            var business = new BusinessServices().GetBusinessModel(user, user.BusinessId, false).Model as BusinessModel;
            orderEmailModel.BusinessName = (business != null && business.BusinessName != null) ? business.BusinessName : "No Business Name";

            orderEmailModel.From = new MailAddress(Utilities.Config("dpo.sys.email.discountrequest"), "DPO Project Desk");

            orderEmailModel.To.Add(orderEmailModel.From);

            if (!string.IsNullOrEmpty(business.AccountManagerEmail))
            {
                orderEmailModel.To.Add(new MailAddress(business.AccountManagerEmail));
            }

            if (!string.IsNullOrEmpty(business.AccountOwnerEmail))
            {
                orderEmailModel.To.Add(new MailAddress(business.AccountOwnerEmail));
            }

            orderEmailModel.RenderTextVersion = true;
            orderEmailModel.BodyTextVersion   = RenderView(this, "SendEmailOrderApproval", orderEmailModel);

            orderEmailModel.RenderTextVersion = false;
            orderEmailModel.BodyHtmlVersion   = RenderView(this, "SendEmailOrderApproval", orderEmailModel);

            new EmailServices().SendEmail(orderEmailModel);
        }
        private void SendApprovalRejectionEmail(DiscountRequestModel model)
        {
            string root        = Server.MapPath("~");
            string parent      = System.IO.Path.GetDirectoryName(root);
            string grandParent = System.IO.Path.GetDirectoryName(parent);

            string _last5DigitsOfProjectId = model.ProjectId.ToString().Substring(model.ProjectId.ToString().Length - 5);

            string DARPdfFile = "Daikin City Discount Request " +
                                DateTime.Now.ToString("MM-dd-yyyy") +
                                "-" +
                                _last5DigitsOfProjectId + ".pdf";

            string DARPdfFilePath = grandParent + "/CustomerDataFiles/DiscountRequestFiles/" + model.QuoteId + "/" + DARPdfFile;

            var emailModel = new SendEmailApprovalModel();

            emailModel.HelpLink = "mailto:[email protected]";

            emailModel.Subject = string.Format("The status of a DPO Discount request has changed");

            emailModel.Reason       = model.ResponseNotes;
            emailModel.ProjectId    = model.ProjectId;
            emailModel.ProjectName  = model.Project.Name;
            emailModel.QuoteTitle   = model.Quote.Title;
            emailModel.TotalNet     = model.Quote.TotalNet;
            emailModel.Approved     = (model.DiscountRequestStatusTypeId == (byte)DiscountRequestStatusTypeEnum.Approved);
            emailModel.ModifierName = model.DiscountRequestStatusModifiedBy;

            //only sent Dar attachment when approved Dar
            if (model.DiscountRequestStatusTypeId != (byte)DiscountRequestStatusTypeEnum.Rejected &&
                model.DiscountRequestStatusTypeId != (byte)DiscountRequestStatusTypeEnum.Deleted)
            {
                emailModel.DARAttachmentFile     = DARPdfFilePath;
                emailModel.DARAttachmentFileName = DARPdfFile;
            }

            UserSessionModel user = new UserSessionModel();

            if (model.ProjectOwnerId != null)
            {
                user = new AccountServices().GetUserSessionModel(model.ProjectOwnerId.Value).Model as UserSessionModel;
            }
            else
            {
                user = new AccountServices().GetUserSessionModel(model.Project.OwnerId.Value).Model as UserSessionModel;
            }

            emailModel.ProjectOwnerName = user.FirstName + " " + user.LastName;
            emailModel.ProjectDate      = model.Project.ProjectDate;

            var business = new BusinessServices().GetBusinessModel(user, user.BusinessId, false).Model as BusinessModel;

            emailModel.BusinessName      = business.BusinessName;
            emailModel.RequestedDiscount = model.RequestedDiscount;
            emailModel.ApprovedDiscount  = model.ApprovedDiscount;

            emailModel.From = new MailAddress(Utilities.Config("dpo.sys.email.discountrequest"), "DPO Project Desk");

            if (model.ShouldSendEmail == true)
            {
                emailModel.To.Add(new MailAddress(user.Email, user.DisplayName));
            }

            emailModel.To.Add(emailModel.From);

            if (!string.IsNullOrEmpty(business.AccountManagerEmail))
            {
                emailModel.To.Add(new MailAddress(business.AccountManagerEmail));
            }

            if (!string.IsNullOrEmpty(business.AccountOwnerEmail))
            {
                emailModel.To.Add(new MailAddress(business.AccountOwnerEmail));
            }

            List <string> emailsList = new List <string>();

            if (model.EmailsList != null && model.EmailsList.Length > 0)
            {
                emailsList = model.EmailsList.ToString().Split(',', ';').ToList();
            }

            foreach (string email in emailsList)
            {
                if (String.IsNullOrWhiteSpace(email))
                {
                    continue;
                }
                emailModel.To.Add(new MailAddress(email.Trim()));
            }

            emailModel.RenderTextVersion = true;
            emailModel.BodyTextVersion   = RenderView(this, "SendEmailDiscountRequestApproval", emailModel);

            emailModel.RenderTextVersion = false;
            emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailDiscountRequestApproval", emailModel);

            new EmailServices().SendEmail(emailModel);
        }