public ActionResult Create(CreateImagesViewModel model) { try { string FileName = UploadFile(model.File) ?? string.Empty; if (ModelState.IsValid) { if (model.ProjectId == -1) { ModelState.AddModelError("", "please review the input fileds"); return(View(GetAllProjects())); } var projects = projectRepository.Find(model.ProjectId); var photo = new Photos { Image = FileName, Project = projects }; imageRepository.Add(photo); return(RedirectToAction("index")); } return(View(model)); } catch { return(View(model)); } }
CreateImagesViewModel GetAllProjects() { var model = new CreateImagesViewModel { Projects = FillProjects() }; return(model); }
public ActionResult Create() { var model = new CreateImagesViewModel { Projects = FillProjects() }; return(View(model)); }