示例#1
0
        public EmailService(IUnitOfWork <IDbConnection, IDbTransaction> unitOfWork, SmtpClient smtpClient,
                            EmailWorkflow emailWorkflow)
            : base(unitOfWork)
        {
            Verify.NotNull(emailWorkflow, nameof(emailWorkflow));
            Verify.NotNull(smtpClient, nameof(smtpClient));

            _emailWorkflow = emailWorkflow;
            _smtpClient    = smtpClient;
        }
示例#2
0
        public EmailWorkflow EmailContent(ProjectWorkflowENT Param)
        {
            NbkDbEntities dbcontext = new NbkDbEntities();
            Users         user      = dbcontext.Users.Where(x => x.Id == Param.InsertedBy).FirstOrDefault();

            dbcontext = new NbkDbEntities();
            var emailDetails                     = new EmailWorkflow();
            EmailTemplateENT    template         = new EmailTemplateCRUD().SelectSingle(Param.EmailTempId);
            ProjectENT          projectDetail    = new ProjectCRUD().SelectSingle(Param.ProjectId);
            ContactENT          customer         = new ContactCRUD().SelectSingle(Convert.ToInt32(projectDetail.CustomerId));
            ContactENT          contactPerson    = new ContactCRUD().SelectSingle(Convert.ToInt32(projectDetail.ContactPersonId));
            BuildingSupplierENT buildingSupplier = new BuildingSupplierCRUD().SelectSingle(Convert.ToInt32(projectDetail.BuildingSupplierId));
            CompanyProfileENT   companyProfile   = new CompanyCRUD().SelectAll();

            emailDetails.EmailFrom = companyProfile.senderEmailAddress;
            emailDetails.EmailTo   = customer.Email;
            if (Param.EmailTempId == 1)
            {
                int   price           = 0;
                float priceWithGst    = 0f;
                var   ProjectServices = new ProjectCRUD().ListOfProjectServices(Param.ProjectId);
                if (ProjectServices != null)
                {
                    foreach (var item in ProjectServices)
                    {
                        price = price + Convert.ToInt32(item.Price);
                    }
                }

                //template.Template = template.Template.Replace("#ansvarlig#", projectDetail.Contact.Name);
                template.Template = template.Template.Replace("#priceWithoutGst#", price.ToString());
                if (price != 0)
                {
                    float remainder = price * 0.25f;
                    priceWithGst = price + remainder;
                }
                template.Template = template.Template.Replace("#priceWithGst#", priceWithGst.ToString());
            }
            dbcontext = new NbkDbEntities();
            string InspectorName = "";

            if (Param.EmailTempId == 7 || Param.EmailTempId == 8)
            {
                if (projectDetail.InspectorId != null)
                {
                    InspectorName = dbcontext.Users.Where(x => x.Id == projectDetail.InspectorId).Select(x => x.FullName).FirstOrDefault();
                }
                template.Template = template.Template.Replace("#InspectorName#", InspectorName);
            }
            if (projectDetail.CustomerId != null)
            {
                template.Template = template.Template.Replace("#anvarligSokerCompany#", contactPerson.CompanyName);
                template.Template = template.Template.Replace("#ansvarlig#", contactPerson.Name);
            }
            else
            {
                template.Template = template.Template.Replace("#anvarligSokerCompany#", "");
                template.Template = template.Template.Replace("#ansvarlig#", "");
            }
            template.Template = template.Template.Replace("#PhoneNumber#", user.ContactNo);
            template.Template = template.Template.Replace("#Email#", user.Email);
            template.Template = template.Template.Replace("#Name#", user.FullName);
            template.Template = template.Template.Replace("#Designation#", user.Designation);
            template.Template = template.Template.Replace("#Address#", projectDetail.Address);
            template.Template = template.Template.Replace("#Description#", projectDetail.Description);
            template.Template = template.Template.Replace("#ProjectTitle#", projectDetail.Title);
            template.Template = template.Template.Replace("#CustomerName#", customer.Name);
            template.Template = template.Template.Replace("#CustomerPhone#", customer.ContactNo);
            template.Template = template.Template.Replace("#BuildingSupplier#", buildingSupplier.Title);

            emailDetails.Content = template.Template;
            emailDetails.Title   = EmailSubjectReplacements(template, projectDetail, customer, contactPerson, buildingSupplier, user);
            return(emailDetails);
        }