#pragma warning disable 1998 public async Task <HttpResponseMessage> GetByDispensary(InventoryDataTableParams filter) { var query = HGContext.DispensaryProducts.AsNoTracking() .Include(p => p.DispensaryProductVariants.Select(v => v.Photos)) .Where(x => !x.IsDeleted && !x.Dispensary.IsDeleted); if (filter.dispensaryId > 0) { query = query.Where(i => i.DispensaryId == filter.dispensaryId); } if (filter.categoryId > 0) { query = query.Where(i => i.ProductCategory.Id == filter.categoryId); } if (!String.IsNullOrEmpty(filter.name)) { query = query.Where(i => i.Name.Contains(filter.name)); } if (filter.iSortCol_0 == 0) { query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.Name) : query.OrderBy(d => d.Product.Name); } if (filter.iSortCol_0 == 1) { query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.ProductCategory.Name) : query.OrderBy(d => d.Product.ProductCategory.Name); } if (filter.iSortCol_0 == 2) { query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.Description) : query.OrderBy(d => d.Product.Description); } var list = query.Skip(filter.iDisplayStart).Take(filter.iDisplayLength); var count = query.Count(); var mappedlist = list.Select(item => new DispensaryProductModel() { Id = item.Id, Name = item.Name, Description = item.Description, ProductCategory = item.ProductCategory == null ? null : new ProductCategoryModel() { Id = item.ProductCategory.Id, Name = item.ProductCategory.Name }, DispensaryProductVariants = item.DispensaryProductVariants.Select(v => new DispensaryProductVariantModel() { Id = v.Id, IsMasterVariant = v.IsMasterVariant, DisplayOrder = v.DisplayOrder, Name = v.Name, Photos = v.Photos.Select(p => new FileModel() { Id = p.Id }), IsPricedByWeight = v.IsPricedByWeight, VariantQuantity = v.VariantQuantity, VariantPricingJSON = v.VariantPricing }), Effects = item.Effects.Select(e => new EffectModel() { Id = e.Id, Name = e.Name }), Symptoms = item.Symptoms.Select(e => new SymptomModel() { Id = e.Id, Name = e.Name }), IsAvailable = item.IsAvailable, IsDiscounted = item.IsDiscounted, IsPopular = item.IsPopular, Slug = item.Slug, YouTubeVideoUrl = item.YouTubeVideoUrl }).ToList(); foreach (DispensaryProductModel product in mappedlist) { foreach (DispensaryProductVariantModel variant in product.DispensaryProductVariants) { variant.VariantPricing = Mapper.Map <List <VariantPricing> >(variant.VariantPricingJSON); } } GridModel <DispensaryProductModel> gritItems = new GridModel <DispensaryProductModel>() { aaData = mappedlist, iTotalDisplayRecords = count, iTotalRecords = count, sEcho = filter.sEcho }; return(Request.CreateResponse(HttpStatusCode.OK, gritItems)); }
#pragma warning disable 1998 public async Task<HttpResponseMessage> GetByDispensary(InventoryDataTableParams filter) { var query = HGContext.DispensaryProducts.AsNoTracking() .Include(p => p.DispensaryProductVariants.Select(v => v.Photos)) .Where(x => !x.IsDeleted && !x.Dispensary.IsDeleted); if (filter.dispensaryId > 0) query = query.Where(i => i.DispensaryId == filter.dispensaryId); if (filter.categoryId > 0) query = query.Where(i => i.ProductCategory.Id == filter.categoryId); if (!String.IsNullOrEmpty(filter.name)) query = query.Where(i => i.Name.Contains(filter.name)); if (filter.iSortCol_0 == 0) query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.Name) : query.OrderBy(d => d.Product.Name); if (filter.iSortCol_0 == 1) query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.ProductCategory.Name) : query.OrderBy(d => d.Product.ProductCategory.Name); if (filter.iSortCol_0 == 2) query = filter.sSortDir_0 == "desc" ? query.OrderByDescending(d => d.Product.Description) : query.OrderBy(d => d.Product.Description); var list = query.Skip(filter.iDisplayStart).Take(filter.iDisplayLength); var count = query.Count(); var mappedlist = list.Select(item => new DispensaryProductModel() { Id = item.Id, Name = item.Name, Description = item.Description, ProductCategory = item.ProductCategory == null ? null : new ProductCategoryModel() { Id = item.ProductCategory.Id, Name = item.ProductCategory.Name }, DispensaryProductVariants = item.DispensaryProductVariants.Select(v => new DispensaryProductVariantModel() { Id = v.Id, IsMasterVariant = v.IsMasterVariant, DisplayOrder = v.DisplayOrder, Name = v.Name, Photos = v.Photos.Select(p => new FileModel() { Id = p.Id }), IsPricedByWeight = v.IsPricedByWeight, VariantQuantity = v.VariantQuantity, VariantPricingJSON = v.VariantPricing }), Effects = item.Effects.Select(e => new EffectModel() { Id = e.Id, Name = e.Name }), Symptoms = item.Symptoms.Select(e => new SymptomModel() { Id = e.Id, Name = e.Name }), IsAvailable = item.IsAvailable, IsDiscounted = item.IsDiscounted, IsPopular = item.IsPopular, Slug = item.Slug, YouTubeVideoUrl = item.YouTubeVideoUrl }).ToList(); foreach (DispensaryProductModel product in mappedlist) { foreach (DispensaryProductVariantModel variant in product.DispensaryProductVariants) { variant.VariantPricing = Mapper.Map<List<VariantPricing>>(variant.VariantPricingJSON); } } GridModel<DispensaryProductModel> gritItems = new GridModel<DispensaryProductModel>() { aaData = mappedlist, iTotalDisplayRecords = count, iTotalRecords = count, sEcho = filter.sEcho }; return Request.CreateResponse(HttpStatusCode.OK, gritItems); }