public void Find(IRepositorySpecification <IProductAggregation, long> repositorySpecification, Action <IList <IProductAggregation> > success, Action <Exception> error) { if (repositorySpecification is ProductRepositoryListCatalogSpecification || repositorySpecification is ProductRepositoryCartSpecification) { ReactiveFunction(() => { var isCatalog = repositorySpecification is ProductRepositoryListCatalogSpecification; var shoppingId = isCatalog? (repositorySpecification as ProductRepositoryListCatalogSpecification).ShoppingId: (repositorySpecification as ProductRepositoryCartSpecification).ShoppingId; var shoppingItems = simpleDb.ListShoppingItems(shoppingId); var products = restApi.ListProducts(); if (!isCatalog) { products = products.Join(shoppingItems.Where(x => x.Quantity > 0), product => product.Id, shoppingItem => shoppingItem.Id, (p, i) => p).ToList(); } if (products?.Count > 0) { var categories = restApi.ListCategories(); var promotions = restApi.ListPromotions(); return(products.Select(x => { var shoppingItem = shoppingItems.FirstOrDefault(y => y.Id == x.Id); var category = categories.FirstOrDefault(y => y.Id == x.Category_Id); var favorite = simpleDb.GetFavorite(x.Id); var promotion = restApi.ListPromotions().FirstOrDefault(y => y.Category_Id == (category?.Id ?? -1)); var productDetail = valueFactory.NewProductDetail(x.Name, x.Description, x.Photo, x.Price, x.Category_Id); var categoryEntity = category != null ? entityFactory.NewProductCategory(category.Id, category.Name) : entityFactory.EmptyProductCategory(); var promotionDetailValues = promotion?.Policies.Select(y => valueFactory.NewProductPromotionDetail(y.Min, y.Discount)).ToList(); var promotionValue = valueFactory.NewProductPromotion(promotion?.Name ?? "", promotion?.Category_Id ?? 0, promotionDetailValues ?? new List <IProductPromotionDetailValue>()); return entityFactory.NewProduct(x.Id, productDetail, promotionValue, categoryEntity, shoppingItem?.Discount ?? 0, shoppingItem?.Quantity ?? 0, favorite.IsFavorite); }).ToList()); } return(new List <IProductAggregation>()); } , list => { success.Invoke(list); }, error); } else { throw new ArgumentException(); } }
public void Find(IRepositorySpecification <IShoppingEntity, long> repositorySpecification, Action <IList <IShoppingEntity> > success, Action <Exception> error) { if (repositorySpecification is ShoppingRepositorySpecification) { ReactiveFunction(() => { var rawShoppings = simpleDb.ListShoppings(); if (rawShoppings?.Count > 0) { return(rawShoppings.Select(x => entityFactory.NewShopping(x.Id, x.Created, x.Finished)).ToList()); } return(new List <IShoppingEntity>()); } , list => { success.Invoke(list); }, error); } else { throw new ArgumentException(); } }
public void Find(IRepositorySpecification <IProductCategoryEntity, long> repositorySpecification, Action <IList <IProductCategoryEntity> > success, Action <Exception> error) { if (repositorySpecification is ProductCategoryRepositoryListSpecification) { ReactiveFunction(() => { var restCategries = restApi.ListCategories(); if (restCategries?.Count > 0) { return(restCategries.Select(y => entityFactory.NewProductCategory(y.Id, y.Name)).ToList()); } return(new List <IProductCategoryEntity>()); } , categories => { success.Invoke(categories); }, error); } else { throw new ArgumentException(); } }
public void Find(IRepositorySpecification <IShoppingItemEntity, long> repositorySpecification, Action <IList <IShoppingItemEntity> > success, Action <Exception> error) { throw new NotImplementedException(); }