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); }
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"); } }
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)); }
public async Task <DocumentUpdateResultDto> CreateAsync(AlertTemplateDto dto) { ValidateDto(dto); await CheckForDuplicatesAsync(dto); AlertTemplate alertTemplate = new AlertTemplate(); AssignDtoToEntity(alertTemplate, dto); return(await _dataContext.CreateDocumentAsync(alertTemplate)); }
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(); } }
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)); }