public async Task AddTask(string userId, TrackerTaskModel task) { if ((await this._context.Users.FindAsync(userId)) is User user) { TrackerTask taskEntity = new TrackerTask(); taskEntity.Title = task.Title; taskEntity.Description = task.Description; taskEntity.TaskStatus = task.Status; taskEntity.User = user; this._context.TrackerTasks.Add(taskEntity); await this._context.SaveChangesAsync(); } else { throw new BusinessException("Invalid user Id"); } }
public async Task UpdateTask(string userId, TrackerTaskModel trackerTask) { if ((await this._context.Users.FindAsync(userId)) is User user) { if (user.Tasks.FirstOrDefault(t => t.Id == trackerTask.Id) is TrackerTask task) { task.TaskStatus = trackerTask.Status; task.Title = trackerTask.Title; task.Description = trackerTask.Description; await this._context.SaveChangesAsync(); } else { throw new BusinessException("Invalid task Id"); } } else { throw new BusinessException("Invalid user Id"); } }
public async Task <IActionResult> UpdateTask([FromForm] TrackerTaskModel viewModel) { await this._trackerService.UpdateTask(this._userManager.GetUserId(this.User), viewModel); return(RedirectToAction(nameof(Index))); }