public ProductCart GetProductCart(Guid id) { ProductCart products = new ProductCart(); var data = _applicationContext.Products.Where(x => x.Id == id).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }) }); foreach (var item in data) { products.Id = item.Id; products.Name = item.Name; products.Cost = item.Cost; foreach (var image in item.Image) { products.Path = image.Path; } } return(products); }
public List <object> FindProductByName(string name) { var product = _applicationContext.Products.Where(x => x.Name.StartsWith(name)).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, ShortDescription = x.ShortDescription, FullDescription = x.FullDescription, Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetProductDetails(Guid id) { var product = _applicationContext.Products.Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, ShortDescription = x.ShortDescription, FullDescription = x.FullDescription, Quantity = x.Quantity, Status = _applicationContext.StatusProducts.Where(p => p.Id == x.StatusProductId).Select(n => n.Name), Provider = _applicationContext.Providers.Where(p => p.Id == x.ProviderId).Select(n => n.Name), Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).Where(x => x.Id == id); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetListDiscountProducts() { var product = _applicationContext.Products .Where(x => x.View >= 100) .Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).OrderBy(x => x.Sale).Take(8).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetProductByCategory(Guid name) { var product = _applicationContext.Products .Join(_applicationContext.StatusProducts, stt => stt.StatusProductId, st => st.Id, (stt, st) => new { stt, st }) .Join(_applicationContext.Providers, sp => sp.stt.ProviderId, spp => spp.Id, (sp, spp) => new { sp, spp }) .Join(_applicationContext.Units, us => us.sp.stt.UnitId, usp => usp.Id, (us, usp) => new { us, usp }) .Join(_applicationContext.ProductTypes, pt => pt.us.sp.stt.ProductTypeId, ptp => ptp.Id, (pt, ptp) => new { pt, ptp }) .Join(_applicationContext.Categeries, ct => ct.pt.us.sp.stt.CategoryId, ctp => ctp.Id, (ct, ctp) => new { ct, ctp }) .Where(x => x.ctp.Id == name) .Select(prd => new { CreatedDate = prd.ct.pt.us.sp.stt.CreatedDate, Name = prd.ct.pt.us.sp.stt.Name, Id = prd.ct.pt.us.sp.stt.Id, Code = prd.ct.pt.us.sp.stt.Code, View = prd.ct.pt.us.sp.stt.View, Cost = prd.ct.pt.us.sp.stt.Cost, CostOld = prd.ct.pt.us.sp.stt.CostOld, Mass = prd.ct.pt.us.sp.stt.Mass, ShortDescription = prd.ct.pt.us.sp.stt.ShortDescription, FullDescription = prd.ct.pt.us.sp.stt.FullDescription, Quantity = prd.ct.pt.us.sp.stt.Quantity, Sale = prd.ct.pt.us.sp.stt.Sale, Category = prd.ctp.Name, Provider = prd.ct.pt.us.spp.Name, StatusProduct = prd.ct.pt.us.sp.st.Name, Unit = prd.ct.pt.usp.Name, Image = _applicationContext.Images.Where(p => p.ProductId == prd.ct.pt.us.sp.stt.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetListOrder(Guid id) { var data = _applicationContext.Orders.Where(x => x.UserId == id) .Join(_applicationContext.OrderDetails, o => o.Id, od => od.OrderId, (o, od) => new { o, od }) .Join(_applicationContext.Products, p => p.od.ProductId, pd => pd.Id, (p, pd) => new { p, pd }) .Join(_applicationContext.StatusCarts, st => st.p.od.StatusCartId, sc => sc.Id, (st, sc) => new { st, sc }) .Select(s => new { ProductName = s.st.pd.Name, Quantity = s.st.p.od.Quantity, TotalCost = s.st.p.od.TotalCost, StatusOrder = s.sc.Name, Images = _applicationContext.Images.Where(x => x.ProductId == s.st.pd.Id).Select( im => "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(im.Path) ).ToList() }); List <object> list = new List <object>(); foreach (var item in data) { list.Add(item); } return(list); }
public async Task <IActionResult> AddToCarts(ProductCarts id) { try { var getSession = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); var ids = new Guid(id.Id); ProductCart products = new ProductCart(); var data = _applicationContext.Products.Where(x => x.Id == ids).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }) }); foreach (var item in data) { products.Id = item.Id; products.Name = item.Name; products.Cost = item.Cost; foreach (var image in item.Image) { products.Path = image.Path; } } if (products == null) { return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = "Không tìm thấy sản phẩm", Error = "Không tìm thấy sản phẩm" })); } else { if (getSession == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { ProductCart = products, Quantity = 1 }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { List <Item> cart = getSession; int index = IsExist(ids); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { ProductCart = products, Quantity = 1 }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = "Thêm sản phẩm vào giỏ hàng thành công", Error = null })); } } catch (Exception ex) { _logger.LogError("Thêm sản phẩm vào giỏ hàng thất bại: " + ex); return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = null, Error = "Thêm sản phẩm vào giỏ hàng thất bại" })); } }