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));
        }
示例#2
0
        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);
            }
        }