public IHttpActionResult GetAll([FromUri] ProductRequestBindingModel model) { if (model == null) { model = new ProductRequestBindingModel(); } if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var products = this.Data.Products.All(); if (model.Id.HasValue) { products = products.Where(p => p.Id == model.Id.Value); } if (model.CategoryName != null) { products = products.Where(p => p.Category.Name == model.CategoryName); } if (model.TradeName != null) { products = products.Where(p => p.Trade.Name == model.TradeName); } if (model.CategoryId.HasValue) { products = products.Where(p => p.CategoryId == model.CategoryId.Value); } if (model.TradeId.HasValue) { products = products.Where(p => p.TradeId == model.TradeId); } if (model.Name != null) { products = products.Where(p => p.Name.Contains(model.Name)); } if (model.FromPrice.HasValue) { products = products.Where(p => p.Price >= model.FromPrice.Value); } if (model.ToPrice.HasValue) { products = products.Where(p => p.Price <= model.ToPrice.Value); } if (model.InPromotion.HasValue) { if (model.InPromotion.Value) { products = products.Where(p => p.Promotions.Any()); } else { products = products.Where(p => !p.Promotions.Any()); } } var productToRetutn = products .Select(ProductBindingModel.FromProduct) .AsEnumerable(); var promotionDecorator = new ItemPromotionProvider(productToRetutn, this.Data); promotionDecorator.Decorate(); return Ok(promotionDecorator.ResultSet); }
public IHttpActionResult GetAll([FromUri] ProductRequestBindingModel model) { if (model == null) { model = new ProductRequestBindingModel(); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var products = this.Data.Products.All(); if (model.Id.HasValue) { products = products.Where(p => p.Id == model.Id.Value); } if (model.CategoryName != null) { products = products.Where(p => p.Category.Name == model.CategoryName); } if (model.TradeName != null) { products = products.Where(p => p.Trade.Name == model.TradeName); } if (model.CategoryId.HasValue) { products = products.Where(p => p.CategoryId == model.CategoryId.Value); } if (model.TradeId.HasValue) { products = products.Where(p => p.TradeId == model.TradeId); } if (model.Name != null) { products = products.Where(p => p.Name.Contains(model.Name)); } if (model.FromPrice.HasValue) { products = products.Where(p => p.Price >= model.FromPrice.Value); } if (model.ToPrice.HasValue) { products = products.Where(p => p.Price <= model.ToPrice.Value); } if (model.InPromotion.HasValue) { if (model.InPromotion.Value) { products = products.Where(p => p.Promotions.Any()); } else { products = products.Where(p => !p.Promotions.Any()); } } var productToRetutn = products .Select(ProductBindingModel.FromProduct) .AsEnumerable(); var promotionDecorator = new ItemPromotionProvider(productToRetutn, this.Data); promotionDecorator.Decorate(); return(Ok(promotionDecorator.ResultSet)); }