// GET: TaskItem/Delete/5 public async Task <ActionResult> Delete(string taskItemId) { string accessToken = Session["MicrosoftAccessToken"] as string; var taskItemService = new TaskItemService(accessToken); var taskItem = await taskItemService.GetTaskItemById(taskItemId); var taskItemModel = GetTaskItemModel(taskItem); var statuses = await taskItemService.GetAvailableTaskStatuses(); taskItemModel.Status = statuses.Single(s => s.Id == taskItem.TaskStatusId).Status; var groupService = new GroupService(accessToken); taskItemModel.GroupName = await groupService.GroupNameByGroupId(taskItem.GroupId); if (await AccessAdmin(taskItem.GroupId)) { return(View(taskItemModel)); } else { return(View("AccessDenied")); } }
// GET: TaskItem public async Task <ActionResult> Index(string sortOrder, string searchString) { string accessToken = Session["MicrosoftAccessToken"] as string; UserService userService = new UserService(accessToken); var userId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft); if (String.IsNullOrWhiteSpace(userId)) { return(RedirectToAction("Login", "Account")); } TaskItemService taskItemService = new TaskItemService(accessToken); var taskItems = await taskItemService.GetTaskItems(userId); var groupIds = taskItems.Select(t => t.GroupId).Distinct(); Dictionary <string, string> groups = new Dictionary <string, string>(); foreach (var groupId in groupIds) { GroupService groupService = new GroupService(accessToken); string groupName = await groupService.GroupNameByGroupId(groupId); groups.Add(groupId, groupName); } var taskStatuses = await taskItemService.GetAvailableTaskStatuses(); var tasks = new List <TaskItemModel>(); foreach (var taskItem in taskItems) { TaskItemModel taskItemModel = GetTaskItemModel(taskItem); taskItemModel.GroupName = groups[taskItemModel.GroupId]; taskItemModel.Status = taskStatuses.Single(s => s.Id == taskItemModel.StatusId).Status; tasks.Add(taskItemModel); } if (!String.IsNullOrWhiteSpace(searchString)) { tasks = tasks.Where(t => t.Name.Contains(searchString) || t.GroupName.Contains(searchString)).ToList(); } ViewBag.TaskNameParam = String.IsNullOrEmpty(sortOrder) ? "taskName_desc" : ""; ViewBag.GroupNameParam = sortOrder == "groupName" ? "groupName_desc" : "groupName"; ViewBag.IsCompletedParam = sortOrder == "isCompleted" ? "isCompleted_desc" : "isCompleted"; ViewBag.StatusParam = sortOrder == "status" ? "status_desc" : "status"; ViewBag.StartDateParam = sortOrder == "startDate" ? "startDate_desc" : "startDate"; ViewBag.EndDateParam = sortOrder == "endDate" ? "endDate_desc" : "endDate"; tasks = OrderTasks(sortOrder, tasks); return(View(tasks)); }
// GET: TaskItem/Create public async Task <ActionResult> Create() { string accessToken = Session["MicrosoftAccessToken"] as string; var groupService = new GroupService(accessToken); var groups = await groupService.GetGroupsAvailableForUserWhereUserIsAdmin(Session["UserId"] as string); var defaultGroup = groups.SingleOrDefault(g => g.GroupName.Contains("Default group for user:"******"Id", "GroupNameTruncated", defaultGroup.Id); ViewBag.StatusID = new SelectList(statuses, "Id", "Status", defaultStatus.Id); return(View()); }
// GET: TaskItem/Edit/5 public async Task <ActionResult> Edit(string taskItemId) { string accessToken = Session["MicrosoftAccessToken"] as string; //UserService userService = new UserService(accessToken); //var userId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft); var taskItemService = new TaskItemService(accessToken); var taskItem = await taskItemService.GetTaskItemById(taskItemId); var groupService = new GroupService(accessToken); var groups = await groupService.GetGroupsAvailableForUserWhereUserIsAdmin(Session["UserId"] as string); //var groupName = await groupService.GroupNameByGroupId(taskItem.GroupId); var statuses = await taskItemService.GetAvailableTaskStatuses(); var status = statuses.Single(s => s.Id == taskItem.TaskStatusId); ViewBag.GroupId = new SelectList(groups, "Id", "GroupNameTruncated", taskItem.GroupId); ViewBag.StatusId = new SelectList(statuses, "Id", "Status", status.Id); var taskItemModel = GetTaskItemModel(taskItem); // if (await AccessAdmin(taskItem.GroupId)) { return(View(taskItemModel)); } else if (await AccessEditor(taskItem.GroupId)) { return(View(taskItemModel)); } else { return(View("AccessDenied")); } }