public async Task <IActionResult> CustomerPartial(int customerId) { var model = new CustomerCommentViewModel(); var comments = await _commentService.GetCustomerComments(customerId); model.Comments = _mapper.Map <List <Comment> >(comments).OrderByDescending(x => x.Id).ToList(); model.Customer = new Customer { Id = customerId }; model.CommentTypes = _mapper.Map <List <CommentType> >(await _commentTypeService.All()); return(PartialView(model)); }
public IActionResult OnGet(int?id) { // int TongDiem = 0; int sumEvaluation = 0; //Kiểm tra tham số truyền vào có rỗng hay không if (id == null) { //return BadRequest(); return(RedirectToPage("/NotFound")); } //Nếu không thì truy xuất csdl lấy ra sản phẩm tương ứng Item = _itemRepository.Find(n => n.Id == id && n.IsDeleted == false); //Comment = _commentRepository.Find(n => n.Id == id && n.IsDeleted == false); if (Item == null) { //Thông báo nếu như không có sản phẩm đó return(RedirectToPage("/NotFound")); } ItemId = Item.Id; Item.View++; _itemRepository.Update(Item); List <Comment> comments = _commentRepository.GetSome(y => y.ItemId == id && y.IsDeleted == false).ToList(); if (comments.Any()) { foreach (Comment comment in comments.ToList()) { sumEvaluation += comment.Evaluation; _countComment++; var cus = _userRepository.FindUser(c => c.Id == comment.CustomerId); CustomerCommentViewModel.Add(new CustomerCommentViewModel() { CommentId = comment.Id, Content = comment.Content, CustomerId = comment.CustomerId, CustomerName = cus.Name, CustomerAvatar = cus.Avatar, Evaluation = comment.Evaluation, ItemId = comment.ItemId, DateCreated = comment.DateCreated, DateModified = comment.DateModified }); } } else { CustomerCommentViewModel = null; } var user = _userManager.GetUserAsync(HttpContext.User).Result; if (user != null) { Reviewed = _commentRepository.GetSome(c => c.IsDeleted == false && c.CustomerId == user.Id).FirstOrDefault(); var orders = _orderRepository.GetSome(o => o.Status == OrderStatus.Delivered && o.IsDeleted == false); foreach (var order in orders) { var address = _addressRepository.GetSome(a => a.Id == order.AddressId && a.IsDeleted == false); foreach (var _address in address) { if (_address.Id == order.AddressId && _address.CustomerId == user.Id) { var orderitems = _orderItemRepository.GetSome(cd => cd.IsDeleted == false && cd.ItemId == id).ToList(); foreach (var orderitem in orderitems) { if (orderitem.OrderId == order.Id) { isordered = true; break; } } } } } } return(Page()); }