public async Task <ActionResult> Post(NotificationCreationDTO notificationCreationDTO) { var notification = await notificationRepository.AddUserNotification(notificationCreationDTO); if (notification == null) { return(BadRequest()); } var dto = mapper.Map <NotificationDTO>(notification); return(new CreatedAtActionResult(nameof(GetNotification), "Notifications", new { id = notification.Id }, dto)); }
public async Task <Notification> AddUserNotification(NotificationCreationDTO notification) { try { var entity = mapper.Map <Notification>(notification); applicationDbContext.Add(entity); await applicationDbContext.SaveChangesAsync(); return(entity); } catch (DbUpdateException) { return(null); } }