public async Task <ActionResult> Delete(int id) { var currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); var currentUser = await _userService.GetUserById(currentUserId); var currentUserName = currentUser.UserName; var lotToDelete = await _lotService.GetLotById(id); if (!User.IsInRole("Admins") && currentUserName != lotToDelete.User) { return(Forbid()); } Regex regex = new Regex(@"[^\/]+(?=\.)"); MatchCollection matches = regex.Matches(lotToDelete.ImageUrl); var publicId = matches[1].ToString(); var deletionParams = new DeletionParams(publicId); var deletionResult = await _cloudinary.DestroyAsync(deletionParams); await _lotService.DeleteLot(id); return(NoContent()); }
public ActionResult <LotDTO> Delete(int id) { var toDelete = _lotService.GetLot(id); if (toDelete == null) { return(NotFound()); } _lotService.DeleteLot(id); return(NoContent()); }
public ActionResult DeleteConfirmed(int id) { if (!_customAuthentication.CheckUserInRoles(UserViewModel.ToUserEntity(), "Admin,Moderator")) { return(new HttpStatusCodeResult(403)); } var lot = _lotService.GetLotEntity(id); _lotService.DeleteLot(lot); return(RedirectToAction("Index")); }
public ActionResult Delete(int lotId, string returnUrl) { _lotService.DeleteLot(_lotService.GetLotEntity(lotId)); if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Lot")); } }