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 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)); } }