示例#1
0
        public async Task <IActionResult> Edit(ProjectTaskModel request)
        {
            var dto = Mapper.Map <ProjectTaskDto>(request);

            if (!User.IsInRole("AdminAupervisor"))
            {
                dto.Author.Id = int.Parse(_userManager.GetUserId(User));
            }
            var result = await _service.EditItemAsync(dto);

            if (result.IsSuccess)
            {
                if (User.IsInRole("AdminAupervisor"))
                {
                    return(RedirectToAction("IndexAdmin", "Project"));
                }
                else
                {
                    return(RedirectToAction("IndexPM", "Project"));
                }
            }
            else
            {
                var project = _serviceProject.GetProject(request.ProjectId);
                if (User.IsInRole("AdminAupervisor"))
                {
                    request.AuthorList = new SelectList(_helper.GetUsers(new List <StatusRole>()
                    {
                        StatusRole.AdminAupervisor,
                        StatusRole.ProjectManager
                    }, _serviceUser), "Id", "FullName");
                }

                request.ExecutorList = new SelectList(_helper.GetUsers(project.ProjectUsers), "Id", "FullName");
                foreach (var resultError in result.Errors)
                {
                    ModelState.AddModelError("Error", resultError);
                }
                return(View(request));
            }
        }