コード例 #1
0
        public async Task <bool> UpdateNotification(int id, NotificationSaveViewModel model)
        {
            var notification = await this.context.Notifications
                               .FirstOrDefaultAsync(t => t.Id.Equals(id));

            if (notification == null)
            {
                return(await Task.FromException <bool>(
                           new Exception($"No entry found for the id {id}, {HttpStatusCode.NotFound}")));
            }

            notification.Update(model.Text, model.IsStickied);

            return(await this.context.SaveChangesAsync() > 0);
        }
コード例 #2
0
        public async Task <NotificationViewModel> CreateNotification(NotificationSaveViewModel model)
        {
            var lastNotification = await this.context.Notifications
                                   .AsNoTracking()
                                   .OrderByDescending(t => t.Id)
                                   .FirstOrDefaultAsync();

            var newNotification = new Notification(model.Text, lastNotification?.OrderIndex ?? 1, model.IsStickied);

            await this.context.AddAsync(newNotification);

            await this.context.SaveChangesAsync();

            return(this.mapper.Map <NotificationViewModel>(newNotification));
        }
コード例 #3
0
 public async Task <IActionResult> UpdateNotification(
     [FromRoute] int id,
     [FromBody] NotificationSaveViewModel model)
 {
     return(this.Ok(await this.notificationService.UpdateNotification(id, model)));
 }
コード例 #4
0
 public async Task <IActionResult> CreateNotification([FromBody] NotificationSaveViewModel model)
 {
     return(this.Ok(await this.notificationService.CreateNotification(model)));
 }