public async Task <IActionResult> Delete(int id) { var rev = await _reviewsRepository.GetByIdAsync(id); if (HttpContext.User.IsInRole("Admin")) { try { _reviewsRepository.Delete(rev); await _reviewsRepository.SaveChangesAsync(); return(RedirectToAction("Index", "Reviews", new { message = "Відгук успішно видалено!" })); } catch { return(RedirectToAction("Index", "Reviews", new { error = "Під час видалення відгуку сталася помилка!" })); } } else { var user = await _userManager.GetUserAsync(HttpContext.User); if (rev.Reviewer.UserId == user.Id) { _reviewsRepository.Delete(rev); await _reviewsRepository.SaveChangesAsync(); return(RedirectToAction("Profile", "Account", new { message = "Відгук успішно видалено!" })); } return(RedirectToAction("Public", "Reviews", new { error = "Ви намагаєтесь видалити чужий відгук!" })); } }
public async Task <IActionResult> Delete([FromBody] Guid[] ids) { foreach (var id in ids) { _reviewsRepository.Delete(id); } await _reviewsRepository.SaveAllChangesAsync(); return(Ok()); }
public IActionResult Delete(int id) { var currentUserProfile = GetCurrentUser(); var review = _reviewsRepository.GetReviewById(id); if (currentUserProfile.Id != review.ReadState.User.Id) { return(Unauthorized()); } _reviewsRepository.Delete(id); return(NoContent()); }
public IActionResult DeleteReview([FromBody] ReviewDto reviewData) { //check if review exists if (_reviewsRepository.GetAll().All(r => r.Id != reviewData.OrderId)) { return(BadRequest("Review you want to update does not exist")); } var reviewToDelete = _reviewsRepository.GetAll().ToList().First(r => r.Id == reviewData.OrderId); _reviewsRepository.Delete(reviewToDelete); return(Ok("Review has been deleted")); }