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); }
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)); }
public async Task <IActionResult> UpdateNotification( [FromRoute] int id, [FromBody] NotificationSaveViewModel model) { return(this.Ok(await this.notificationService.UpdateNotification(id, model))); }
public async Task <IActionResult> CreateNotification([FromBody] NotificationSaveViewModel model) { return(this.Ok(await this.notificationService.CreateNotification(model))); }