Exemplo n.º 1
0
        /// <summary>
        /// Method for adding a new template - RS
        /// </summary>
        /// <param name="addedTemplate"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <dynamic> AddOrUpdateTemplateAsync(AddTemplateAc addedTemplate, ApplicationUser currentUser)
        {
            if (string.IsNullOrEmpty(addedTemplate.Name.Trim()))
            {
                return new { HasError = true, Message = "Name can't be empty" }
            }
            ;
            else if (string.IsNullOrEmpty(addedTemplate.Format.Trim()))
            {
                return new { HasError = true, Message = "Format can't be empty" }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

                var template = await _iMSDbContext.Templates.FirstOrDefaultAsync(x => x.TemplateFormat ==
                                                                                 EnumHelperService.GetValueFromDescription <TemplateFormatEnum>(addedTemplate.TemplateFormat) && x.InstituteId == instituteId &&
                                                                                 x.TemplateFeatureType == EnumHelperService.GetValueFromDescription <TemplateFeatureEnum>(addedTemplate.TemplateFeatureType) &&
                                                                                 x.TemplateType == EnumHelperService.GetValueFromDescription <TemplateTypeEnum>(addedTemplate.TemplateType));

                if (template == null)
                {
                    template = new Template
                    {
                        CreatedOn           = DateTime.UtcNow,
                        EmailBcc            = addedTemplate.EmailBcc,
                        EmailSubject        = addedTemplate.EmailSubject,
                        To                  = addedTemplate.To,
                        Name                = addedTemplate.Name,
                        TemplateFormat      = EnumHelperService.GetValueFromDescription <TemplateFormatEnum>(addedTemplate.TemplateFormat),
                        TemplateFeatureType = EnumHelperService.GetValueFromDescription <TemplateFeatureEnum>(addedTemplate.TemplateFeatureType),
                        TemplateType        = EnumHelperService.GetValueFromDescription <TemplateTypeEnum>(addedTemplate.TemplateType),
                        Format              = addedTemplate.Format,
                        InstituteId         = instituteId
                    };
                    _iMSDbContext.Templates.Add(template);
                    await _iMSDbContext.SaveChangesAsync();
                }
                else
                {
                    template.EmailBcc     = addedTemplate.EmailBcc;
                    template.EmailSubject = addedTemplate.EmailSubject;
                    template.To           = addedTemplate.To;
                    template.Name         = addedTemplate.Name;
                    template.Format       = addedTemplate.Format;
                    _iMSDbContext.Templates.Add(template);
                    await _iMSDbContext.SaveChangesAsync();
                }
                return(new { HasError = false, Message = "Template updated successfully" });
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddOrUpdateTemplateAsync([FromBody] AddTemplateAc addedTemplate)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            return(Ok(await _templateManagementRepository.AddOrUpdateTemplateAsync(addedTemplate, user)));
        }