Example #1
0
        private static string GetTemplate(EmailVariables template, Dictionary <string, object> data, CultureInfo culture = null, string language = "")
        {
            string templateName = template.ToString();

            if (!String.IsNullOrEmpty(language))
            {
                templateName += language;
            }

            var templatePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath(SettingsManager.Email.Templates.Path), templateName.ToString() + SettingsManager.Email.Templates.Type);

            return(TemplateEngine.ProcessTemplate(templatePath, data, culture));
        }
Example #2
0
        public void AddParttimerSalary(ServiceRequestModel <ParttimerSalaryViewModel> serviceRequestModel)
        {
            var employee =
                _genericUnitOfWork.GetRepository <ParttimerEmployee, Guid>()
                .GetAll()
                .SingleOrDefault(c => c.Id == serviceRequestModel.Model.ParttimerEmployeeId);

            if (employee != null)
            {
                if (employee.JoinedDate.Year >= serviceRequestModel.Model.SalaryYear && employee.JoinedDate.Month > serviceRequestModel.Model.SalaryMonth)
                {
                    throw new ArgumentNullException($"Join date is greater than salary date", innerException: null);
                }
            }
            var repo         = _genericUnitOfWork.GetRepository <ParttimerSalary, Guid>();
            var salaryExists = repo.GetAll().Any(c => c.ParttimerEmployeeId == serviceRequestModel.Model.ParttimerEmployeeId && c.SalaryYear == serviceRequestModel.Model.SalaryYear && c.SalaryMonth == serviceRequestModel.Model.SalaryMonth && c.ProcessingStatus != ProcessingStatus.Rejected);

            if (salaryExists)
            {
                throw new ArgumentNullException($"Parttimer salary with Year '{serviceRequestModel.Model.SalaryYear}' and Month '{serviceRequestModel.Model.SalaryMonth}' already exists in the system", innerException: null);
            }
            var mapped = _objectMapper.Map <ParttimerSalaryViewModel, ParttimerSalary>(serviceRequestModel.Model);

            mapped.Id               = Guid.NewGuid();
            mapped.CreatedById      = serviceRequestModel.CurrentUserId.Value;
            mapped.Step             = 1;
            mapped.ProcessingStatus = ProcessingStatus.Pending;
            mapped.CreatedDate      = GeneralService.CurrentDate;
            repo.Add(mapped);
            _genericUnitOfWork.SaveChanges();

            var           sql = $@"select distinct Email from [ParttimerSalary] ps 
                        inner join [ParttimerEmployee] pe on pe.Id = ps.ParttimerEmployeeId 
                        inner join DocumentProcessingSetting dps on dps.Step = ps.Step and dps.KeyId = pe.ParttimerType
                        inner join [UserRole] ur on ur.RoleId = dps.RoleId
                        inner join [User] u on u.Id = ur.UserId
                        inner join [Role] r on r.Id = dps.RoleId
                        inner join [UserBranch] ub on ub.UserId = u.Id and (r.RoleType = 2 or ub.BranchId = pe.BranchId)
                        where ps.Id = '{mapped.Id}' and ps.Step = 1 and DocumentType = {(int)DocumentType.Parttimer} and DocumentProcessorType=1";
            List <string> firstProcessorEmails = _genericUnitOfWork.SqlQuery <string>(sql).ToList();

            if (firstProcessorEmails.Any())
            {
                var emailRequest = new EmailVariables();
                firstProcessorEmails.ForEach(x => emailRequest.To.Add(new System.Net.Mail.MailAddress(x)));
                _emailComposer.SendParttimerSalaryProcessedEmail(emailRequest);
            }
        }
 public async void SendGeneralEmail(EmailVariables emailRequest, bool appendFooter = true)
 {
     using (MailMessage mailMessage = new MailMessage())
     {
         mailMessage.IsBodyHtml = true;
         mailMessage.Body       = emailRequest.Body + (appendFooter ? _emailer.RenderTemplate("GeneralMailFooter") : string.Empty);
         mailMessage.Subject    = emailRequest.Subject;
         if (emailRequest.From != null)
         {
             mailMessage.From = emailRequest.From;
         }
         emailRequest.To.ToList().ForEach(mailMessage.To.Add);
         emailRequest.CC.ToList().ForEach(mailMessage.CC.Add);
         await _emailer.SendEmailAsync(mailMessage);
     }
 }
 public async void SendCircularBOASEmail(EmailVariables emailRequest)
 {
     using (MailMessage mailMessage = new MailMessage())
     {
         mailMessage.IsBodyHtml = true;
         mailMessage.Body       = emailRequest.Body;
         mailMessage.Subject    = "MBOS : Circular Email From BOAS.";
         if (emailRequest.From != null)
         {
             mailMessage.From = emailRequest.From;
         }
         emailRequest.To.ToList().ForEach(mailMessage.To.Add);
         emailRequest.CC.ToList().ForEach(mailMessage.CC.Add);
         await _emailer.SendEmailAsync(mailMessage);
     }
 }
        public async void SendParttimerSalaryProcessedEmail(EmailVariables emailRequest, bool appendFooter = true)
        {
            var body = _emailer.RenderTemplate(EmailTemplate.ParttimerSalaryProcessing, null) + (appendFooter ? _emailer.RenderTemplate("GeneralMailFooter") : string.Empty);

            using (MailMessage mailMessage = new MailMessage())
            {
                mailMessage.Body       = body;
                mailMessage.IsBodyHtml = true;
                mailMessage.Subject    = "MBOS : Parttimer salary processed.";
                if (emailRequest.From != null)
                {
                    mailMessage.From = emailRequest.From;
                }
                emailRequest.To.ToList().ForEach(mailMessage.To.Add);
                emailRequest.CC.ToList().ForEach(mailMessage.CC.Add);
                await _emailer.SendEmailAsync(mailMessage);
            }
        }
Example #6
0
        private static string GetTemplate(EmailVariables template, Dictionary<string, object> data, CultureInfo culture = null, string language = "")
        {
            string templateName = template.ToString();
            if (!String.IsNullOrEmpty(language))
                templateName += language;

            var templatePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath(SettingsManager.Email.Templates.Path), templateName.ToString() + SettingsManager.Email.Templates.Type);

            return TemplateEngine.ProcessTemplate(templatePath, data, culture);
        }