// GET: Projects/Create /// <summary> /// This is the naughty version, without repositories, where the list items etc are created and passed through here. /// </summary> /// <returns>Project Create View Model, and associated SelectListItems</returns> public IActionResult Create() { //create the view ProjectCreateVM pvcm = new ProjectCreateVM { //Get all the PID types,order them and add just their IDs and Names to a Select Item List in the View Model PidTypes = _context.PIDTypes.OrderBy(p => p.PIDTypeName).Select(n => new SelectListItem { Value = n.PIDTypeId.ToString(), Text = n.PIDTypeName }) .ToList(), //As above but for Workstreams Workstreams = _context.Workstreams.OrderBy(w => w.WorkstreamName).Select(n => new SelectListItem { Value = n.WorkstreamId.ToString(), Text = n.WorkstreamName }).ToList() }; //pass the pre-populated view model to the view return(View(pvcm)); }
public void PostMethod_ValidInput_ReturnsCorrectResponse(int companyId, string projectName) { var mockedProjectId = 1; var sprintName = "Backlog"; var project = new ProjectCreateVM { CompanyId = companyId, Name = projectName }; _projectService.Setup(x => x.CreateProject(It.IsAny <ProjectCreateVM>(), mockedUserGuid)).Returns(mockedProjectId); var result = _controller.Object.Post(project); _projectService.Verify(x => x.CreateProject( It.Is <ProjectCreateVM>( p => p.CompanyId == companyId && p.Name == projectName), mockedUserGuid )); _sprintService.Verify(x => x.CreateSprint( It.Is <SprintCreateVM>( p => p.ProjectId == mockedProjectId && p.Name == sprintName) )); Assert.AreEqual(typeof(CreatedAtActionResult), result.GetType()); }
public async Task <IActionResult> CreateProject([FromBody] ProjectCreateVM projectCreateVM) { Response response = await _mediator.Send(new CreateProject() { ProjectCreateVM = projectCreateVM }); return(CreatedAtAction("GetProjectById", new { id = (response.Data as ProjectVM).Id }, response)); }
public async Task <IActionResult> Create(ProjectCreateVM pVM) { //Model state valid returns false but it still saves fine. if (ModelState.IsValid) { //Manually move over all the values form the VM to the actual Project - except calculated fields (Patient Safety Risk "PSR") and Infered fields - Project Owner [logged in user] //Need approach for catagorical and dynamic list types: Workstreams and Pid Type. Project project = new Project { AgeRange = pVM.AgeRange, HowManyPeopleAffected = pVM.HowManyPeopleAffected, IIAApproved = Approval.Unassessed, QIAApproved = Approval.Unassessed, QIARequired = pVM.QIARequired, workstream = await _context.Workstreams.FindAsync(pVM.WorkstreamId), PatientSafetyDesc = pVM.PatientSafetyDesc, pIDType = await _context.PIDTypes.FindAsync(pVM.PIDTypeId), ProjectAssumptions = pVM.ProjectAssumptions, ProjectDescription = pVM.ProjectDescription, ProjectObjective = pVM.ProjectObjective, ProjectTitle = pVM.ProjectTitle, PSC = pVM.PSC.GetValueOrDefault(), PSL = pVM.PSL.GetValueOrDefault(), WhereLiving = pVM.WhereLiving }; //generate and add project ID project.ProjectId = Guid.NewGuid(); //check, fetch and add user, as owner if (User.Identity.IsAuthenticated) { ApplicationUser user = await GetCurrentUserAsync(); if (user != null) { project.ProjectOwner = user; } } //check and calculate impact scores - this should have a null check, but the ints aren't null to start... project.PSR = project.PSC * project.PSL; _context.Add(project); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { ViewBag.ErrorCount = ModelState.ErrorCount; return(View(pVM)); } }
public IActionResult Post([FromBody] ProjectCreateVM project) { if (!ModelState.IsValid) { return(BadRequest()); } var projectId = _projectService.CreateProject(project, GetUserId()); var sprintId = _sprintService.CreateBackLogSprint(projectId); return(CreatedAtAction("Get", new { id = projectId }, projectId)); }
// GET: Projects/Create public ActionResult Create() { if (User.IsInRole("Admin") || User.IsInRole("ProjectManager")) { ProjectCreateVM projectCreate = new ProjectCreateVM(); var pmUsers = userHelper.UsersInRole("ProjectManager"); projectCreate.ProjectManagers = new SelectList(pmUsers, "Id", "FullName"); return(View(projectCreate)); } TempData["Alert"] = "You are not authorized to create projects"; return(RedirectToAction("Index", "Projects")); }
public int CreateProject(ProjectCreateVM project, Guid createdBy) { var projectToBeCreated = new Database.Entities.Project { CompanyId = project.CompanyId, Name = project.Name, CreatedBy = createdBy, CreatedOn = DateTime.Now }; _dbContext.Projects.Add(projectToBeCreated); _dbContext.SaveChanges(); return(projectToBeCreated.ProjectId); }
public ActionResult Create(ProjectCreateVM projectCreate, string projectManagerId) { if (ModelState.IsValid) { Project project = new Project(); project.Name = projectCreate.Project.Name; project.Description = projectCreate.Project.Description; project.ProjectManagerId = projectManagerId; project.Created = DateTime.Now; db.Projects.Add(project); db.SaveChanges(); var projId = project.Id; return(RedirectToAction("Details", new { id = projId })); } return(View(projectCreate)); }