public async Task <IActionResult> Edit(EditAdsModel edit) { //if (id != advertisement.Id) //{ // return NotFound(); //} if (ModelState.IsValid) { Advertisement ad = _context.Advertisements.Find(edit.Id); ad.Title = edit.Title; ad.BodyText = edit.BodyText; ad.ValidUntil = edit.ValidUntil; ad.UniqueID = edit.UniqueID; ad.CreationDate = edit.CreationDate; if (edit.Image != null) { if (edit.PhotoPath != null) { string filepath = Path.Combine(hostingEnvironment.WebRootPath, "images", edit.PhotoPath); System.IO.File.Delete(filepath); } ad.Image = ProccedFileUpload(edit); } try { _context.Update(ad); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdvertisementExists(edit.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(edit)); }
// GET: Control/Advertisements/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var advertisement = await _context.Advertisements.FindAsync(id); if (advertisement == null) { return(NotFound()); } EditAdsModel forview = new EditAdsModel(); forview.Title = advertisement.Title; forview.UniqueID = advertisement.UniqueID; forview.CreationDate = advertisement.CreationDate; forview.ValidUntil = advertisement.ValidUntil; forview.BodyText = advertisement.BodyText; forview.PhotoPath = advertisement.Image; forview.Id = advertisement.Id; return(View(forview)); }