コード例 #1
0
        // 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"));
            }
        }