public ActionResult DeleteConfirmed(int id, bool?isMyOrdersPage, bool?isNewOrdersPage, int?currentCategoryId, OrderSorts ordersSort = OrderSorts.New) { if (User.Identity.GetUserId <int>() != _orderService.Find(id).UserId) { return(View("~/Views/Error/Forbidden.cshtml")); } var responses = _responseService.GetAllForOrder(id); if (responses.Any()) { foreach (var response in responses) { _responseService.Delete(response.Id); } } _orderService.DeleteOrder(id); var picture = _orderService.Find(id).PictureId; if (picture.HasValue) { _pictureService.Delete(picture.Value); } _unitOfWork.Save(); return(RedirectToAction("Index", new { newApplications = isNewOrdersPage, myOrders = isMyOrdersPage, categoryId = currentCategoryId, sort = ordersSort })); }
public async Task <ActionResult> DeleteAccount(DeleteAccountViewModel model) { if (ModelState.IsValid) { var user = _userService.FindById(User.Identity.GetUserId <int>()); var picture = _userService.FindById(user.Id).PictureId; if (picture.HasValue) { _pictureService.Delete(picture.Value); } var ordersId = _orderService.GetAll().Where(o => o.UserId == user.Id).Select(o => o.Id).ToList(); if (ordersId.Any()) { var responses = _responseService.GetAll() .Select(r => r.OrderId.Value) .Where(r => ordersId.Contains(r)).ToList(); if (responses.Any()) { foreach (var response in responses) { _responseService.Delete(response); } } } var comments = _commentService.GetAll().Where(c => c.CustomerId == user.Id).ToList(); if (comments.Any()) { foreach (var comment in comments) { _commentService.Delete(comment.Id); } } ClientViewModelBLL userDto = new ClientViewModelBLL { Password = model.Password, Email = User.Identity.Name }; var operationDetails = await _userService.DeleteAccount(userDto); if (operationDetails.Succedeed) { _unitOfWork.Save(); LogOff(); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } return(View(model)); }
public async Task <IActionResult> Delete([FromRoute] string commentId, string id) { await _responseService.Delete(commentId, id); return(NoContent()); }