Ejemplo n.º 1
0
        public async Task <AlertTemplateDto> GetAsync(string id)
        {
            var alertTemplate = await GetAlertTemplateAsync(id);

            AlertTemplateDto dto = new AlertTemplateDto()
            {
                Id            = alertTemplate.Id,
                ETag          = alertTemplate.ETag,
                GroupId       = alertTemplate.GroupId,
                Culture       = alertTemplate.Culture,
                Section       = alertTemplate.Section,
                Key           = alertTemplate.Key,
                Priority      = alertTemplate.Priority,
                Channel       = alertTemplate.Channel,
                SenderId      = alertTemplate.SenderId,
                Subject       = alertTemplate.Subject,
                Content       = alertTemplate.Content,
                Remark        = alertTemplate.Remark,
                UpdatedOnUtc  = alertTemplate.UpdatedOnUtc,
                UpdatedById   = alertTemplate.UpdatedById,
                UpdatedByName = alertTemplate.UpdatedByName
            };

            return(dto);
        }
Ejemplo n.º 2
0
 private void ValidateDto(AlertTemplateDto dto)
 {
     if ((dto.Channel == SystemKeys.AlertChannelKeys.Email && string.IsNullOrEmpty(dto.Subject)) ||
         (dto.Channel != SystemKeys.AlertChannelKeys.Email && !string.IsNullOrEmpty(dto.Subject)))
     {
         throw new YawnMassageException("UNSUPPORTED_FIELDS_FOR_CHANNEL");
     }
 }
Ejemplo n.º 3
0
        public async Task <DocumentUpdateResultDto> UpdateAsync(AlertTemplateDto dto)
        {
            ValidateDto(dto);
            await CheckForDuplicatesAsync(dto);

            var localisation = await GetAlertTemplateAsync(dto.Id);

            AssignDtoToEntity(localisation, dto);
            return(await _dataContext.ReplaceDocumentAsync(localisation));
        }
Ejemplo n.º 4
0
        public async Task <DocumentUpdateResultDto> CreateAsync(AlertTemplateDto dto)
        {
            ValidateDto(dto);
            await CheckForDuplicatesAsync(dto);

            AlertTemplate alertTemplate = new AlertTemplate();

            AssignDtoToEntity(alertTemplate, dto);
            return(await _dataContext.CreateDocumentAsync(alertTemplate));
        }
Ejemplo n.º 5
0
        private async Task CheckForDuplicatesAsync(AlertTemplateDto dto)
        {
            var exists = await _dataContext.AnyAsync <AlertTemplate>(q => q.Where(d =>
                                                                                  d.Key == dto.Key &&
                                                                                  d.GroupId == dto.GroupId &&
                                                                                  d.Culture == dto.Culture &&
                                                                                  d.Section == dto.Section &&
                                                                                  d.Channel == dto.Channel &&
                                                                                  (dto.Id == null || d.Id != dto.Id)));

            if (exists)
            {
                throw new DocumentDuplicateException();
            }
        }
Ejemplo n.º 6
0
        private void AssignDtoToEntity(AlertTemplate alertTemplate, AlertTemplateDto dto)
        {
            alertTemplate.Section  = dto.Section;
            alertTemplate.Culture  = dto.Culture;
            alertTemplate.Key      = dto.Key;
            alertTemplate.Channel  = dto.Channel;
            alertTemplate.SenderId = dto.SenderId;
            alertTemplate.Subject  = dto.Subject;
            alertTemplate.Content  = dto.Content;
            alertTemplate.Remark   = dto.Remark;
            alertTemplate.Priority = ConfigurationHelper.GetConfigurationPriority(dto.GroupId, dto.Culture, dto.Section);

            if (!string.IsNullOrEmpty(alertTemplate.Id))
            {
                alertTemplate.ETag = dto.ETag;
            }
        }
 public async Task <DocumentUpdateResultDto> Put([FromBody] AlertTemplateDto alertTemplateDto)
 {
     return(await _alertTemplateService.UpdateAsync(alertTemplateDto));
 }