public IActionResult Edit(Guid id, PortFlioViewModel model) { if (id != model.ID) { return(NotFound()); } if (ModelState.IsValid) { try { if (model.File != null) { string Uploads = Path.Combine(_hosting.WebRootPath, @"img\portfolio"); string FullPath = Path.Combine(Uploads, model.File.FileName); model.File.CopyTo(new FileStream(FullPath, FileMode.Create)); } PortflioItem portflioItem1 = new PortflioItem { ID = model.ID, ProjectName = model.ProjectName, Description = model.Description, ImgUrl = model.File.FileName }; _PortflioItem.Entity.Update(portflioItem1); _PortflioItem.save(); } catch (DbUpdateConcurrencyException) { if (!PortflioItemExists(model.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(PortFlioViewModel model) { if (ModelState.IsValid) { if (model.File != null) { string Uploads = Path.Combine(_hosting.WebRootPath, @"img\portfolio"); string FullPath = Path.Combine(Uploads, model.File.FileName); model.File.CopyTo(new FileStream(FullPath, FileMode.Create)); } PortflioItem portflioItem1 = new PortflioItem { ProjectName = model.ProjectName, Description = model.Description, ImgUrl = model.File.FileName }; _PortflioItem.Entity.Insert(portflioItem1); _PortflioItem.save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: PortflioItems/Edit/5 public IActionResult Edit(Guid?id) { if (id == null) { return(NotFound()); } var portflioItem = _PortflioItem.Entity.GetById(id); if (portflioItem == null) { return(NotFound()); } PortFlioViewModel portFlioViewModel = new PortFlioViewModel { ID = portflioItem.ID, ProjectName = portflioItem.ProjectName, Description = portflioItem.Description, ImgUrl = portflioItem.ImgUrl }; return(View(portFlioViewModel)); }