public async Task <OutputResponse> Add(NotificationChannelDTO notificationChannel) { var isFound = await _context.NotificationChannels.AnyAsync(x => x.ChannelName.ToLower() == notificationChannel.ChannelName.ToLower()); if (isFound) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification channel name already exist, duplicates not allowed" }); } var mappedNotificationChannel = new AutoMapperHelper <NotificationChannelDTO, NotificationChannels>().MapToObject(notificationChannel); mappedNotificationChannel.RowAction = "I"; mappedNotificationChannel.DateCreated = DateTime.UtcNow; await _context.NotificationChannels.AddAsync(mappedNotificationChannel); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.AddNewSuccess }); }
public async Task <IActionResult> Update([FromBody] NotificationChannelDTO notificationChannel) { var outputHandler = await _service.Update(notificationChannel); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Ok(outputHandler.Message)); }
public async Task <OutputResponse> Update(NotificationChannelDTO notificationChannel) { var notificationChannelToUpdate = await _context.NotificationChannels.FirstOrDefaultAsync(x => x.ChannelId.Equals(notificationChannel.ChannelId)); if (notificationChannelToUpdate == null) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification channel specified does not exist, update cancelled" }); } var isFound = await _context.NotificationChannels.Where(x => x.ChannelId != notificationChannel.ChannelId).AnyAsync(x => x.ChannelName.ToLower() == notificationChannel.ChannelName.ToLower()); if (isFound) { return(new OutputResponse { IsErrorOccured = true, Message = "Notification channel name already exist, duplicates not allowed" }); } //update details notificationChannelToUpdate.ChannelName = notificationChannel.ChannelName; notificationChannelToUpdate.RowAction = "U"; notificationChannelToUpdate.ModifiedBy = notificationChannel.CreatedBy; notificationChannelToUpdate.DateModified = DateTime.UtcNow; await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.UpdateSuccess }); }