public ActionResult Edit(int id, EditProjectsViewModel model) { try { string FileName = UploadFile(model.File, model.ImageUrl); if (ModelState.IsValid) { var category = categoriesrepository.Find(model.CategoryId); if (category == null) { ModelState.AddModelError("", "Please review the inpyt fields"); return(View(GetAllCategories())); } var project = new Projects { Name = model.Name, Image = FileName, Client = model.Client, ProjectDate = model.ProjectDate, Description = model.Description, Category = category }; projectrepository.Update(model.Id, project); model.Categories = FillCategories(); return(RedirectToAction("index")); } return(View(model)); } catch { return(View()); } }
public ActionResult Edit(int id) { var project = projectrepository.Find(id); if (project == null) { return(NotFound()); } var categoryId = project.Category == null ? project.Category.ID = 0 : project.Category.ID; var model = new EditProjectsViewModel { Id = project.ID, Name = project.Name, ImageUrl = project.Image, Client = project.Client, ProjectDate = project.ProjectDate, Description = project.Description, Categories = FillCategories(), CategoryId = categoryId }; return(View(model)); }