public IActionResult Edit(Guid id, PortfoioItem model, IFormFile?load) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (load != null) { string upload = Path.Combine(_hosting.WebRootPath, @"img/portfolio"); string fullPath = Path.Combine(upload, load.FileName); load.CopyTo(new FileStream(fullPath, FileMode.Create)); } PortfoioItem portfoio = new PortfoioItem { Id = model.Id, ProjectName = model.ProjectName, Descrption = model.Descrption, ImageUrl = load != null ? load.FileName:model.ImageUrl }; _portfoioItems.Entity.Update(portfoio); _portfoioItems.Save(); } catch (DbUpdateConcurrencyException) { if (!PortfoioItemExists(model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public IActionResult Create(PortfolioViewModel model) { if (ModelState.IsValid) { if (model.File != null) { string upload = Path.Combine(_hosting.WebRootPath, @"img/portfolio"); string fullPath = Path.Combine(upload, model.File.FileName); model.File.CopyTo(new FileStream(fullPath, FileMode.Create)); } PortfoioItem portfoio = new PortfoioItem { ProjectName = model.ProjectName, Descrption = model.Descrption, ImageUrl = model.File.FileName }; _portfoioItems.Entity.Insert(portfoio); _portfoioItems.Save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }