public IActionResult Edit(Guid id, PortifolioViewModel 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)); } PortifolioItem portifolioItem = new PortifolioItem { Id = model.Id, Projectname = model.Projectname, Description = model.Description, ImageUrl = model.File.FileName, }; _porifolio.Entity.Update(portifolioItem); _porifolio.Save(); } catch (DbUpdateConcurrencyException) { if (!PortifolioItemExists(model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(PortifolioViewModel 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)); } PortifolioItem portifolioItem = new PortifolioItem { Projectname = model.Projectname, Description = model.Description, ImageUrl = model.File.FileName, }; _porifolio.Entity.Insert(portifolioItem); _porifolio.Save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: PortifolioItems/Edit/5 public IActionResult Edit(Guid?id) { if (id == null) { return(NotFound()); } var portifolioItem = _porifolio.Entity.GetById(id); if (portifolioItem == null) { return(NotFound()); } PortifolioViewModel portifolioViewModel = new PortifolioViewModel { Id = portifolioItem.Id, Description = portifolioItem.Description, Projectname = portifolioItem.Projectname, ImageUrl = portifolioItem.ImageUrl, }; return(View(portifolioViewModel)); }