public JsonResult List(Guid?categoryId, List <Guid> categoryIds, string keywords, int?skip, int?take, string sortField, string orderBy) { var xtake = 10; var xskip = 0; long total = 0; if (skip != null) { xskip = skip.Value; } if (take != null) { xtake = take.Value; } if (string.IsNullOrEmpty(sortField)) { sortField = nameof(FeNews.CreatedDate); } if (string.IsNullOrEmpty(orderBy)) { orderBy = "desc"; } List <FeProduct> rows = new List <FeProduct>(); List <ContentLanguage> contentLanguages = null; categoryIds = categoryIds ?? new List <Guid>(); if (categoryId != null && categoryId.Value != Guid.Empty) { categoryIds.Add(categoryId.Value); } var producs = ProductSearchServices.Search(keywords, LanguageId, categoryIds, null, xskip, xtake, out contentLanguages, out total); foreach (var p in producs) { var i = new FeProduct(); i.CreatedDate = p.CreatedDate; i.Id = p.Id; i.Price = p.Price; i.ProductCode = p.ProductCode; i.Published = p.Published; i.AllowComment = p.AllowComment; i.Title = contentLanguages.GetValue(i.Id, "Title"); i.UrlImage = contentLanguages.GetValue(i.Id, "UrlImage"); i.SeoUrlFriendly = contentLanguages.GetValue(i.Id, "SeoUrlFriendly"); rows.Add(i); } return(Json(new { total, rows, success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Detail(string urlsegment) { if (string.IsNullOrEmpty(urlsegment)) { return(Content("404 not found product")); } var model = new FeProduct(); List <ContentLanguage> contentLanguages; Guid id = Guid.Empty; using (var db = new DomainDrivenDesign.CoreEcommerce.Ef.CoreEcommerceDbContext()) { var temp = db.UrlFriendlys.FirstOrDefault( i => i.UrlSegment.Equals(urlsegment, StringComparison.OrdinalIgnoreCase) && i.TableName.Equals("Product", StringComparison.OrdinalIgnoreCase)); if (temp == null) { return(Content("404 not found product")); } id = temp.Id; var product = db.Products.FirstOrDefault(i => i.Id == id); if (product == null) { return(Content("404 not found product")); } model.Id = id; model.Quantity = product.Quantity; model.Gram = product.Gram; model.Calorie = product.Calorie; model.ProductCode = product.ProductCode; model.AllowComment = product.AllowComment; model.Price = product.Price; model.IsCombo = product.IsCombo; model.Galleries = db.PhotoGalleries.Where(i => i.Id == id).Select(i => i.UrlImage).ToList(); model.ProductsInCombo = db.Products.Join(db.ProductInCombos, px => px.Id, c => c.ProductComboId, (px, c) => new { P = px, C = c }) .Where(m => m.C.ProductId == id).Select(m => new FeProduct.ProductInCombo { Id = m.P.Id, Price = m.P.Price, ProductCode = m.P.ProductCode, Published = m.P.Published }).ToList(); model.Promotions = db.ProductPromotions.Join(db.RelationShips, pp => pp.Id, r => r.FromId , (pp, r) => new { R = r, Pp = pp }).Where(m => m.R.ToId == id) .Select(m => new FeProductPromotion() { Id = m.Pp.Id, DiscountValue = m.Pp.DiscountValue, CreatedDate = m.Pp.CreatedDate, ProductQuantity = m.Pp.ProductQuantity, FromDate = m.Pp.FromDate, ToDate = m.Pp.ToDate }).OrderByDescending(m => m.CreatedDate).ToList(); var ids = new List <Guid>(); ids.Add(id); ids.AddRange(model.ProductsInCombo.Select(i => i.Id).ToList()); ids.AddRange(model.Promotions.Select(i => i.Id).ToList()); contentLanguages = db.ContentLanguages.Where(i => ids.Contains(i.Id)).ToList(); } model.Title = contentLanguages.GetValue(id, "Title"); model.ShortDescription = contentLanguages.GetValue(id, "ShortDescription"); model.Description = contentLanguages.GetValue(id, "Description"); model.SeoKeywords = contentLanguages.GetValue(id, "SeoKeywords"); model.UrlImage = contentLanguages.GetValue(id, "UrlImage"); model.SeoDescription = contentLanguages.GetValue(id, "SeoDescription"); foreach (var pc in model.ProductsInCombo) { pc.Title = contentLanguages.GetValue(pc.Id, "Title"); } foreach (var pm in model.Promotions) { pm.Description = contentLanguages.GetValue(pm.Id, "Description"); } return(View(model)); }
public JsonResult ListResult(string keywords, int?skip, int?take, string sortField, string orderBy) { var xtake = 10; var xskip = 0; long total = 0; if (skip != null) { xskip = skip.Value; } if (take != null) { xtake = take.Value; } if (string.IsNullOrEmpty(sortField)) { sortField = nameof(FeProduct.CreatedDate); } if (string.IsNullOrEmpty(orderBy)) { orderBy = "desc"; } List <FeProduct> rows = new List <FeProduct>(); if (!string.IsNullOrEmpty(keywords)) { List <ContentLanguage> contentLanguages = null; var tempProduct = ProductSearchServices.Search(keywords, LanguageId, new List <Guid>() { }, true, xskip, xtake, out contentLanguages, out total); if (tempProduct.Count == 0) { rows.Add(new FeProduct() { Title = "Not found any content match with keywords" }); } else { foreach (var p in tempProduct) { var i = new FeProduct(); i.CreatedDate = p.CreatedDate; i.Id = p.Id; i.ProductCode = p.ProductCode; i.Price = p.Price; i.Quantity = p.Quantity; i.Published = p.Published; i.Title = contentLanguages.GetValue(p.Id, "Title"); i.ShortDescription = contentLanguages.GetValue(p.Id, "ShortDescription"); i.UrlImage = contentLanguages.GetValue(p.Id, "UrlImage"); i.SeoUrlFriendly = contentLanguages.GetValue(p.Id, "SeoUrlFriendly"); rows.Add(i); } } } else { rows.Add(new FeProduct() { Title = "No keywords to search" }); } return(Json(new { total, rows, success = true }, JsonRequestBehavior.AllowGet)); }