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()); } }
// GET: TaskSubitem/Delete/5 public async Task <ActionResult> Delete(string taskItemId, string taskSubitemId) { ViewBag.TaskItemId = taskItemId; var accessToken = Session["MicrosoftAccessToken"] as string; TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken); TaskSubitem taskSubitem = await taskSubitemService.GetTaskSubitemById(taskSubitemId); TaskSubitemModel taskSubitemModel = GetTaskSubitemModel(taskSubitem); var statuses = await taskSubitemService.GetAvailableTaskStatuses(); taskSubitemModel.Status = statuses.Single(s => s.Id == taskSubitem.TaskStatusId).Status; //ViewBag.StatusID = new SelectList(statuses, "Id", "Status", status.Id); var tasks = new ObservableCollection <TaskSubitem>() { new TaskSubitem() }; var items = await taskSubitemService.GetTaskSubitems(taskItemId); if (!String.IsNullOrWhiteSpace(taskSubitem.PredecessorId)) { taskSubitemModel.Predecessor = await taskSubitemService.GetTaskSubitemNameByTaskSubitemId(taskSubitem.PredecessorId); } else { taskSubitemModel.Predecessor = ""; } if (!String.IsNullOrWhiteSpace(taskSubitem.SuccessorId)) { taskSubitemModel.Successor = await taskSubitemService.GetTaskSubitemNameByTaskSubitemId(taskSubitem.SuccessorId); } else { taskSubitemModel.Successor = ""; } UserService userService = new UserService(accessToken); if (!String.IsNullOrWhiteSpace(taskSubitem.ExecutorId)) { taskSubitemModel.Executor = (await userService.GetUserById(taskSubitem.ExecutorId)).FullName; } else { taskSubitemModel.Executor = ""; } if (await AccessAdmin(taskItemId)) { return(View(taskSubitemModel)); } else { return(View("AccessDenied")); } }
// GET: TaskSubitem/Edit/5 public async Task <ActionResult> Edit(string taskItemId, string taskSubitemId) { ViewBag.TaskItemId = taskItemId; string accessToken = Session["MicrosoftAccessToken"] as string; TaskSubitemService taskSubitemService = new TaskSubitemService(accessToken); TaskSubitem taskSubitemInfo = await taskSubitemService.GetTaskSubitemById(taskSubitemId); TaskSubitemModel taskSubitemModel = GetTaskSubitemModel(taskSubitemInfo); var statuses = await taskSubitemService.GetAvailableTaskStatuses(); var status = statuses.Single(s => s.Id == taskSubitemInfo.TaskStatusId); ViewBag.StatusID = new SelectList(statuses, "Id", "Status", status.Id); var tasks = new ObservableCollection <TaskSubitem>() { new TaskSubitem() }; var items = await taskSubitemService.GetTaskSubitems(taskItemId); items.ForEach(i => tasks.Add(i)); if (String.IsNullOrWhiteSpace(taskSubitemInfo.PredecessorId)) { ViewBag.PredecessorID = new SelectList(tasks, "Id", "Name", new TaskSubitem()); } else { ViewBag.PredecessorID = new SelectList(tasks, "Id", "Name", taskSubitemInfo.PredecessorId); } if (String.IsNullOrWhiteSpace(taskSubitemInfo.SuccessorId)) { ViewBag.SuccessorID = new SelectList(tasks, "Id", "Name", new TaskSubitem()); } else { ViewBag.SuccessorID = new SelectList(tasks, "Id", "Name", taskSubitemInfo.SuccessorId); } UserService userService = new UserService(accessToken); TaskItemService taskItemService = new TaskItemService(accessToken); UserGroupService userGroup = new UserGroupService(accessToken); var itemInfo = await taskItemService.GetTaskItemById(taskItemId); var groupInfo = await userGroup.GetUserGroupTableForGroup(itemInfo.GroupId); var userInGroup = groupInfo.Select(u => u.UserId); List <User> userProp = new List <User>(); userProp.Add(new User()); foreach (var usrId in userInGroup) { var user = await userService.GetUserById(usrId); userProp.Add(user); } var userInternalId = await userService.GetUserInternalId(Session["UserId"] as string, UserDomainEnum.Microsoft); //var defaultExecutor = userProp.Single(i => i.Id == userInternalId); if (String.IsNullOrWhiteSpace(taskSubitemInfo.ExecutorId)) { ViewBag.ExecutorID = new SelectList(userProp, "Id", "FullName", new TaskSubitem()); } else { ViewBag.ExecutorID = new SelectList(userProp, "Id", "FullName", taskSubitemInfo.ExecutorId); } if (await AccessAdmin(taskItemId)) { return(View(taskSubitemModel)); } else if (await AccessEditor(taskItemId)) { return(View(taskSubitemModel)); } else { return(View("AccessDenied")); } }