public static void Do(Products products, string keyword)
        {
            products.Type = AggregationType.BySearch;

            string[] keywords = keyword.Split(new char[] {',', ';', ' '});

            Remix.Server server = new Remix.Server("", "");
            Remix.Products remixProducts = server.GetProductByKeywords(keywords, products.CurrentPage);

            List<string> relatedSkuList = new List<string>();
            if (remixProducts != null && remixProducts.Count > 0)
            {
                int.TryParse(remixProducts.TotalPages, out products.TotalPages);
                int.TryParse(remixProducts.Total, out products.Total);
                int.TryParse(remixProducts.To, out products.To);
                int.TryParse(remixProducts.From, out products.From);
                int.TryParse(remixProducts.CurrentPage, out products.CurrentPage);

                foreach (var remixProduct in remixProducts)
                {
                    Product product = new Product();
                    product.BBYSKU = remixProduct.Sku;
                    product.UPC = remixProduct.UPC;
                    product.Name = remixProduct.Name;
                    product.BBYCategoryPath = remixProduct.CategoryPath.ToArray();
                    product.ThumbnailImageUrl = string.IsNullOrEmpty(remixProduct.ImageUrl) ?
                        remixProduct.ThumbnailimageUrl : remixProduct.ImageUrl;
                    product.LargeImageUrl = remixProduct.LargeImageUrl;
                    product.BBYUrl = remixProduct.BBYUrl;

                    product.BBYSubClassId = remixProduct.SubclassId;
                    product.BBYSubClassName = remixProduct.Subclass;

                    product.DescShort = remixProduct.ShortDescription;
                    decimal.TryParse(remixProduct.SalePrice, out product.BBYSalePrice);

                    if (remixProduct.RelatedProducts != null)
                    {
                        foreach (var sku in remixProduct.RelatedProducts)
                        {
                            product.SimilarProducts.Add(new Product() { BBYSKU = sku });
                            relatedSkuList.Add(sku);
                        }
                    }

                    products.Add(product);
                }
            }

            //
        }
예제 #2
0
 public void AddProduct(Product product)
 {
     Products.Add(product);
     ModifiedDateTime = DateTime.UtcNow;
 }
예제 #3
0
 public void AddProduct(Product product)
 {
     Products.Add(product);
     SubAll(product.Listeners);
 }
예제 #4
0
        /// <summary>
        /// Initializes the instance of <see cref="MenuMergingViewModel"/> class.
        /// </summary>
        public MenuMergingViewModel()
        {
            this.Products = new ObservableCollection <ChartModel>();
            Random rndm = new Random();

            CommonResourceDictionary = new ResourceDictionary()
            {
                Source = new Uri("/syncfusion.navigationdemos.wpf;component/Assets/Menu/Icon.xaml", UriKind.RelativeOrAbsolute)
            };
            newGridCommand        = new DelegateCommand <object>(OpenNewGrid);
            newChartCommand       = new DelegateCommand <object>(OpenNewChart);
            newCommand            = new DelegateCommand <object>(OpenNew);
            tileHorizontalCommand = new DelegateCommand <object>(TileHorizontal);
            tileVerticallCommand  = new DelegateCommand <object>(TileVertical);
            tileCascadeCommand    = new DelegateCommand <object>(Cascade);
            helpCommand           = new DelegateCommand <object>(ExecuteHelpCommand);
            aboutCommand          = new DelegateCommand <object>(ExecuteAboutCommand);

            Products.Add(new ChartModel()
            {
                ProductId = 1, ProductName = "Rice", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 2, ProductName = "Wheat", OldPrice = rndm.Next(5, 80), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 1, ProductName = "Oil", OldPrice = rndm.Next(5, 60), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 4, ProductName = "Corn", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 5, ProductName = "Gram", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 6, ProductName = "Milk", OldPrice = rndm.Next(5, 90), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 7, ProductName = "Butter", OldPrice = rndm.Next(5, 40), NewPrice = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 8, ProductName = "Oil", OldPrice = rndm.Next(5, 60), NewPrice = rndm.Next(10, 60)
            });

            FileCollection   = new ObservableCollection <MenuMergingModel>();
            WindowCollection = new ObservableCollection <MenuMergingModel>();

            FileModel = new MenuMergingModel()
            {
                Name = "File"
            };
            FileModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "New Product Details", Icon = CommonResourceDictionary["New"] as object, ImageTemplate = CommonResourceDictionary["NewPathIcon"] as DataTemplate, Command = NewGridCommand
            });
            FileModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "New product Statistics", Icon = CommonResourceDictionary["FileChart"] as object, ImageTemplate = CommonResourceDictionary["ChartPathIcon"] as DataTemplate, Command = NewChartCommand
            });
            FileModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Open", Icon = CommonResourceDictionary["Open"] as object, ImageTemplate = CommonResourceDictionary["OpenPathIcon"] as DataTemplate, Command = NewCommand
            });
            FileModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Exit", Icon = CommonResourceDictionary["FileDelete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand
            });

            WindowModel = new MenuMergingModel()
            {
                Name = "Windows"
            };
            WindowModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Cascade", Icon = CommonResourceDictionary["CascadeWindow"] as object, ImageTemplate = CommonResourceDictionary["CascadeWindowPathIcon"] as DataTemplate, Command = TileCascadeCommand, IsCheckable = true
            });
            WindowModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Tile Horizontally", Icon = CommonResourceDictionary["ArrangeWindow"] as object, ImageTemplate = CommonResourceDictionary["ArrangeWindowPathIcon"] as DataTemplate, Command = TileHorizontalCommand, IsCheckable = true
            });
            WindowModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Tile Vertically", Icon = CommonResourceDictionary["SideBySide"] as object, ImageTemplate = CommonResourceDictionary["SideBySidePathIcon"] as DataTemplate, Command = TileVerticalCommand, IsCheckable = true
            });

            WindowModel.MenuMergingCollection[0].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
            WindowModel.MenuMergingCollection[1].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
            WindowModel.MenuMergingCollection[2].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);

            ChartModel = new MenuMergingModel()
            {
                Name = "Chart View"
            };
            ChartModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "New Statistics", Icon = CommonResourceDictionary["Chart"] as object, ImageTemplate = CommonResourceDictionary["ChartPathIcon"] as DataTemplate, Command = NewCommand
            });
            ChartModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Refresh Chart", Icon = CommonResourceDictionary["Repeat"] as object, ImageTemplate = CommonResourceDictionary["RepeatPathIcon"] as DataTemplate, Command = NewCommand
            });
            ChartModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Publish Data", Icon = CommonResourceDictionary["PublishWeb"] as object, ImageTemplate = CommonResourceDictionary["PublishWebPathIcon"] as DataTemplate, Command = NewCommand
            });
            ChartModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Close View", Icon = CommonResourceDictionary["Delete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand
            });

            Chart1Model = new MenuMergingModel()
            {
                Name = "Customize Chart"
            };
            Chart1Model.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Change Chart Type", Icon = CommonResourceDictionary["Pie"] as object, ImageTemplate = CommonResourceDictionary["AlignToBottomPathIcon"] as DataTemplate, Command = NewCommand
            });
            Chart1Model.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Add Series", Icon = CommonResourceDictionary["AlignToBottom"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand
            });

            this.PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);

            GridModel = new MenuMergingModel()
            {
                Name = "Grid View"
            };
            GridModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Refresh Grid", Icon = CommonResourceDictionary["GridRepeat"] as object, ImageTemplate = CommonResourceDictionary["RepeatPathIcon"] as DataTemplate, Command = NewCommand
            });
            GridModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Close View", Icon = CommonResourceDictionary["GridDelete"] as object, ImageTemplate = CommonResourceDictionary["DeletePathIcon"] as DataTemplate, Command = NewCommand
            });

            HelpModel = new MenuMergingModel()
            {
                Name = "Help"
            };
            HelpModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "Online Help", Icon = CommonResourceDictionary["Help"] as object, Command = HelpCommand
            });
            HelpModel.MenuMergingCollection.Add(new MenuMergingModel()
            {
                Name = "About", Command = AboutCommand
            });

            OtherCollection        = new ObservableCollection <MenuMergingModel>();
            OtherToolBarCollection = new ObservableCollection <MenuMergingModel>();
            OtherCollection.Add(FileModel);
            FileCollection = FileModel.MenuMergingCollection;
            OtherCollection.Add(WindowModel);
            WindowCollection = WindowModel.MenuMergingCollection;
        }
예제 #5
0
 public virtual void AddProduct(Product product)
 {
     product.StoresStockedIn.Add(this);
     Products.Add(product);
 }
예제 #6
0
        public async Task LoadPopularProducts()
        {
            stagedProductList = await ProductRepository.GetProductsAsync();

            stagedProductList.ForEach(p => Products.Add(p));
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="value"></param>
        private void AddItem(ItemType itemType, object value)
        {
            if (value.ToString().Length == 0)
            {
                return;
            }

            switch (itemType)
            {
            case ItemType.IpAddress:
                var ipAddresses = from ipAddress in IpAddresses where ipAddress.Text.ToUpper() == ((string)value).ToUpper() select ipAddress;
                if (ipAddresses.Count() == 0)
                {
                    IpAddress ipAddress = new IpAddress();
                    ipAddress.Text = (string)value;
                    IpAddresses.Add(ipAddress);
                }
                break;

            case ItemType.HostName:
                var hosts = from host in HostNames where host.ToUpper() == ((string)value).ToUpper() select host;
                if (hosts.Count() == 0)
                {
                    HostNames.Add((string)value);
                }
                break;

            case ItemType.Port:
                var ports = from port in Ports where port == (int)value select port;
                if (ports.Count() == 0)
                {
                    Ports.Add((int)value);
                }
                break;

            case ItemType.Protocol:
                var protocols = from protocol in Protocols where protocol.ToUpper() == ((string)value).ToUpper() select protocol;
                if (protocols.Count() == 0)
                {
                    Protocols.Add(((string)value).ToUpper());
                }
                break;

            case ItemType.Service:
                var services = from service in Services where service.ToUpper() == ((string)value).ToUpper() select service;
                if (services.Count() == 0)
                {
                    Services.Add((string)value);
                }
                break;

            case ItemType.State:
                var states = from state in States where state.ToUpper() == ((string)value).ToUpper() select state;
                if (states.Count() == 0)
                {
                    States.Add((string)value);
                }
                break;

            case ItemType.Severities:
                var severities = from severity in Severities where severity.ToUpper() == ((string)value).ToUpper() select severity;
                if (severities.Count() == 0)
                {
                    Severities.Add((string)value);
                }
                break;

            case ItemType.PluginFamily:
                var pluginFamilies = from pluginFamily in PluginFamilys where pluginFamily.ToUpper() == ((string)value).ToUpper() select pluginFamily;
                if (pluginFamilies.Count() == 0)
                {
                    PluginFamilys.Add((string)value);
                }
                break;

            case ItemType.PluginId:
                var pluginIds = from pluginId in PluginIds where pluginId.ToString().ToUpper() == ((string)value).ToUpper() select pluginId;
                if (pluginIds.Count() == 0)
                {
                    PluginIds.Add(int.Parse(value.ToString()));
                }
                break;

            case ItemType.PluginName:
                var pluginNames = from pluginName in PluginNames where pluginName.ToUpper() == ((string)value).ToUpper() select pluginName;
                if (pluginNames.Count() == 0)
                {
                    PluginNames.Add((string)value);
                }
                break;

            case ItemType.Product:
                var products = from product in Products where product.ToUpper() == ((string)value).ToUpper() select product;
                if (products.Count() == 0)
                {
                    Products.Add((string)value);
                }
                break;

            case ItemType.Versions:
                var versions = from version in Versions where version.ToUpper() == ((string)value).ToUpper() select version;
                if (versions.Count() == 0)
                {
                    Versions.Add((string)value);
                }
                break;

            case ItemType.ExploitAvailable:
                var exploitAvailable = from e in ExploitAvailable where e.ToUpper() == ((string)value).ToUpper() select e;
                if (exploitAvailable.Count() == 0)
                {
                    ExploitAvailable.Add((string)value);
                }
                break;

            default:
                break;
            }
        }
예제 #8
0
 public void Add(ProductToSell product)
 {
     Products.Add(product);
 }
        private void AddButter(Products products, int quantity)
        {
            Butter butter = new Butter(quantity);

            products.Add(butter);
        }
예제 #10
0
        private void fill()
        {
            MyCategory category1 = new MyCategory();

            category1.Name = "Clothing";
            MyCategory category2 = new MyCategory();

            category2.Name = "Tools";

            MyVendor vendor1 = new MyVendor();

            vendor1.Name = "Nike";
            MyVendor vendor2 = new MyVendor();

            vendor2.Name = "Castorama";
            MyVendor vendor3 = new MyVendor();

            vendor3.Name = "Decathlon";

            MyProduct product1 = new MyProduct();

            product1.Name     = "Hammer";
            product1.Category = category2;
            product1.Vendor   = vendor2;

            MyProduct product2 = new MyProduct();

            product2.Name     = "T-shirt";
            product2.Category = category1;
            product2.Vendor   = vendor1;

            MyProduct product3 = new MyProduct();

            product3.Name     = "Screwdriver";
            product3.Category = category2;
            product3.Vendor   = vendor2;

            MyProduct product4 = new MyProduct();

            product4.Name     = "Shoes";
            product4.Category = category1;
            product4.Vendor   = vendor3;

            MyProduct product5 = new MyProduct();

            product5.Name     = "Trousers";
            product5.Category = category1;
            product5.Vendor   = vendor2;

            Categories.Add(category1);
            Categories.Add(category2);

            Vendors.Add(vendor1);
            Vendors.Add(vendor2);
            Vendors.Add(vendor3);

            Products.Add(product1);
            Products.Add(product2);
            Products.Add(product3);
            Products.Add(product4);
            Products.Add(product5);
        }
예제 #11
0
        public void AddPurchaseOrders(IEnumerable <PurchaseOrder> purchaseOrders)
        {
            if (Status != DeliveryStatus.Waiting)
            {
                throw SheaftException.Validation(
                          "Impossible de modifier les commandes d'une livraison qui n'est pas en attente");
            }

            if (purchaseOrders == null || !purchaseOrders.Any())
            {
                return;
            }

            PurchaseOrders ??= new List <PurchaseOrder>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                if (purchaseOrder.DeliveryId.HasValue)
                {
                    purchaseOrder.Delivery.RemovePurchaseOrders(new List <PurchaseOrder> {
                        purchaseOrder
                    });
                }

                PurchaseOrders.Add(purchaseOrder);
            }

            Products ??= new List <DeliveryProduct>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                foreach (var purchaseOrderProduct in purchaseOrder.Products)
                {
                    var preparedQuantity = 0;
                    if (purchaseOrder.PickingId.HasValue)
                    {
                        var preparedProduct = purchaseOrder.Picking.PreparedProducts.FirstOrDefault(p =>
                                                                                                    p.ProductId == purchaseOrderProduct.ProductId && p.PurchaseOrderId == purchaseOrder.Id);

                        if (preparedProduct != null)
                        {
                            preparedQuantity = preparedProduct.Quantity;
                        }
                    }
                    else
                    {
                        preparedQuantity = purchaseOrderProduct.Quantity;
                    }

                    var existingProduct = Products.FirstOrDefault(p =>
                                                                  p.ProductId == purchaseOrderProduct.ProductId && p.RowKind == ModificationKind.ToDeliver);

                    if (existingProduct != null)
                    {
                        existingProduct.AddQuantity(preparedQuantity);
                    }
                    else if (preparedQuantity > 0)
                    {
                        Products.Add(new DeliveryProduct(purchaseOrderProduct, preparedQuantity,
                                                         ModificationKind.ToDeliver));
                    }
                }
            }

            Refresh();
        }
예제 #12
0
 private async Task AddProduct(Product p)
 {
     await App.Current.Dispatcher.BeginInvoke(
         (Action) delegate() { Products.Add(new ProductViewModel(p)); });
 }
예제 #13
0
        public IActionResult Index(int?page)
        {
            const string SqlFilterProduct          = "join Recipe_Products frp on frp.RecipeId = r.RecipeId ";
            const string SqlFilterNationalCuisines = "join Recipe_NationalCuisines frn on frn.RecipeId = r.RecipeId ";
            const string SqlFilterTypeOfDishes     = "join Recipe_TypeOfDishes frt on frt.RecipeId = r.RecipeId ";
            const string SqlTopFilter = "SELECT Distinct TOP (10) " +
                                        "Products.ProductId as itemId, 'Top products' as itemType, Products.ProductName as itemName, " +
                                        "COUNT(Distinct Recipe_Products.RecipeId) AS itemCount, 0 as itemSort, " +
                                        "'' as itemChecked, '1' as mainsort," +
                                        "CONCAT('/filter?flp=',Products.ProductId) as itemLink " +
                                        "FROM Products JOIN Recipe_Products ON Recipe_Products.ProductId = Products.ProductId join ProductTypes pt on pt.ProductTypeId = Products.ProductTypeId " +
                                        "WHERE Recipe_Products.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                                        SqlFilterProduct +
                                        SqlFilterNationalCuisines +
                                        SqlFilterTypeOfDishes +
                                        ") GROUP BY Products.ProductId,pt.ProductTypeName,Products.ProductName ORDER BY itemCount DESC ";
            const string SqlFilter = "SELECT Distinct " +
                                     "Products.ProductId as itemId, pt.ProductTypeName as itemType, Products.ProductName as itemName, " +
                                     "COUNT(Distinct Recipe_Products.RecipeId) AS itemCount, 1 as itemSort, " +
                                     "'' as itemChecked, '4' as mainsort," +
                                     "CONCAT('/filter?flp=',Products.ProductId) as itemLink " +
                                     "FROM Products JOIN Recipe_Products ON Recipe_Products.ProductId = Products.ProductId join ProductTypes pt on pt.ProductTypeId = Products.ProductTypeId " +
                                     "WHERE Recipe_Products.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                                     SqlFilterProduct +
                                     SqlFilterNationalCuisines +
                                     SqlFilterTypeOfDishes +
                                     ") GROUP BY Products.ProductId,pt.ProductTypeName,Products.ProductName " +
                                     "UNION " +
                                     "SELECT Distinct " +
                                     "NationalCuisines.NationalCuisineId as itemId, 'National Cuisines' as itemType, NationalCuisines.NationalCuisineName as itemName, " +
                                     "COUNT(Distinct Recipe_NationalCuisines.RecipeId) AS itemCount, 2 as itemSort, " +
                                     "'' as itemChecked,  '3' as mainsort," +
                                     "CONCAT('/filter?flc=',NationalCuisines.NationalCuisineId) as itemLink " +
                                     "FROM NationalCuisines JOIN Recipe_NationalCuisines ON Recipe_NationalCuisines.NationalCuisineId = NationalCuisines.NationalCuisineId " +
                                     "WHERE Recipe_NationalCuisines.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                                     SqlFilterProduct +
                                     SqlFilterNationalCuisines +
                                     SqlFilterTypeOfDishes +
                                     ") GROUP BY NationalCuisines.NationalCuisineId,NationalCuisines.NationalCuisineName " +
                                     "UNION " +
                                     "SELECT Distinct " +
                                     "TypeOfDishes.TypeOfDishId as itemId, 'Type Of Dishes' as itemType, TypeOfDishes.TypeOfDishName as itemName, " +
                                     "COUNT(Distinct Recipe_TypeOfDishes.RecipeId) AS itemCount, 3 as itemSort, " +
                                     "'' as itemChecked, '2' as mainsort, " +
                                     "CONCAT('/filter?fld=',TypeOfDishes.TypeOfDishId) as itemLink " +
                                     "FROM TypeOfDishes JOIN Recipe_TypeOfDishes ON Recipe_TypeOfDishes.TypeOfDishId = TypeOfDishes.TypeOfDishId " +
                                     "WHERE Recipe_TypeOfDishes.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                                     SqlFilterProduct +
                                     SqlFilterNationalCuisines +
                                     SqlFilterTypeOfDishes +
                                     ") GROUP BY TypeOfDishes.TypeOfDishId,TypeOfDishes.TypeOfDishName " +
                                     "ORDER BY mainsort, itemType, itemChecked DESC, itemCount DESC, itemName;"
            ;
            List <Filter> TopFilterProduct = db.Filters.FromSql(SqlTopFilter).ToList();

            List <Filter> Filters = db.Filters.FromSql(SqlFilter).ToList();

            List <Recipe_Filter> Recipe_Filters   = new List <Recipe_Filter>();
            List <Filter>        Products         = new List <Filter>();
            List <Filter>        NationalCuisines = new List <Filter>();
            List <Filter>        TypeOfDishes     = new List <Filter>();
            string asType     = "";
            int    itemsCount = 0;
            string itemClass  = "";

            foreach (Filter filter in Filters)
            {
                if (asType == "")
                {
                    asType = filter.itemType;
                }
                if (asType != filter.itemType)
                {
                    if (itemsCount <= this.maxCountView)
                    {
                        itemClass = "maxHeight-" + itemsCount;
                    }
                    Recipe_Filters.Add(new Recipe_Filter {
                        items = Products, itemType = asType, itemMD5 = this.MD5HashFilter(asType), itemsCount = itemsCount, itemClass = itemClass
                    });
                    asType     = filter.itemType;
                    Products   = new List <Filter>();
                    itemClass  = "";
                    itemsCount = 0;
                }
                itemsCount++;
                Products.Add(filter);
            }
            if (asType != "")
            {
                if (itemsCount <= this.maxCountView)
                {
                    itemClass = "maxHeight-" + itemsCount;
                }
                Recipe_Filters.Add(new Recipe_Filter {
                    items = Products, itemType = asType, itemMD5 = this.MD5HashFilter(asType), itemsCount = itemsCount, itemClass = itemClass
                });
                Products = new List <Filter>();
            }

            IEnumerable <Recipe> recipes = db.Recipes.ToList().OrderByDescending(r => r.CreatedDate);
            var count = recipes.Count();

            var pager = new PageInfo(recipes.Count(), page);

            FilterViewModel viewModel = new FilterViewModel
            {
                TopFilterProduct = TopFilterProduct,
                Recipe_Filters   = Recipe_Filters,
                Recipes          = recipes.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize),
                Products         = Products,
                TypeOfDishes     = TypeOfDishes,
                NationalCuisines = NationalCuisines,
                PageInfo         = pager
            };

            return(View(viewModel));
        }
예제 #14
0
        public IActionResult Filters(string flp, string flc, string fld, int?page)
        {
            string SqlFilterProduct          = "join Recipe_Products frp on frp.RecipeId = r.RecipeId ";
            string SqlFilterNationalCuisines = "join Recipe_NationalCuisines frn on frn.RecipeId = r.RecipeId ";
            string SqlFilterTypeOfDishes     = "join Recipe_TypeOfDishes frd on frd.RecipeId = r.RecipeId ";
            string SqlFilterRecept           = "";

            string[]      up  = { };
            string[]      uc  = { };
            string[]      ud  = { };
            List <string> sfl = new List <string>();
            string        pfl = "";
            bool          tpl = false;

            if (flp != null)
            {
                up = flp.Split(',');
                sfl.Add("flp=" + flp);
                tpl = true;
                for (int i = 0; i < up.Length; i++)
                {
                    string fs = "frp" + i;
                    SqlFilterRecept += "join Recipe_Products " + fs + " on " + fs + ".RecipeId = r.RecipeId and " + fs + ".ProductId = " + up[i] + " ";
                }
            }
            else
            {
                flp              = "0";
                SqlFilterRecept += SqlFilterProduct;
            }
            if (flc != null)
            {
                uc = flc.Split(',');
                sfl.Add("flc=" + flc);
                tpl = true;
                for (int i = 0; i < uc.Length; i++)
                {
                    string fs = "frc" + i;
                    SqlFilterRecept += "join Recipe_NationalCuisines " + fs + " on " + fs + ".RecipeId = r.RecipeId and " + fs + ".NationalCuisineId = " + uc[i] + " ";
                }
            }
            else
            {
                flc              = "0";
                SqlFilterRecept += SqlFilterNationalCuisines;
            }
            if (fld != null)
            {
                ud = fld.Split(',');
                sfl.Add("fld=" + fld);
                tpl = true;
                for (int i = 0; i < ud.Length; i++)
                {
                    string fs = "frd" + i;
                    SqlFilterRecept += "join Recipe_TypeOfDishes " + fs + " on " + fs + ".RecipeId = r.RecipeId and " + fs + ".TypeOfDishId = " + ud[i] + " ";
                }
            }
            else
            {
                fld              = "0";
                SqlFilterRecept += SqlFilterTypeOfDishes;
            }
            if (tpl)
            {
                pfl = "/filter?" + String.Join("&", sfl);
            }

            string SqlTopFilter = "SELECT Distinct TOP (10) " +
                                  "Products.ProductId as itemId, 'Top products' as itemType, Products.ProductName as itemName, " +
                                  "COUNT(Distinct Recipe_Products.RecipeId) AS itemCount, 0 as itemSort, " +
                                  "CASE WHEN Products.ProductId in (" + flp + ") THEN 'active' ELSE '' END as itemChecked, '1' as mainsort, " +
                                  "'' as itemLink " +
                                  "FROM Products JOIN Recipe_Products ON Recipe_Products.ProductId = Products.ProductId join ProductTypes pt on pt.ProductTypeId = Products.ProductTypeId " +
                                  "WHERE Recipe_Products.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                                  SqlFilterRecept +
                                  ") GROUP BY Products.ProductId,pt.ProductTypeName,Products.ProductName ORDER BY itemChecked DESC, itemCount DESC ";

            List <Filter> TopProduct       = db.Filters.FromSql(SqlTopFilter).ToList();
            List <Filter> TopFilterProduct = new List <Filter>();
            int           index;

            string[] u;
            bool     t;

            foreach (Filter filter in TopProduct)
            {
                t = false;
                List <string> s = new List <string>();
                filter.itemLink = "/";
                u     = up;
                index = Array.IndexOf(u, filter.itemId + "");
                if (index > -1)
                {
                    filter.itemChecked = "active";
                    Delete(ref u, index);
                    if (u.Length > 0)
                    {
                        t = true;
                        s.Add("flp=" + String.Join(",", u));
                    }
                }
                else
                {
                    t = true;
                    if (u.Length > 0)
                    {
                        s.Add("flp=" + String.Join(",", u) + "," + filter.itemId);
                    }
                    else
                    {
                        s.Add("flp=" + filter.itemId);
                    }
                };
                if (uc.Length > 0)
                {
                    t = true;
                    s.Add("flc=" + String.Join(",", uc));
                }
                if (ud.Length > 0)
                {
                    t = true;
                    s.Add("fld=" + String.Join(",", ud));
                }
                if (t)
                {
                    filter.itemLink = "/filter?" + String.Join("&", s);
                }
                TopFilterProduct.Add(filter);
            }
            string SqlFilter = "SELECT Distinct " +
                               "Products.ProductId as itemId, pt.ProductTypeName as itemType, Products.ProductName as itemName, " +
                               "COUNT(Distinct Recipe_Products.RecipeId) AS itemCount, 1 as itemSort, " +
                               "CASE WHEN Products.ProductId in (" + flp + ") THEN 'active' ELSE '' END as itemChecked, '4' as mainsort, " +
                               "'' as itemLink " +
                               "FROM Products JOIN Recipe_Products ON Recipe_Products.ProductId = Products.ProductId join ProductTypes pt on pt.ProductTypeId = Products.ProductTypeId " +
                               "WHERE Recipe_Products.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                               SqlFilterRecept +
                               ") GROUP BY Products.ProductId,pt.ProductTypeName,Products.ProductName " +
                               "UNION " +
                               "SELECT Distinct " +
                               "NationalCuisines.NationalCuisineId as itemId, 'National Cuisines' as itemType, NationalCuisines.NationalCuisineName as itemName, " +
                               "COUNT(Distinct Recipe_NationalCuisines.RecipeId) AS itemCount, 2 as itemSort, " +
                               "CASE WHEN NationalCuisines.NationalCuisineId in (" + flc + ") THEN 'active' ELSE '' END as itemChecked, '2' as mainsort, " +
                               "'' as itemLink " +
                               "FROM NationalCuisines JOIN Recipe_NationalCuisines ON Recipe_NationalCuisines.NationalCuisineId = NationalCuisines.NationalCuisineId " +
                               "WHERE Recipe_NationalCuisines.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                               SqlFilterRecept +
                               ") GROUP BY NationalCuisines.NationalCuisineId,NationalCuisines.NationalCuisineName " +
                               "UNION " +
                               "SELECT Distinct " +
                               "TypeOfDishes.TypeOfDishId as itemId, 'Type Of Dishes' as itemType, TypeOfDishes.TypeOfDishName as itemName, " +
                               "COUNT(Distinct Recipe_TypeOfDishes.RecipeId) AS itemCount, 3 as itemSort, " +
                               "CASE WHEN TypeOfDishes.TypeOfDishId in (" + fld + ") THEN 'active' ELSE '' END as itemChecked, '3' as mainsort, " +
                               "'' as itemLink " +
                               "FROM TypeOfDishes JOIN Recipe_TypeOfDishes ON Recipe_TypeOfDishes.TypeOfDishId = TypeOfDishes.TypeOfDishId " +
                               "WHERE Recipe_TypeOfDishes.RecipeId in (SELECT Distinct r.RecipeId FROM Recipes r " +
                               SqlFilterRecept +
                               ") GROUP BY TypeOfDishes.TypeOfDishId,TypeOfDishes.TypeOfDishName " +
                               "ORDER BY mainsort, itemSort, itemType, itemChecked DESC, itemCount DESC, itemName;"

            ;
            List <Filter>        Filters          = db.Filters.FromSql(SqlFilter).ToList();
            List <Recipe_Filter> Recipe_Filters   = new List <Recipe_Filter>();
            List <Filter>        Products         = new List <Filter>();
            List <Filter>        NationalCuisines = new List <Filter>();
            List <Filter>        TypeOfDishes     = new List <Filter>();

            index = -1;
            string asType     = "";
            int    itemsCount = 0;
            string itemClass  = "";

            foreach (Filter filter in Filters)
            {
                if (asType == "")
                {
                    asType = filter.itemType;
                }
                if (asType != filter.itemType)
                {
                    if (itemsCount <= this.maxCountView)
                    {
                        itemClass += " maxHeight-" + itemsCount;
                    }
                    Recipe_Filters.Add(new Recipe_Filter {
                        items = Products, itemType = asType, itemMD5 = this.MD5HashFilter(asType), itemsCount = itemsCount, itemClass = itemClass
                    });
                    asType     = filter.itemType;
                    Products   = new List <Filter>();
                    itemsCount = 0;
                    itemClass  = "";
                }
                itemsCount++;

                t = false;
                List <string> s = new List <string>();
                filter.itemLink = "/";
                switch (filter.itemType)
                {
                case "National Cuisines":
                    u     = uc;
                    index = Array.IndexOf(u, filter.itemId + "");
                    if (up.Length > 0)
                    {
                        t = true;
                        s.Add("flp=" + String.Join(",", up));
                    }
                    if (index > -1)
                    {
                        Delete(ref u, index);
                        filter.itemChecked = "active";
                        if (u.Length > 0)
                        {
                            t = true;
                            s.Add("flc=" + String.Join(",", u));
                        }
                    }
                    else
                    {
                        t = true;
                        if (u.Length > 0)
                        {
                            s.Add("flc=" + String.Join(",", u) + "," + filter.itemId);
                        }
                        else
                        {
                            s.Add("flc=" + filter.itemId);
                        }
                    };
                    if (ud.Length > 0)
                    {
                        t = true;
                        s.Add("fld=" + String.Join(",", ud));
                    }
                    if (t)
                    {
                        filter.itemLink = "/filter?" + String.Join("&", s);
                    }


                    Products.Add(filter);
                    break;

                case "Type Of Dishes":
                    u     = ud;
                    index = Array.IndexOf(u, filter.itemId + "");
                    if (up.Length > 0)
                    {
                        t = true;
                        s.Add("flp=" + String.Join(",", up));
                    }
                    if (uc.Length > 0)
                    {
                        t = true;
                        s.Add("flc=" + String.Join(",", uc));
                    }
                    if (index > -1)
                    {
                        Delete(ref u, index);
                        filter.itemChecked = "active";
                        if (u.Length > 0)
                        {
                            t = true;
                            s.Add("fld=" + String.Join(",", u));
                        }
                    }
                    else
                    {
                        t = true;
                        if (u.Length > 0)
                        {
                            s.Add("fld=" + String.Join(",", u) + "," + filter.itemId);
                        }
                        else
                        {
                            s.Add("fld=" + filter.itemId);
                        }
                    };
                    if (t)
                    {
                        filter.itemLink = "/filter?" + String.Join("&", s);
                    }

                    Products.Add(filter);
                    break;

                default:
                    u     = up;
                    index = Array.IndexOf(u, filter.itemId + "");
                    if (index > -1)
                    {
                        filter.itemChecked = "active";
                        Delete(ref u, index);

                        //Array.Clear(u, index, 1);
                        if (u.Length > 0)
                        {
                            t = true;
                            s.Add("flp=" + String.Join(",", u));
                        }
                    }
                    else
                    {
                        t = true;
                        if (u.Length > 0)
                        {
                            s.Add("flp=" + String.Join(",", u) + "," + filter.itemId);
                        }
                        else
                        {
                            s.Add("flp=" + filter.itemId);
                        }
                    };
                    if (uc.Length > 0)
                    {
                        t = true;
                        s.Add("flc=" + String.Join(",", uc));
                    }
                    if (ud.Length > 0)
                    {
                        t = true;
                        s.Add("fld=" + String.Join(",", ud));
                    }
                    if (t)
                    {
                        filter.itemLink = "/filter?" + String.Join("&", s);
                    }
                    Products.Add(filter);
                    break;
                }
                if (index > -1)
                {
                    itemClass = "in";
                }
            }
            if (asType != "")
            {
                if (itemsCount <= this.maxCountView)
                {
                    itemClass += " maxHeight-" + itemsCount;
                }
                Recipe_Filters.Add(new Recipe_Filter {
                    items = Products, itemType = asType, itemMD5 = this.MD5HashFilter(asType), itemsCount = itemsCount, itemClass = itemClass
                });
                Products = new List <Filter>();
            }
            string sqlRecept             = "SELECT Distinct r.* FROM Recipes r " + SqlFilterRecept;
            IEnumerable <Recipe> recipes = db.Recipes.FromSql(sqlRecept).ToList().OrderByDescending(r => r.CreatedDate);
            var count = recipes.Count();

            var pager = new PageInfo(recipes.Count(), page, pfl);

            FilterViewModel viewModel = new FilterViewModel
            {
                TopFilterProduct = TopFilterProduct,
                Recipe_Filters   = Recipe_Filters,
                Recipes          = recipes.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize),
                Products         = Products,
                TypeOfDishes     = TypeOfDishes,
                NationalCuisines = NationalCuisines,
                PageInfo         = pager
            };

            return(View("Index", viewModel));
        }
        private void AddMilks(Products products, int quantity)
        {
            var milk = new Milk(quantity);

            products.Add(milk);
        }
 public static void AddProduct(Product newProduct)
 {
     Products.Add(newProduct);
 }
        private void AddBread(Products products, int quantity)
        {
            Bread bread = new Bread(quantity);

            products.Add(bread);
        }
예제 #18
0
 public void AddProduct(Product product)
 {
     Products.Add(product);
 }
예제 #19
0
 public void AddProduct(string product)
 {
     Products.Add(product);
 }
예제 #20
0
        public async Task GetProductByBarCodeAsync(string BarCode)
        {
            stagedProductList = await ProductRepository.GetProductByBarCodeAsync(BarCode);

            stagedProductList.ForEach(p => Products.Add(p));
        }
예제 #21
0
 private async void Connect()
 {
     //add handlers which will be called from server-side
     _hubConnection.On <Product>("Add", p => Device.BeginInvokeOnMainThread(() => Products.Add(new ProductViewModel(p))));
     _hubConnection.On <int>("Delete", id => Device.BeginInvokeOnMainThread(() => Products.Remove(_products.FirstOrDefault(p => p.Id == id))));
     _hubConnection.On <int, int>("ChangeQuantity", (id, quantity) => Device.BeginInvokeOnMainThread(() => Products.FirstOrDefault(p => p.Id == id).Quantity = quantity));
     //start connection
     await _hubConnection.StartAsync();
 }
예제 #22
0
        public async Task GetProductByNameAsync(string name)
        {
            stagedProductList = await ProductRepository.GetProductByNameAsync(name);

            stagedProductList.ForEach(p => Products.Add(p));
        }
예제 #23
0
 public ProductExtra(Product product) : this()
 {
     Products.Add(product);
 }
예제 #24
0
        public ViewModel()
        {
            this.Products = new ObservableCollection <ChartModel>();
            Random rndm = new Random();

            Products.Add(new ChartModel()
            {
                ProductId = 1, ProductName = "Rice", Price2000 = rndm.Next(5, 40), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 2, ProductName = "Wheat", Price2000 = rndm.Next(5, 80), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 1, ProductName = "Oil", Price2000 = rndm.Next(5, 60), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 4, ProductName = "Corn", Price2000 = rndm.Next(5, 40), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 5, ProductName = "Gram", Price2000 = rndm.Next(5, 40), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 6, ProductName = "Milk", Price2000 = rndm.Next(5, 90), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 7, ProductName = "Butter", Price2000 = rndm.Next(5, 40), Price2010 = rndm.Next(10, 60)
            });
            Products.Add(new ChartModel()
            {
                ProductId = 8, ProductName = "Oil", Price2000 = rndm.Next(5, 60), Price2010 = rndm.Next(10, 60)
            });


            FileCommands   = new ObservableCollection <CommandModel>();
            WindowCommands = new ObservableCollection <CommandModel>();

            FileCommands.Add(new CommandModel()
            {
                Name = "New Product Details", Icon = "/Images/NewDocumentHS.png", Command = NewGridCommand
            });
            FileCommands.Add(new CommandModel()
            {
                Name = "New product Statistics", Icon = "/Images/graphhs.png", Command = NewChartCommand
            });
            FileCommands.Add(new CommandModel()
            {
                Name = "Open", Icon = "/Images/openfolderHS.png"
            });
            FileCommands.Add(new CommandModel()
            {
                Name = "Exit", Icon = "/Images/DeleteHS.png"
            });

            WindowCommands.Add(new CommandModel()
            {
                Name = "Cascade", Icon = "/Images/CascadeWindowsHS.png", Command = TileCascade, IsCheckable = true
            });
            WindowCommands.Add(new CommandModel()
            {
                Name = "Tile Horizontally", Icon = "/Images/ArrangeWindowsHS.png", Command = TileHorizontal, IsCheckable = true
            });
            WindowCommands.Add(new CommandModel()
            {
                Name = "Tile Vertically", Icon = "/Images/ArrangeSideBySideHS.png", Command = TileVertical, IsCheckable = true
            });

            WindowCommands[0].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
            WindowCommands[1].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
            WindowCommands[2].PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);

            ChartModel = new CommandModel()
            {
                Name = "Chart View"
            };
            ChartModel.Commands.Add(new CommandModel()
            {
                Name = "New Statistics", Icon = "/Images/graphhs.png", Command = NewCommand
            });
            ChartModel.Commands.Add(new CommandModel()
            {
                Name = "Refresh Chart", Icon = "/Images/RepeatHS.png", Command = NewCommand
            });
            ChartModel.Commands.Add(new CommandModel()
            {
                Name = "Publish Data", Icon = "/Images/PublishToWebHS.png", Command = NewCommand
            });
            ChartModel.Commands.Add(new CommandModel()
            {
                Name = "Close View", Icon = "/Images/DeleteHS.png", Command = NewCommand
            });

            Chart1Model = new CommandModel()
            {
                Name = "Customize Chart"
            };
            Chart1Model.Commands.Add(new CommandModel()
            {
                Name = "Change Chart Type", Icon = "/Images/PieChartHS.png", Command = NewCommand
            });
            Chart1Model.Commands.Add(new CommandModel()
            {
                Name = "Add Series", Icon = "/Images/AlignObjectsBottomHS.png", Command = NewCommand
            });

            this.PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);

            GridModel = new CommandModel()
            {
                Name = "Grid View"
            };
            GridModel.Commands.Add(new CommandModel()
            {
                Name = "New Payroll", Icon = "/Images/NewReportHS.png", Command = NewCommand
            });
            GridModel.Commands.Add(new CommandModel()
            {
                Name = "Refresh Grid", Icon = "/Images/RepeatHS.png", Command = NewCommand
            });
            GridModel.Commands.Add(new CommandModel()
            {
                Name = "Close View", Icon = "/Images/DeleteHS.png", Command = NewCommand
            });

            OtherCommands        = new ObservableCollection <CommandModel>();
            OtherToolbarCommands = new ObservableCollection <CommandModel>();
        }
예제 #25
0
 public Task InsertAsync(string id, ProductDto product)
 {
     Products.Add(product);
     return(Task.CompletedTask);
 }
예제 #26
0
 public ActionResult AddProduct(ProductViewModel model)
 {
     Products.Add(model);
     return(Json(Products));
 }
예제 #27
0
 public List <ProductDTO> addProducts(List <ProductDTO> products)
 {
     products.ForEach(product => Products.Add(product));
     return(products);
 }
예제 #28
0
    private void Insert()
    {
        Data objdata = new Data(Global.ConnectionSql);

        try
        {
            Products obj = new Products();
            obj.DataObject  = objdata;
            obj.Title       = txtTitle.Text.Trim();
            obj.ProductCode = txtProductCode.Text.Trim().ToUpper();
            obj.Description = txtDescription.Text.Trim();
            obj.Detail      = radContents.Content;
            obj.IsActived   = true;
            obj.IsMostSale  = cbkMostSale.Checked;
            obj.Links       = Global.FilterFileName(txtTitle.Text.Trim()).Replace(" ", "-");
            obj.CategoryID  = Convert.ToInt32(ddlCategory.SelectedValue);
            if (this.uplImage.HasFile)
            {
                Neodynamic.WebControls.ImageDraw.ImageElement uploadedImage;
                uploadedImage = Neodynamic.WebControls.ImageDraw.ImageElement.FromBinary(this.uplImage.FileBytes);
                Neodynamic.WebControls.ImageDraw.Resize actResize = new Neodynamic.WebControls.ImageDraw.Resize();
                actResize.Width  = 150;
                actResize.Height = 150;
                uploadedImage.Actions.Add(actResize);
                Neodynamic.WebControls.ImageDraw.ImageDraw imgDraw = new Neodynamic.WebControls.ImageDraw.ImageDraw();
                imgDraw.Elements.Add(uploadedImage);
                imgDraw.ImageFormat          = Neodynamic.WebControls.ImageDraw.ImageDrawFormat.Jpeg;
                imgDraw.JpegCompressionLevel = 90;
                string filename = GetDate + "_" + uplImage.FileName;
                imgDraw.Save(Server.MapPath(Global.GetConfigKey("uploadproduct") + filename));
                obj.Image = Global.GetConfigKey("uploadproduct") + filename;
            }
            else
            {
                obj.Image = Global.GetConfigKey("uploadproduct") + "alternate.png";
            }
            obj.Date = DateTime.Now;
            int result = Convert.ToInt32(obj.Add());
            if (result > 0)// no error
            {
                Response.Write("<script>window.location='product.aspx'</script>");
            }
            else if (result == 0)
            {
                lblMessage.Text = "Trùng dữ liệu vui lòng kiểm tra lại";
                return;
            }
            else
            {
                lblMessage.Text = "Lỗi xảy ra trong quá trình lưu dữ liệu. Liên hệ với người quản trị để khắc phục";
                return;
            }
        }
        catch (Exception ex)
        {
            Global.WriteLogError("Insert() " + ex);
        }
        finally
        {
            objdata.DeConnect();
        }
    }
예제 #29
0
        public void addProduct(Product product)
        {
            bool           exists   = false;
            Product        mProduct = null;
            List <Product> Products = new List <Product>();

            {
                Products = Deserialize(ProductFilePath) as List <Product>;
                if (Products != null)
                {
                    if (product.Id != 0 && (product.Id % 1000) > 0)
                    {
                        try
                        {
                            mProduct = Products.ElementAt(product.Id % 1000);
                        }
                        catch (IndexOutOfRangeException e)
                        {
                        }
                        catch (NullReferenceException e)
                        {
                        }
                    }
                    else
                    {
                        foreach (Product p in Products)
                        {
                            if (product.Name == p.Name)
                            {
                                mProduct = p;
                            }
                        }
                    }
                }
                else
                {
                    Products = new List <Product>();
                }


                if (mProduct != null)
                {
                    exists = true;
                    Products.Remove(mProduct);
                    mProduct.Amount = product.Amount;
                    if (product.Quantity > mProduct.Quantity)
                    {
                        mProduct.Quantity = product.Quantity;
                    }
                    Products.Add(mProduct);
                }
            }


            if (!exists)
            {
                ProductId  = ProductId + Products.Count() + 1;
                product.Id = ProductId;
                Products.Add(product);
            }

            Stream write = File.Open(ProductFilePath, FileMode.Create);

            Serializer.Serialize(write, Products);
            write.Close();
        }
 public ApiTransactionOffer Add(ApiTransactionProduct product)
 {
     Products ??= new List <ApiTransactionProduct>();
     Products.Add(product);
     return(this);
 }
예제 #31
0
        //Constructor
        public HomeViewModel(ContentPage CurrentPage)
        {
            //Declare Variables
            Events                  = new ObservableCollection <Event>();
            Categories              = new ObservableCollection <Category>();
            ProductSections         = new ObservableCollection <ProductSection>();
            IsLoadingProductSection = false;
            IsLoadingPage           = true;
            IsReady                 = false;

            //Dữ liệu được tạo ảo 2 dòng để cho thấy cấu trúc mô phỏng thực tế của app. Vì dữ liệu trên Database không đầy đủ hoặc hình ảnh chưa thêm.
            //Tuy nhiên quá trình tải dữ liệu các danh mục sau đó là hoàn toàn từ server.
            ProductSections.Add(new ProductSection
            {
                category = new Category
                {
                    Full_name = "Category01"
                },
                products = new ObservableCollection <Product>
                {
                    new Product {
                        Id = 10, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    },
                    new Product {
                        Id = 2, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    },
                    new Product {
                        Id = 3, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    }
                }
            });
            ProductSections.Add(new ProductSection
            {
                category = new Category
                {
                    Full_name = "Category02"
                },
                products = new ObservableCollection <Product>
                {
                    new Product {
                        Id = 3, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    },
                    new Product {
                        Id = 4, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    },
                    new Product {
                        Id = 5, Url_images = "jacket.png", Full_name = "Product", Cost = 100
                    }
                }
            });


            LoadMoreCategoryCommand = new Command <ObservableCollection <Category> >(async(Categories) =>
            {
                //Get more categories from SERVER
                ObservableCollection <Category> tempCategories = new ObservableCollection <Category>();
                tempCategories = await App.CategoryManager.RefreshCategoryAsync();
                if (tempCategories.Count <= 0)
                {
                    Console.WriteLine("ERROR: LoadMoreCategoriesCommand with no data. Server responsed no anything");
                }
                else
                {
                    //Add events into Events List.
                    //Notes : Wrong assign Events = events;
                    for (int i = 0; i < tempCategories.Count; i++)
                    {
                        Categories.Add(tempCategories[i]);
                    }
                    Console.WriteLine("LoadMoreCategoriesCommand excuted");
                }
            });

            LoadMoreProductCommand = new Command <ObservableCollection <Product> >(Products =>
            {
                if (Products.Count <= 0)
                {
                    Console.WriteLine("ERROR: LoadMoreProductCommand with no data. Server responsed no anything");
                }
                else
                {
                    var categoryid = Products[0].Root_id;
                    Products.Add(new Product {
                        Root_id = categoryid, Url_images = "jacket.png", Full_name = "New ID" + categoryid.ToString(), Cost = 1500
                    });
                }
            });

            LoadMoreEventCommand = new Command <ObservableCollection <Event> >(async(Events) =>
            {
                //Get more events from SERVER
                ObservableCollection <Event> tempEvents = new ObservableCollection <Event>();
                tempEvents = await App.EventManager.RefreshEventAsync();

                //Add events into Events List.
                //Notes : Wrong assign Events = events;
                for (int i = 0; i < tempEvents.Count; i++)
                {
                    Events.Add(tempEvents[i]);
                }
                Console.WriteLine("LoadMoreEventCommand excuted");
            });

            AutoSliderCommand = new Command <int>(Position =>
            {
                Device.StartTimer(TimeSpan.FromSeconds(5), (Func <bool>)(() =>
                {
                    Position = (Position + 1) % Events.Count;
                    return(true);
                }));
            });

            ProductClickedCommand = new Command <int>(async(ProductId) =>
            {
                Console.WriteLine("Product Clicked Command's running");
                await App.Current.MainPage.Navigation.PushAsync(new DetailProduct(ProductId));
            });
            CartClickedCommand = new Command(async() =>
            {
                Console.WriteLine("Cart Clicked Command's running");
                await App.Current.MainPage.Navigation.PushModalAsync(new Cart());
            });

            LoadMoreProductSection = new Command <ObservableCollection <ProductSection> >(async(ProductSections) =>
            {
                //Set Activity Indicator
                IsLoadingProductSection = true;
                //Get more categories from SERVER
                Console.WriteLine("=>>>>LoadMoreProductSectionCommand is running");
                ObservableCollection <ProductSection> temp = new ObservableCollection <ProductSection>();
                temp = await App.ProductSectionManager.RefreshProductSectionAsync();
                if (temp.Count <= 0)
                {
                    Console.WriteLine("ERROR: LoadMoreProductSection with no data. Server responsed no anything");
                }
                else
                {
                    //for (int i = 0; i < temp.Count; i++)
                    //{
                    //    ProductSections.Add(temp[i]);
                    //}
                    //Notes: Thực tế sẽ phải load những danh mục & sản phẩm , tuy nhiên dữ liệu giả lập chưa có nên sẽ load lặp lại , và hiện vẫn cài đặt nhớ phần dữ liệu đã load.
                    //Để test load dữ liệu chỉ load 1 danh mục kèm sản phẩm ngẫu nhiên từ server.
                    int rInt;
                    do
                    {
                        Random r = new Random();
                        rInt     = r.Next(0, temp.Count); //for ints
                    } while (temp[rInt].products.Count <= 0);
                    ProductSections.Add(temp[rInt]);
                    Console.WriteLine("LoadMoreProductSection successfully run");
                }
                //Set Activity Indicator
                IsLoadingProductSection = false;
            });
            //Set Activity Indicator
            IsLoadingPage = false;
            IsReady       = true;;
        }