private async Task DeleteCommentRatings(string id) { IEnumerable <CommentRatingDTO> ratings = _commentRatingService.GetCommentRatings(id); if (ratings == null) { return; } foreach (var rating in ratings) { await _commentRatingService.Delete(rating.Id); } }
public async Task <IActionResult> DeleteCommentRating([Required] string id) { if (ModelState.IsValid && User.Identity.IsAuthenticated) { ApplicationUser user = await _authenticationManager.UserManager.FindByNameAsync(User.Identity.Name); CommentRatingDTO commentRating = await _commentRatingService.GetById(id); if (commentRating == null) { return(NotFound()); } if (commentRating.ApplicationUserId == user.Id || await _authenticationManager.UserManager.IsInRoleAsync(user, "Admin")) { CommentRatingDTO deletedCommentRating = await _commentRatingService.Delete(id); return(Ok(await GetCommentRatingModelFromDTO(deletedCommentRating))); } } return(BadRequest(ModelState)); }