public void Update(IShoppingEntity entity, IByIdRepositorySpecification <IShoppingEntity, long> spec, Action <IShoppingEntity> success, Action <Exception> error)
        {
            if (spec is ShoppingRepositoryByIdSpecification)
            {
                ReactiveFunction(() =>
                {
                    var id          = (spec as ShoppingRepositoryByIdSpecification).Id;
                    var rawShopping = simpleDb.GetShoppingById(id);

                    if (rawShopping.Id == id)
                    {
                        rawShopping.Created  = entity.Creation;
                        rawShopping.Finished = entity.Finished;
                        simpleDb.SetShopping(rawShopping);

                        return(entity);
                    }

                    return(entityFactory.EmptyShopping());
                }
                                 , list =>
                {
                    success.Invoke(list);
                }, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }
        public void GetById(IByIdRepositorySpecification <IShoppingItemEntity, long> byIdRepositorySpecification, Action <IShoppingItemEntity> success, Action <Exception> error)
        {
            if (byIdRepositorySpecification is ShoppingItemQueryByIdRepositorySpecification)
            {
                ReactiveFunction(() =>
                {
                    var shoppingId = (byIdRepositorySpecification as ShoppingItemQueryByIdRepositorySpecification).ShoppingId;
                    var itemId     = (byIdRepositorySpecification as ShoppingItemQueryByIdRepositorySpecification).Id;

                    return(ProcessByIdRequest(shoppingId, itemId, null));
                }
                                 , success, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Esempio n. 3
0
        public void Update(IFavoriteProductEntity entity, IByIdRepositorySpecification <IFavoriteProductEntity, long> spec, Action <IFavoriteProductEntity> success, Action <Exception> error)
        {
            if (spec is FavoriteProductRepositoryByIdSpecification)
            {
                ReactiveFunction(() =>
                {
                    var favorite = new Favorite
                    {
                        Id         = entity.Id,
                        IsFavorite = entity.IsFavorite
                    };

                    simpleDb.SetFavorite(favorite);

                    return(entity);
                }

                                 , success, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Esempio n. 4
0
        public void GetById(IByIdRepositorySpecification <IProductAggregation, long> byIdRepositorySpecification, Action <IProductAggregation> success, Action <Exception> error)
        {
            if (byIdRepositorySpecification is ProductRepositoryByIdSpecification || byIdRepositorySpecification is ShoppingProductRepositoryByIdSpecification)
            {
                ReactiveFunction(() =>
                {
                    var shoppingId = byIdRepositorySpecification is ShoppingProductRepositoryByIdSpecification? (byIdRepositorySpecification as ShoppingProductRepositoryByIdSpecification).ShoppingId: 0;
                    var productId  = (byIdRepositorySpecification as ProductRepositoryByIdSpecification).Id;

                    var shoppingItem = simpleDb.GetShoppingItemById(shoppingId, productId);
                    var product      = restApi.ListProducts().FirstOrDefault(x => x.Id == productId);
                    var category     = restApi.ListCategories().FirstOrDefault(x => x.Id == (product?.Category_Id ?? -1));
                    var promotion    = restApi.ListPromotions().FirstOrDefault(x => x.Category_Id == (category?.Id ?? -1));

                    if (product != null)
                    {
                        var productDetailValue    = valueFactory.NewProductDetail(product.Name, product.Description, product.Photo, product.Price, product.Category_Id);
                        var promotionDetailValues = promotion?.Policies.Select(x => valueFactory.NewProductPromotionDetail(x.Min, x.Discount)).ToList();
                        var promotionValue        = valueFactory.NewProductPromotion(promotion?.Name ?? "", promotion?.Category_Id ?? 0, promotionDetailValues ?? new List <IProductPromotionDetailValue>());
                        var categoryEntity        = category != null ? entityFactory.NewProductCategory(category.Id, category.Name) : entityFactory.EmptyProductCategory();

                        return(entityFactory.NewProduct(product.Id, productDetailValue, promotionValue, categoryEntity, shoppingItem?.Discount ?? 0, shoppingItem?.Quantity ?? 0, shoppingItem?.Favorite ?? false));
                    }

                    return(entityFactory.EmptyProduct());
                }
                                 , item =>
                {
                    success.Invoke(item);
                }, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }
        public void Update(IShoppingItemEntity entity, IByIdRepositorySpecification <IShoppingItemEntity, long> spec, Action <IShoppingItemEntity> success, Action <Exception> error)
        {
            if (spec is ShoppingItemUpdateByIdRepositorySpecification)
            {
                ReactiveFunction(() =>
                {
                    var shoppingId = (spec as ShoppingItemUpdateByIdRepositorySpecification).ShoppingId;
                    var itemId     = (spec as ShoppingItemUpdateByIdRepositorySpecification).Id;

                    return(ProcessByIdRequest(shoppingId, itemId, (shopping, shoppingItem, product, productDetailValue, promotionValue) =>
                    {
                        shoppingItem.Quantity = entity.Quantity;
                        shoppingItem.Discount = entity.Discount;

                        simpleDb.SetShoppingItem(shoppingId, shoppingItem);
                    }));
                }
                                 , success, error);
            }
            else
            {
                throw new ArgumentException();
            }
        }
 public void GetById(IByIdRepositorySpecification <IShoppingEntity, long> byIdRepositorySpecification, Action <IShoppingEntity> success, Action <Exception> error)
 {
     throw new NotImplementedException();
 }