public async Task <IActionResult> Edit(int id, [Bind("CommentID,UserId,AdvertisementID,DateOfComent,Text,Like,Dislike")] Comment comment) { // if (comment.UserId == _userName) //{ if (id != comment.CommentID) { return(NotFound()); } if (ModelState.IsValid) { try { comment.UserId = _userName; _context.Update(comment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(comment.CommentID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } //} return(View(comment)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryName")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,AddDate,ExpirationDate,CategoryName")] Ad ad) { if (id != ad.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ad); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdExists(ad.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ad)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,City,Area,Address,Description,Price,Contact,Date,Studio,OneRoom,TwoRooms,ThreeRooms")] PutAdViewModel putAdViewModel) { if (id.ToString() != putAdViewModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(putAdViewModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PutAdViewModelExists(putAdViewModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(putAdViewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,Price,CategoryId")] Advertisement advertisement) { if (id != advertisement.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(advertisement); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdvertisementExists(advertisement.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "ID", "Name", advertisement.CategoryId); return(View(advertisement)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,UserID,City,Area,Address,Description,Studio,OneRoom,TwoRooms,ThreeRooms,Price,Contact,Date")] Advertisement advertisement) { if (id != advertisement.ID) { return(NotFound()); } if (ModelState.IsValid) { try { if (advertisement.UserID == _userName) { advertisement.UserID = _userName; advertisement.Date = DateTime.Now; _context.Update(advertisement); await _context.SaveChangesAsync(); } else { //warning //Reporter.Error.WriteLine(ToolsStrings.DesktopCommandsRequiresWindows(framework.GetShortFolderName()); return(RedirectToAction("Index")); } } catch (DbUpdateConcurrencyException) { if (!AdvertisementExists(advertisement.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["UserID"] = new SelectList(_context.Users, "ID", "ID", advertisement.UserID); return(View(advertisement)); }
public async Task Update([FromBody] Ad ad) { _context.Update(ad); await _context.SaveChangesAsync(); }