public async Task <IActionResult> Create(portfolioViewModel model) { if (ModelState.IsValid) { if (model.File != null) { //save the File at the level of the root in portfolio folder string uploads = Path.Combine(_hosting.WebRootPath, @"img\portfolio"); string Fullpath = Path.Combine(uploads, model.File.FileName); model.File.CopyTo(new FileStream(Fullpath, FileMode.Create)); } //mapping the version to EF PortfolioItem portfolioItem = new PortfolioItem { ProjectName = model.ProjectName, Discreption = model.Discreption, ImageUrl = model.File.FileName, id = model.id, }; //insert and save in UnitOfWork _portfolio.entity.Insert(portfolioItem); _portfolio.Save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public IActionResult Edit(Guid id, portfolioViewModel model) { if (id != model.id) { return(NotFound()); } if (ModelState.IsValid) { try { if (model.File != null) { //save the File at the level of the root in portfolio folder string uploads = Path.Combine(_hosting.WebRootPath, @"img\portfolio"); string Fullpath = Path.Combine(uploads, model.File.FileName); model.File.CopyTo(new FileStream(Fullpath, FileMode.Create)); } //mapping the version to EF PortfolioItem portfolioItem = new PortfolioItem { ProjectName = model.ProjectName, Discreption = model.Discreption, ImageUrl = model.File.FileName, id = model.id, }; //insert and save in UnitOfWork _portfolio.entity.Update(portfolioItem); _portfolio.Save(); } catch (DbUpdateConcurrencyException) { if (!PortfolioItemExists(model.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: PortfolioItems/Edit/5 public IActionResult Edit(Guid?id) { if (id == null) { return(NotFound()); } var portfolioItem = _portfolio.entity.GetById(id); if (portfolioItem == null) { return(NotFound()); } portfolioViewModel portfolioViewModel = new portfolioViewModel { ProjectName = portfolioItem.ProjectName, Discreption = portfolioItem.Discreption, ImageUrl = portfolioItem.ImageUrl, id = portfolioItem.id, }; return(View(portfolioViewModel)); }