public async Task Create_2_CatalogCategory_Successfully(string nameOfCategory1, string nameofCategory2)
        {
            await this._testFixture.InitData();

            var category1 = Category.Create(nameOfCategory1);
            var category2 = Category.Create(nameofCategory2);

            CatalogCategory catalogCategory1 = null;
            CatalogCategory catalogCategory2 = null;

            await this._testFixture.SeedingData <Category, CategoryId>(category1, category2);

            await this._testFixture.DoActionWithCatalog(catalog =>
            {
                catalogCategory1 =
                    catalog.AddCategory(category1.Id, category1.DisplayName);

                catalogCategory2 =
                    catalog.AddCategory(category2.Id, category2.DisplayName);
            });

            await this._testFixture.DoAssert(catalog =>
            {
                catalog.Categories.ShouldContain(catalogCategory1);
                catalog.Categories.ShouldContain(catalogCategory2);
            });
        }
Exemple #2
0
        public Task InitializeAsync()
        {
            this._mockDbContext = new Mock <DbContext>();
            var catalogRepository = new DefaultRepositoryAsync <Catalog>(this._mockDbContext.Object);
            var productRepository = new DefaultRepositoryAsync <Product>(this._mockDbContext.Object);

            this.MockRepositoryFactory
            .Setup(x => x.CreateRepository <Catalog>()).Returns(catalogRepository);
            this.MockRepositoryFactory
            .Setup(x => x.CreateRepository <Product>()).Returns(productRepository);

            this._catalog         = Catalog.Create(this.Fixture.Create <string>());
            this._category        = Category.Create(this.Fixture.Create <string>());
            this._product         = Product.Create(this.Fixture.Create <string>());
            this._catalogCategory = this._catalog.AddCategory(this._category.CategoryId, this._category.DisplayName);

            this._mockDbContext
            .Setup(x => x.Set <Catalog>())
            .ReturnsDbSet(new List <Catalog> {
                this._catalog
            });
            this._mockDbContext
            .Setup(x => x.Set <Product>())
            .ReturnsDbSet(new List <Product> {
                this._product
            });

            this._validator      = new CreateCatalogProductCommandValidator(this.MockRepositoryFactory.Object);
            this._requestHandler = new CommandHandler(this.MockRepositoryFactory.Object, this._validator);

            return(Task.CompletedTask);
        }
Exemple #3
0
        public CatalogCategory UpdateCatalogCategory(CatalogCategory updatedEntity)
        {
            var existingObj = this.context.CatalogCategories.Where(p => p.CategoryId == updatedEntity.CategoryId).FirstOrDefault();

            this.context.Entry(existingObj).CurrentValues.SetValues(updatedEntity);
            this.context.SaveChanges();
            return(updatedEntity);
        }
        public CategoriesViewModel(CatalogCategory category = null)
        {
            Category = category;

            SubCategories = new ObservableCollection <CatalogCategory>();

            _CatalogClient = DependencyService.Get <ICatalogDataClient>();
        }
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     CatalogMetadata.OnModelCreating(modelBuilder);
     CatalogGroup.OnModelCreating(modelBuilder);
     CatalogCategory.OnModelCreating(modelBuilder);
     CatalogDiscount.OnModelCreating(modelBuilder);
     base.OnModelCreating(modelBuilder);
 }
Exemple #6
0
        public override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            this.Category = Category.Create(this.Fixture.Create <string>());
            await this.SeedingData <Category, CategoryId>(this.Category);

            this.Catalog         = Catalog.Create(this.Fixture.Create <string>());
            this.CatalogCategory = this.Catalog.AddCategory(this.Category.Id, this.Category.DisplayName);
            await this.SeedingData <Catalog, CatalogId>(this.Catalog);
        }
        public override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            this.Category = Category.Create(this.AutoFixture.Create <string>());
            await this.SeedingData(this.Category);

            this.Product = Product.Create(this.AutoFixture.Create <string>());
            await this.SeedingData(this.Product);

            this.Catalog         = Catalog.Create(this.AutoFixture.Create <string>());
            this.CatalogCategory = this.Catalog.AddCategory(this.Category.CategoryId, this.Category.DisplayName);
            this.CatalogCategory.CreateCatalogProduct(this.Product.ProductId, this.Product.Name);
            await this.SeedingData(this.Catalog);
        }
Exemple #8
0
        public async Task InitData()
        {
            this.Catalog = Catalog.Create(this.Fixture.Create <string>());

            this.CatalogCategoryLv1 =
                this.Catalog.AddCategory(this.CategoryLv1.CategoryId, this.Fixture.Create <string>());
            this.CatalogCategoryLv2 =
                this.Catalog.AddCategory(this.CategoryLv2.CategoryId, this.Fixture.Create <string>(), this.CatalogCategoryLv1);
            this.CatalogCategoryLv3 =
                this.Catalog.AddCategory(this.CategoryLv3.CategoryId, this.Fixture.Create <string>(), this.CatalogCategoryLv2);

            await this.RepositoryExecute <Catalog>(async repository =>
            {
                await repository.AddAsync(this.Catalog);
            });
        }
Exemple #9
0
        public CatalogCategoryCellViewModel(CatalogCategory model, IRepository <CatalogCategory> categoryRepo)
        {
            _model          = model;
            _visibleToUsers = model.VisibleToUsers;

            this
            .WhenAnyValue(x => x.VisibleToUsers)
            .Skip(1)
            .Do(x => _model.VisibleToUsers = x)
            .SelectMany(
                _ =>
            {
                return(categoryRepo.Upsert(_model));
            })
            .Subscribe();
        }
        protected override async Task Handle(CreateCatalogCategoryCommand request, CancellationToken cancellationToken)
        {
            await this._validator.ValidateAndThrowAsync(request, null, cancellationToken);

            var catalog = await this._repository.FindOneWithIncludeAsync(x => x.CatalogId == request.CatalogId,
                                                                         x => x.Include(c => c.Categories));

            CatalogCategory parent = null;

            if (request.ParentCatalogCategoryId != null)
            {
                parent = catalog.Categories.SingleOrDefault(x => x.CatalogCategoryId == request.ParentCatalogCategoryId);
            }

            catalog.AddCategory(request.CategoryId, request.DisplayName, parent);

            await this._repository.UpdateAsync(catalog);
        }
Exemple #11
0
        public int CreateCatalogCategories(Category categoryModel)
        {
            WorkLinqToSql.CatalogCategory category = new CatalogCategory();
            try
            {
                CatalogDatabaseDataContext context = new CatalogDatabaseDataContext();

                var categoryNames = from cat in context.CatalogCategories select cat.Name;
                if (!categoryNames.Contains(categoryModel.Name))
                {
                    category.Name = categoryModel.Name;
                    context.CatalogCategories.InsertOnSubmit(category);
                    context.CatalogCategories.Context.SubmitChanges();
                }
            }
            catch
            {
                return(0);
            }
            return(category.Id);
        }
 public CatalogProduct()
 {
     Name            = Description = ImageUrl = string.Empty;
     Price           = 0;
     CatalogCategory = new CatalogCategory();
 }
Exemple #13
0
 public CatalogCategory CreateCatalogCategory(CatalogCategory entity)
 {
     this.context.CatalogCategories.Add(entity);
     this.context.SaveChanges();
     return(entity);
 }
 public CatalogProduct()
 {
     Name = Description = ImageUrl = string.Empty;
     Price = 0;
     CatalogCategory = new CatalogCategory();
 }
Exemple #15
0
        async Task <double> GetOrderTotalForCategoryAsync(IEnumerable <Order> orders, CatalogCategory category, int numberOfWeeks = 6, bool isOpen = false)
        {
            double total = 0;

            var categoryProducts = await _CatalogClient.GetAllChildProductsAsync(category.Id);

            DateTime dateEnd   = DateTime.UtcNow;
            DateTime dateStart = dateEnd.AddDays(-numberOfWeeks * 7);

            IEnumerable <Order> results;

            if (isOpen)
            {
                results = orders.Where(
                    order => order.IsOpen == isOpen &&
                    order.OrderDate >= dateStart &&
                    order.OrderDate <= dateEnd &&
                    categoryProducts.Any(product => product.Name.ToLower() == order.Item.ToLower()));
            }
            else
            {
                results = orders.Where(
                    order => order.IsOpen == isOpen &&
                    order.ClosedDate >= dateStart &&
                    order.ClosedDate <= dateEnd &&
                    categoryProducts.Any(product => product.Name.ToLower() == order.Item.ToLower()));
            }

            foreach (var order in results)
            {
                total += order.Price;
            }

            return(total);
        }
 public CatalogCategoryCellViewModel(CatalogCategory model, IViewStackService viewStackService = null)
     : base(viewStackService)
 {
     _model = model;
 }
        public CategoryListPage(string title = null, bool isPerformingProductSelection = false)
        {
            if (title == null)
            {
                Title = "Products";
            }

            SetBinding(CategoryListPage.TitleProperty, new Binding("Category", converter: new CategoryTitleConverter(Title)));

            #region category list
            CategoryListView categoryListView = new CategoryListView();
            categoryListView.SetBinding(CategoryListView.ItemsSourceProperty, "SubCategories");
            categoryListView.IsPullToRefreshEnabled = true;
            categoryListView.SetBinding(CategoryListView.RefreshCommandProperty, "LoadCategoriesCommand");
            categoryListView.SetBinding(CategoryListView.IsRefreshingProperty, "IsBusy", mode: BindingMode.OneWay);

            categoryListView.ItemTapped += async(sender, e) =>
                                           await App.ExecuteIfConnected(async() =>
            {
                CatalogCategory catalogCategory = ((CatalogCategory)e.Item);
                if (catalogCategory.HasSubCategories)
                {
                    await Navigation.PushAsync(new CategoryListPage(catalogCategory.Name, isPerformingProductSelection)
                    {
                        BindingContext = new CategoriesViewModel(catalogCategory)
                    });
                }
                else
                {
                    await Navigation.PushAsync(new ProductListPage(catalogCategory.Name, isPerformingProductSelection)
                    {
                        BindingContext = new ProductsViewModel(catalogCategory.Id)
                    });
                }
            });

            categoryListView.SetBinding(CategoryListView.HeaderProperty, ".");
            categoryListView.HeaderTemplate = new DataTemplate(() => {
                Label loadingLabel = new Label()
                {
                    Text      = TextResources.Products_CategoryList_LoadingLabel,
                    FontSize  = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                    XAlign    = TextAlignment.Center,
                    YAlign    = TextAlignment.End,
                    TextColor = Palette._007
                };
                loadingLabel.SetBinding(Label.IsEnabledProperty, "IsBusy", mode: BindingMode.OneWay);
                loadingLabel.SetBinding(Label.IsVisibleProperty, "IsBusy", mode: BindingMode.OneWay);
                return(loadingLabel);
            });
            #endregion

            #region compose view hierarchy
            Content = new UnspacedStackLayout()
            {
                Children =
                {
                    categoryListView
                }
            };
            #endregion
        }