public async Task <ActionResult> ProjectStateUpdate(ProjectStateProjectVM projectStateVM) { try { var siteId = User.GetUserSiteIdAsGuid(); ProjectViewModel updatedProject = new ProjectViewModel { ProjectId = projectStateVM.ProjectId, ProjectName = projectStateVM.Project.ProjectName, ProjectDescription = projectStateVM.Project.ProjectDescription, MunicipalRefNo = projectStateVM.Project.MunicipalRefNo, MunicipalAssessmentOfficer = projectStateVM.Project.MunicipalAssessmentOfficer, AssessmentOfficerContactNo = projectStateVM.Project.AssessmentOfficerContactNo, AssessmentOfficerEmail = projectStateVM.Project.AssessmentOfficerEmail, DateCreated = projectStateVM.Project.DateCreated, DateofSubmission = projectStateVM.Project.DateofSubmission, DraughtsmanId = projectStateVM.Project.DraughtsmanId, PropertyId = projectStateVM.Project.PropertyId, PropertyOwnerId = projectStateVM.Project.PropertyOwnerId, ProjectStateId = projectStateVM.Project.ProjectStateId, DateModified = DateTime.Now, SiteId = projectStateVM.Project.SiteId }; var mappedProject = _mapper.Map <ProjectViewModel, Project>(updatedProject); var isSuccess = await _repo.Update(mappedProject); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(projectStateVM.ProjectId)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
//Update Project State public async Task <ActionResult> ProjectStateUpdate(int id) { var userId = User.GetUserIdAsGuid(); try { if (User.IsInRole("Draughtsman") || User.IsInRole("Administrators")) { var project = await _repo.Get(id); var mappedProject = _mapper.Map <Project, ProjectViewModel>(project); string projectCurrentStateName = null; switch (mappedProject.ProjectStateId) { case 1: projectCurrentStateName = "New"; break; case 2: projectCurrentStateName = "Active"; break; case 3: projectCurrentStateName = "Dormant"; break; case 4: projectCurrentStateName = "Lost"; break; case 5: projectCurrentStateName = "Concluded"; break; case 6: projectCurrentStateName = "Archived"; break; } List <ProjectStateViewModel> StateList = new List <ProjectStateViewModel>(); StateList.Add(new ProjectStateViewModel { ProjectStateId = 1, ProjectStateName = "New" }); StateList.Add(new ProjectStateViewModel { ProjectStateId = 2, ProjectStateName = "Active" }); StateList.Add(new ProjectStateViewModel { ProjectStateId = 3, ProjectStateName = "Dormant" }); StateList.Add(new ProjectStateViewModel { ProjectStateId = 4, ProjectStateName = "Lost" }); StateList.Add(new ProjectStateViewModel { ProjectStateId = 5, ProjectStateName = "Concluded" }); StateList.Add(new ProjectStateViewModel { ProjectStateId = 6, ProjectStateName = "Archived" }); var projectStateSelect = StateList.Select(n => new SelectListItem { Text = n.ProjectStateName, Value = n.ProjectStateId.ToString() }); var projectstate = new ProjectStateProjectVM { ProjectId = id, Project = mappedProject, ProjectStateName = projectCurrentStateName, StateSelectList = projectStateSelect, }; //return RedirectToAction(nameof(Index)); //return RedirectToAction("Details", "Property", new { id = entity.PropertyId }); return(View(projectstate)); } } catch { throw new AccessViolationException("User not a Authorized"); } return(RedirectToAction("Index", "Project", new { userId })); }