public IActionResult EditProject(int?id) { // Verify that id is not Null if (id == null) { return(View()); } var projectContext = _context.ProjectModel.First(p => p.ID == id); if (projectContext == null) { return(View()); } var modelView = new ProjectEditViewClass { ProjectName = projectContext.ProjectName, Custid = projectContext.Customer, ActiveProj = projectContext.IsActive, ProjBudget = projectContext.ProjBudget, ProjCost = projectContext.ProjCurentCost, ProjStart = projectContext.StartDate, ProjEnd = projectContext.EndDate }; return(View(modelView)); }
public async Task <IActionResult> EditProject(ProjectEditViewClass model, int?id) { var UpdateModel = await _context.ProjectModel.Where(m => m.ID == id).FirstOrDefaultAsync(); // Verify it exists if (UpdateModel != null) { UpdateModel.ProjectName = model.ProjectName; UpdateModel.IsActive = model.ActiveProj; UpdateModel.ProjBudget = model.ProjBudget; UpdateModel.ProjCurentCost = model.ProjCost; UpdateModel.Customer = model.Custid; UpdateModel.StartDate = model.ProjStart; UpdateModel.EndDate = model.ProjEnd; _context.ProjectModel.Update(UpdateModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(AllProjectsPartial))); } _logger.LogError($"NO VALUE FOUND FOR MODEL WITH ID '{id}'"); return(View(model)); }