public IActionResult RatingAndComment(int?id) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { if (!id.HasValue) { return(NotFound()); } var basket = unitOfWork.Basket.GetById(id.Value); if (basket == null) { return(NotFound()); } var basketInventories = unitOfWork.BasketInventory.GetBasketInventories(basket.Id).ToList(); var userId = _userManager.GetUserId(User); var model = new BasketRatingAndComment { Id = basket?.Id ?? 0, UserId = int.Parse(userId), OrganizationId = basket.OrganizationId }; foreach (var rec in basketInventories) { var rating = unitOfWork.Ratings.GetRating(int.Parse(userId), rec.Id); var comment = unitOfWork.Comments.GetComment(int.Parse(userId), rec.Id); var basketInventory = new BasketInventoryRatingAndComment { Id = rec.Id, CountInventory = rec.CountInventory, Sum = rec.Sum, DishId = rec.DishId, Name = rec.Dish?.Name ?? string.Empty, Comment = comment?.Text ?? string.Empty, PictureFormat = rec.Dish?.PictureFormat ?? string.Empty, PictureName = rec.Dish?.PictureName ?? string.Empty, Price = rec.Price, Raiting = rating?.RatingNumber ?? 0 }; model.BasketInventoryRatingAndComments.Add(basketInventory); } return(View(model)); } }
public async Task <IActionResult> CreateOrEdit(BasketRatingAndComment request) { var basketEditDto = new BasketEditDto { Id = request.Id, UserId = request.UserId, OrganizationId = request.OrganizationId }; foreach (var rec in request.BasketInventoryRatingAndComments) { var basketInventoryEditDto = new BasketInventoryEditDto { Id = rec.Id, CountInventory = rec.CountInventory, Price = rec.Price, DishId = rec.DishId, Sum = rec.Sum }; basketEditDto.BasketInventoryDtos.Add(basketInventoryEditDto); } var result = await _service.CreateOrEditItemAsync(basketEditDto); if (result.IsSuccess) { return(RedirectToAction("Index")); } else { foreach (var resultError in result.Errors) { ModelState.AddModelError("Error", resultError); } return(View(request)); } }
public async Task <IActionResult> RatingAndComment(BasketRatingAndComment request) { var model = new BasketRatingAndCommentDto() { Id = request.Id, UserId = request.UserId }; foreach (var rec in request.BasketInventoryRatingAndComments) { var basketInventoryRatingAndComment = new BasketInventoryRatingAndCommentDto() { Id = rec.Id, DishId = rec.DishId, Comment = rec.Comment, Rating = rec.Raiting }; model.BasketInventoryRatingAndCommentDtos.Add(basketInventoryRatingAndComment); } var result = await _service.RatingAndCommentAsync(model); if (result.IsSuccess) { return(RedirectToAction("Index")); } else { foreach (var resultError in result.Errors) { ModelState.AddModelError("Error", resultError); } return(View(request)); } }
public IActionResult CreateOrEdit(int?organizationId) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { if (!organizationId.HasValue) { return(NotFound()); } var userId = _userManager.GetUserId(User); /*var basketCheck = unitOfWork.Basket.GetClose(int.Parse(userId), organizationId.Value); * if (basketCheck != null) * { * return NotFound(); * }*/ var basket = unitOfWork.Basket.GetOpen(int.Parse(userId), organizationId.Value); var dishes = unitOfWork.Dish.GetAll(organizationId.Value); var basketInventories = new List <BasketInventory>(); if (basket != null) { basketInventories = unitOfWork.BasketInventory.GetBasketInventories(basket.Id).ToList(); } var model = new BasketRatingAndComment { Id = basket?.Id ?? 0, UserId = int.Parse(userId), OrganizationId = organizationId.Value, }; foreach (var dish in dishes) { var comment = unitOfWork.Comments.GetComment(dish.Id); var basketInventory = new BasketInventoryRatingAndComment { DishId = dish.Id, DishComment = dish.Comment, Name = dish.Name, PictureFormat = dish.PictureFormat, PictureName = dish.PictureName, Price = dish.Price, Comment = comment, Raiting = dish.RatingAverage, RatingCount = dish.RatingCount }; var tempBasketInventory = basketInventories.FirstOrDefault(x => x.DishId == dish.Id); if (tempBasketInventory != null) { basketInventory.Id = tempBasketInventory.Id; basketInventory.CountInventory = tempBasketInventory.CountInventory; basketInventory.Sum = tempBasketInventory.Sum; } model.BasketInventoryRatingAndComments.Add(basketInventory); } return(View(model)); } }