public async Task <ActionResult> Edit(ProjectStatusItemViewModel projectStatusItemViewModel) { var projectId = projectStatusItemViewModel.ProjectItemStatuses.FirstOrDefault().ProjectId; try { if (!ModelState.IsValid) { return(View(projectStatusItemViewModel)); } foreach (var itemstatus in projectStatusItemViewModel.ProjectItemStatuses) { var newitemstatus = await _repo.FindByDetails(itemstatus.ProjectId, itemstatus.ProjectItemId); if (itemstatus.IsComplete) { newitemstatus.IsComplete = true; newitemstatus.DateCompleted = DateTime.Now; //var mappeditemstatus = _mapper.Map<ProjectItemStatus>(newitemstatus); } else { newitemstatus.IsComplete = false; newitemstatus.DateCompleted = DateTime.Now; //var mappeditemstatus = _mapper.Map<ProjectItemStatus>(newitemstatus); } var isSuccess = await _repo.Update(newitemstatus); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(projectId)); } } ; var project = await _projectrepo.Get(projectId); project.DateModified = DateTime.Now; //var mappedproject = _mapper.Map<Project>(project); var isProjectSuccess = await _projectrepo.Update(project); if (!isProjectSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(projectStatusItemViewModel)); } ; return(RedirectToAction("Index", new { id = projectId })); } catch { return(View(projectStatusItemViewModel)); } }
// GET: /<controller>/ public async Task <IActionResult> Index(int id) { var project = await _projectrepo.Get(id); var mappedproject = _mapper.Map <Project, ProjectViewModel>(project); var property = await _propertyrepo.Get(project.PropertyId); var mappedproperty = _mapper.Map <Property, PropertyViewModel>(property); var propertyOwner = await _siteUserManager.FindByIdAsync(project.PropertyOwnerId.ToString()); var draughtsman = await _siteUserManager.FindByIdAsync(project.DraughtsmanId.ToString()); //string siteid = "1732d901-82c3-4c48-9e02-3049c8ea2738"; var siteId = User.GetUserSiteIdAsGuid(); ProjectDetailsViewModel projectDetails = new ProjectDetailsViewModel { ProjectId = project.ProjectId, ProjectName = project.ProjectName, ProjectDescription = project.ProjectDescription, MunicipalRefNo = project.MunicipalRefNo, DateofSubmission = project.DateofSubmission, MunicipalAssessmentOfficer = project.MunicipalAssessmentOfficer, AssessmentOfficerEmail = project.AssessmentOfficerEmail, AssessmentOfficerContactNo = project.AssessmentOfficerContactNo, DateCreated = project.DateCreated, DateModified = project.DateModified, PropertyId = project.PropertyId, DraughtsmanId = project.DraughtsmanId, ProjectStateId = project.ProjectStateId, SiteId = property.SiteId, PropertyName = property.PropertyName, PropertyAddress = property.PropertyAddress, PropertyERF_LotNo = property.PropertyERF_LotNo, IsComplex = property.IsComplex, IsEstate = property.IsEstate, Complex_Estate_No = property.Complex_Estate_No, PropertySGNo = property.PropertySGNo, PropertyOwnerFirstName = propertyOwner.FirstName, PropertyOwnerLastName = propertyOwner.LastName, PropertyOwnerEmail = propertyOwner.Email, // PropertyOwnerContactNo = propertyOwner.PhoneNumber, DraughtsmanFirstName = draughtsman.FirstName, DraughtsmanLastName = draughtsman.LastName, DraughtsmanEmail = draughtsman.Email, // DraughtsmanContactNo = draughtsman.PhoneNumber, }; //mappedproject.Property = mappedproperty;*/ var projectStatusItemViewModel = new ProjectStatusItemViewModel { ProjectId = id, Project = projectDetails // Project = mappedproject }; var projectitemstatuses = await _repo.GetAllById(id); var projectItemStatusList = new List <ProjectItemStatusViewModel> { }; foreach (var projectitemstatus in projectitemstatuses) { var mappeditemstatus = _mapper.Map <ProjectItemStatus, ProjectItemStatusViewModel>(projectitemstatus); projectItemStatusList.Add(mappeditemstatus); } projectStatusItemViewModel.ProjectItemStatuses = projectItemStatusList; return(View(projectStatusItemViewModel)); }