public HttpResponseMessage Create(PortifolioItem item) { var response = new HttpResponseMessage(); try { item = _service.PortifolioItem.Create(item); response = Request.CreateResponse(HttpStatusCode.OK, item); } catch (Exception ex) { response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message); } return response; }
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)); }