public async Task <ActionResult> Edit(string taskItemId, string taskSubitemId, TaskSubitemModel taskSubitemModel) { ViewBag.TaskItemId = taskItemId; var accessToken = Session["MicrosoftAccessToken"] as string; TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken); try { // TODO: Add update logic here TaskSubitem taskSubitem = GetTaskSubitemFromModel(taskItemId, taskSubitemModel); taskSubitem.Id = taskSubitemId; if (taskSubitem.IsCompleted || taskSubitem.TaskStatusId.Equals(((int)TaskStatusEnum.Completed).ToString())) { taskSubitem.TaskStatusId = ((int)TaskStatusEnum.Completed).ToString(); taskSubitem.IsCompleted = true; } await taskSubitemService.UpdateTaskSubitem(taskSubitem); var allTaskSubitems = await taskSubitemService.GetTaskSubitems(taskItemId); if (allTaskSubitems.All(t => t.IsCompleted)) { var taskItemService = new TaskItemService(accessToken); var taskItem = await taskItemService.GetTaskItemById(taskItemId); taskItem.IsCompleted = true; taskItem.TaskStatusId = ((int)TaskStatusEnum.Completed).ToString(); await taskItemService.UpdateTaskItem(taskItem); } return(RedirectToAction("Index", new { taskItemId })); } catch { return(View(taskSubitemModel)); } }
public async Task <ActionResult> Delete(string taskItemId, string taskSubitemId, TaskSubitemModel taskSubitemModel) { var accessToken = Session["MicrosoftAccessToken"] as string; try { // TODO: Add delete logic here TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken); TaskSubitem taskSubitem = await taskSubitemService.GetTaskSubitemById(taskSubitemId); taskSubitem.IsDeleted = true; await taskSubitemService.UpdateTaskSubitem(taskSubitem); return(RedirectToAction("Index", new { taskItemId })); } catch { return(View()); } }