public IActionResult Create(CreateWorkTaskViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var presenter = _presenterFactory.Create(MessageHandler, ErrorHandler); var request = vm.ToRequest(CurrentUserId); try { var uc = _useCaseFactory.Create; var response = uc.Execute(request); return(RedirectToAction(nameof(Index), new { id = presenter.Present(response) })); } catch (InvalidRequestException ire) { presenter.PresentErrors(ire.Message, ire.Errors); return(View(presenter.Present(vm))); } catch (Exception e) { presenter.PresentMessage(MessageType.Error, e.Message); return(View(presenter.Present(vm))); } }
public CreateWorkTaskViewModel GetInitialViewModel(string projectId, string type, string parent = null, string child = null) { var project = RepositoryProvider.Project.Read(Identity.FromString(projectId)); var backlog = RepositoryProvider.Project.ReadProductBacklog(project.Id); var possibleParents = GetTasksFromBacklog( backlog, status => status != ProductBacklog.WorkTaskStatus.Done, CreateParentTypeFilter(Parse(type))); var possibleChildren = GetTasksFromBacklog( backlog, status => status != ProductBacklog.WorkTaskStatus.Done, CreateChildTypeFilter(Parse(type))); var vm = new CreateWorkTaskViewModel { Type = type, Project = project.ToViewModel(), ParentTasks = ToSelectListWithBlankEntry(possibleParents), ChildTasks = ToSelectListWithBlankEntry(possibleChildren), Documents = Documents(project.Id), }; if (!string.IsNullOrWhiteSpace(parent)) { vm.ParentTaskId = parent; } if (!string.IsNullOrWhiteSpace(child)) { vm.ChildTaskIds.Add(child); } return(vm); }
public static CreateWorkTaskRequest ToRequest(this CreateWorkTaskViewModel vm, string userId) { return(new CreateWorkTaskRequest(userId) { Name = vm.Name, ProjectId = Identity.FromString(vm.Project.Id), ParentTask = string.IsNullOrWhiteSpace(vm.ParentTaskId) ? Identity.BlankIdentity : Identity.FromString(vm.ParentTaskId), Type = Enum.Parse <WorkTaskType>(vm.Type), Description = vm.Description, ChildTasks = vm.ChildTaskIds.Select(Identity.FromString), StoryPoints = vm.StoryPoints, Steps = vm.Steps, Documents = vm.SelectedDocumentIds.Select(Identity.FromString), }); }
public CreateWorkTaskViewModel Present(CreateWorkTaskViewModel vm) { var project = RepositoryProvider.Project.Read(Identity.FromString(vm.Project.Id)); var backlog = RepositoryProvider.Project.ReadProductBacklog(project.Id); var possibleParents = GetTasksFromBacklog( backlog, status => status != ProductBacklog.WorkTaskStatus.Done && status != ProductBacklog.WorkTaskStatus.InSprint, CreateParentTypeFilter(Parse(vm.Type))); var possibleChildren = GetTasksFromBacklog( backlog, status => status != ProductBacklog.WorkTaskStatus.Done && status != ProductBacklog.WorkTaskStatus.InSprint, CreateChildTypeFilter(Parse(vm.Type))); vm.ParentTasks = ToSelectListWithBlankEntry(possibleParents); vm.ChildTasks = ToSelectListWithBlankEntry(possibleChildren); vm.Documents = Documents(project.Id); return(vm); }