protected PrepackBaseViewModel(T entity) : base(entity) { InitializeCollections(); // Заполнение ингредиентов из сущности. foreach (var ingredient in entity.Ingredients) { Ingredients.Add(new IngredientViewModel(ingredient)); } // Подписка на события коллекции. Ingredients.CollectionChanged += IngredientsOnCollectionDeleted; Ingredients.CollectionChanged += IngredientsOnCollectionAdded; Products.AddRange(Repository.Get <ProductBase>().ToList() .Where(x => !(x is DishBase)) .Where(x => x.Id != entity.Id) .OrderBy(x => x.Name)); AddIngredient = new SimpleCommand(() => { Ingredients.Add(new IngredientViewModel(new Ingredient())); }); RemoveIngredient = new SimpleCommand(() => { if (SelectedIngredient == null) { return; } Ingredients.Remove(SelectedIngredient); }); }
public async Task LoadMore() { var result = await productCatalogService.ListProducts(ContinuationToken); Products.AddRange(result.Items); ContinuationToken = result.ContinuationToken; }
private void AddProducts() { Product1 = new Product { ID = 1, Name = "A", Price = 20, Promo = new Promotions { Id = 1, Name = "Buy 1 Get 1 Free", TypePromotion = 2, PricePromotion = 0 } }; Product2 = new Product { ID = 2, Name = "B", Price = 4, Promo = new Promotions { Id = 2, Name = "3 for 10 Euro", TypePromotion = 3, PricePromotion = 10 } }; Product3 = new Product { ID = 3, Name = "C", Price = 2 }; Products.AddRange(new List <Product> { Product1, Product2, Product3 }); }
public static void LoadFromDisk(string folder) { Products.Clear(); Products.AddRange(Directory.GetFiles(folder, "*.txt") .Select(ReadProduct) .ToList()); }
public MainViewModel() { try { productCommands = new ProductCommands(_connectionString); Products.AddRange(productCommands.GetList()); ProdCategoryCommands prodCategoryCommands = new ProdCategoryCommands(_connectionString); ProdCategories.AddRange(prodCategoryCommands.GetList()); LocationCommands locationCommands = new LocationCommands(_connectionString); Locations.AddRange(locationCommands.GetList()); LocCategoryCommands locCategoryCommands = new LocCategoryCommands(_connectionString); LocationCategories.AddRange(locCategoryCommands.GetList()); UnitCommands unitCommands = new UnitCommands(_connectionString); Units.AddRange(unitCommands.GetList()); UpdateAppStatus($"Database tables fetched.", Brushes.DarkGreen); } catch (Exception ex) { UpdateAppStatus($"Error on retrieving tables from SQL database:\n{ex.Message}", Brushes.Red); } GenerateTableProductsToDisplay(); InitializeAllPropertyFields(); Scheduler(); }
public void Merge(Sector metadataSource) { if (metadataSource == null) { throw new ArgumentNullException("metadataSource"); } // TODO: This is very fragile; if a new type is added to Sector we need to add more code here. if (metadataSource.Names.Any()) { Names.Clear(); Names.AddRange(metadataSource.Names); } if (metadataSource.DataFile != null && DataFile != null && (metadataSource.DataFile.FileName != DataFile.FileName || metadataSource.DataFile.Type != DataFile.Type)) { throw new Exception(string.Format("Mismatching DataFile entries for {0}", this.Names[0].Text)); } if (metadataSource.DataFile != null) { DataFile = metadataSource.DataFile; } Subsectors.AddRange(metadataSource.Subsectors); Allegiances.AddRange(metadataSource.Allegiances); Borders.AddRange(metadataSource.Borders); Routes.AddRange(metadataSource.Routes); Labels.AddRange(metadataSource.Labels); Credits = metadataSource.Credits; Products.AddRange(metadataSource.Products); StylesheetText = metadataSource.StylesheetText; }
private async Task AddToResultsAsync(IEnumerable <Product> newProducts) { var goodProducts = new List <ProductVM>(); lock (Products) { foreach (var newProduct in newProducts) { _cts.Token.ThrowIfCancellationRequested(); bool isProductExist = Products.Any(x => x.Model.Id == newProduct.Id); if (!isProductExist) { goodProducts.Add(new ProductVM(newProduct)); } } } await AsyncHelper.ExecuteAtUI(() => { lock (Products) { Products.AddRange(goodProducts); } }).ConfigureAwait(false); }
public void Seed(Model model) { if (model.Categories != null) { Categories.AddRange(model.Categories); } if (model.Products != null) { Products.AddRange(model.Products); } if (model.Regions != null) { Regions.AddRange(model.Regions); } if (model.Shops != null) { Shops.AddRange(model.Shops); } if (model.Customers != null) { Customers.AddRange(model.Customers); } if (model.Campaigns != null) { Campaigns.AddRange(model.Campaigns); } if (model.Sales != null) { Sales.AddRange(model.Sales); } if (model.LeadStates != null) { LeadStates.AddRange(model.LeadStates); } if (model.LeadHistory != null) { LeadHistory.AddRange(model.LeadHistory); } if (model.Budget != null) { Budget.AddRange(model.Budget); } if (model.RegionWiseSales != null) { RegionWiseSales.AddRange(model.RegionWiseSales); } if (model.Opportunities != null) { Opportunities.AddRange(model.Opportunities); } if (model.ProfitAndSales != null) { ProfitAndSales.AddRange(model.ProfitAndSales); } if (model.RegionSales != null) { RegionSales.AddRange(model.RegionSales); } SaveChanges(); }
static Store() { Products.AddRange( new List <Product> { new Product() { ProductID = 1, Name = "First", Description = "My first product", Price = 1000.00m, Category = "Numbers" }, new Product() { ProductID = 2, Name = "Second", Description = "My second product", Price = 15000.00m, Category = "Numbers" }, new Product() { ProductID = 3, Name = "Bread", Description = "Smth for eat", Price = 1000.00m, Category = "food" } }); }
public IActionResult AddNewProductList([FromBody] IEnumerable <Product> productList) { if (productList?.Any() != null) { Products.AddRange(productList); } return(NoContent()); }
public void Load() { var products = ProductService.GetProducts(); var discounts = DiscountService.GetDiscounts(); var discountProducts = DiscountService.GetDiscountProductsByCustomerId(Customer.Id); Products.AddRange(products.Select(o => new SaleItemViewModel { Product = o, Discount = discountProducts.Where(p => p.ProductId == o.Id).Select(p => p.Discount).DefaultIfEmpty(0.0m).Max() })); }
public void Load() { var products = ProductService.GetProducts(); Products.AddRange(products.Select(o => new SaleItemViewModel(o) { BasePrice = o.Cost, ImageSource = ImageService.GetImage(o.Code) })); }
public Products GetProductsByCategoryID(int catId) { if (!AuthorizeService.CheckAdminCookies()) { return(null); } var products = new Products(); products.AddRange(CategoryService.GetProductsByCategoryId(catId)); return(products); }
private void LoadData() { List <Product> products = new List <Product> { new Product { Id = new Guid("f647f6be-15b1-4927-8e1c-bddb8663cb13"), Name = "Iphone11", Price = 7000M }, new Product { Id = new Guid("203a7848-2fbb-4010-8ca3-edc7001d2843"), Name = "IphoneX", Price = 6000M }, new Product { Id = new Guid("9ef19716-a95d-4422-8986-bc4f7f8ee594"), Name = "Iphone11 ProMax", Price = 9000M } }; List <Stock> stocks = new List <Stock> { new Stock { Id = Guid.NewGuid(), ProductId = new Guid("9ef19716-a95d-4422-8986-bc4f7f8ee594"), Piece = 1, MaxPiece = 1, }, new Stock { Id = Guid.NewGuid(), ProductId = new Guid("203a7848-2fbb-4010-8ca3-edc7001d2843"), Piece = 4, MaxPiece = 3, }, new Stock { Id = Guid.NewGuid(), ProductId = new Guid("f647f6be-15b1-4927-8e1c-bddb8663cb13"), Piece = 5, MaxPiece = 6, } }; Products.AddRange(products); Stocks.AddRange(stocks); SaveChangesAsync(); }
private async Task LoadData() { IsBusy = true; var products = await App.NetworkManager.GetProductsAsync(); if (products.Any()) { IsBusy = false; Products.Clear(); Products.AddRange(products); } }
public Products GetProducts() { if (!AuthorizeService.CheckAdminCookies()) { return(null); } var products = new Products(); products.AddRange(ProductService.GetProducts()); return(products); }
private void ReadTableFromDatabaseAfterModification(string successMessage, string failureMessage) { try { ProductsAllTablesMerged.Clear(); Products.Clear(); Products.AddRange(productCommands.GetList()); GenerateTableProductsToDisplay(); UpdateAppStatus(successMessage, Brushes.DarkGreen); } catch (Exception ex) { UpdateAppStatus(failureMessage + ex.Message, Brushes.Red); } }
/// <summary> /// Добавляет поставку в список поставок /// </summary> /// <param name="supply"></param> public void AddSupply(Supply supply) { if (supply is null) { throw new ArgumentNullException(nameof(supply), "Поставка не может быть null."); } Products.AddRange(supply.Products); if (GetDuplicateSupplier(supply.Supplier) == null) { Suppliers.Add(supply.Supplier); } Supplies.Add(supply); }
public async Task GetAllProducts() { List <string> categories = await categoryService.GetCategories(); var products = await ProductsService.GetProductsAsync(); Products.Clear(); var categorizedProducts = new List <CategorizedProducts>(); GetOfferProducts(products).ToList().ForEach(p => OfferProducts.Add(p)); categories.ForEach(cat => categorizedProducts.Add(new CategorizedProducts(GetCategorizedProducts(cat, products), cat))); Products.AddRange(categorizedProducts); ObservableRangeCollection <Product> offerProducts = new ObservableRangeCollection <Product>(products.Where(p => p.Offer != null)); Products.Insert(0, new CategorizedProducts(offerProducts, "Tilbud")); }
private void Initialize() { if (Products.Count() == 0) { Products.AddRange(new List <Product> { new Product { Nom = "T-shirt pour les femmes", Imagem = "imagem1.png", Pr = 109.90, }, new Product { Nom = "T-shirt pour les femmes", Imagem = "imagem2.png", Pr = 109.90, }, new Product { Nom = "short pour les femmes", Imagem = "imagem3.png", Pr = 139.90, }, new Product { Nom = "truc pour les femmes", Imagem = "imagem4.png", Pr = 269.90, }, new Product { Nom = "truc pour les femmes", Imagem = "imagem5.png", Pr = 199.90, }, }); SaveChanges(); } }
private Products GetProducts() { Products result = new Products(); try { _httpClient = new HttpClient(); string url = String.Format("{0}?ProductName={1}&Version={2}", this.Config.UpdateUrl, this.ProductName, this.ProductVersion); byte[] data = _httpClient.Get(url); using (MemoryStream memoryStream = new MemoryStream(data)) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateResult)); UpdateResult updateResult = (UpdateResult)serializer.Deserialize(memoryStream); //has error ? if (!String.IsNullOrEmpty(updateResult.Error)) { throw new Exception(updateResult.Error); } //find new version .. result.AddRange(updateResult.Products.FindAll(obj => obj.ProductName.Equals(this.ProductName) && (new Version(obj.ProductVersion) > ProductVersion))); } } catch (Exception exception) { OnError(new UpdateErrorArgs(exception)); } //has a new version .. if (result.Count > 0) { //tigger callback method . OnNewVersion(new NewVersionEventArgs(result)); } else { OnError(new UpdateErrorArgs("hav't a new version .", -1)); } return(result); }
/// <summary> /// Обновление списков сущностей. /// </summary> private void UpdateLists() { Dishes.Clear(); Prepacks.Clear(); Products.Clear(); Shared.NHibernate.Environment.Session.Clear(); var dishes = Repository.Get <Dish>(); foreach (var dish in dishes) { dish.Update(); dish.EntitySaved += OnEntityChanged; dish.EntityDeleted += OnEntityChanged; } var prepacks = Repository.Get <Prepack>(); foreach (var prepack in prepacks) { prepack.Update(); prepack.EntitySaved += OnEntityChanged; prepack.EntityDeleted += OnEntityChanged; } var products = Repository.Get <Product>(); foreach (var product in products) { product.Update(); product.EntitySaved += OnEntityChanged; product.EntityDeleted += OnEntityChanged; } Dishes.AddRange(dishes.Select(x => new DishViewModel(x))); Prepacks.AddRange(prepacks.Select(x => new PrepackViewModel(x))); Products.AddRange(products.Select(x => new ProductViewModel(x))); }
private static void LoadFromCsv() { Companies = new List <Company> { Company.Create(Constants.CompanyAId, Constants.CompanyAName), Company.Create(Constants.CompanyBId, Constants.CompanyBName) }; Products = File.ReadLines("..\\..\\..\\..\\input\\catalogA.csv").Skip(1).Select(line => Product.Create(line.Split(',')[0], line.Split(',')[1], Constants.CompanyAId)).ToList(); Products.AddRange(File.ReadLines("..\\..\\..\\..\\input\\catalogB.csv").Skip(1).Select(line => Product.Create(line.Split(',')[0], line.Split(',')[1], Constants.CompanyBId)).ToList()); Suppliers = File.ReadLines("..\\..\\..\\..\\input\\suppliersA.csv").Skip(1).Select(line => Supplier.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], Constants.CompanyAId)).ToList(); Suppliers.AddRange(File.ReadLines("..\\..\\..\\..\\input\\suppliersB.csv").Skip(1).Select(line => Supplier.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], Constants.CompanyBId)).ToList()); SupplierProductBarcodes = File.ReadLines("..\\..\\..\\..\\input\\barcodesA.csv").Skip(1).Select(line => SupplierProductBarcode.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], line.Split(',')[2], Constants.CompanyAId)).ToList(); SupplierProductBarcodes.AddRange(File.ReadLines("..\\..\\..\\..\\input\\barcodesB.csv").Skip(1).Select(line => SupplierProductBarcode.Create(int.Parse(line.Split(',')[0]), line.Split(',')[1], line.Split(',')[2], Constants.CompanyBId)).ToList()); }
protected void Load(bool refresh) { if (!refresh && Products.Count > 0) { IsLoading = false; return; } IsLoading = true; Task.Factory.StartNew(() => { Products.Clear(); //System.Threading.Thread.Sleep(2000); Products.AddRange(ProductService.GetProducts()); }).ContinueWith(t => { Execute.OnUIThread(() => { IsLoading = false; }); }); }
public FluentFilterTestDataBaseFromDb() { var options = new DbContextOptionsBuilder <MyTestDb>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var db = new MyTestDb(options); MyOrders = db.Orders; OrderDetails = db.OrderDetails; Products = db.Products; // 初始化数据 MyOrders.AddRange(TempnoaryList); var details = TempnoaryList.SelectMany(p => p.Details).Distinct(); OrderDetails.AddRange(details); var products = details.Select(p => p.ProductInfo).Distinct(new ProductEqualityComparer()); Products.AddRange(products); db.SaveChanges(); }
//public static readonly LoggerFactory MyLoggerFactory // = new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) }); //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) // => optionsBuilder.UseLoggerFactory(MyLoggerFactory); public async Task ClearAndFillWithDemoData() { await OrderDetails.ForEachAsync(od => OrderDetails.Remove(od)); await Orders.ForEachAsync(o => Orders.Remove(o)); await Customers.ForEachAsync(c => Customers.Remove(c)); await Products.ForEachAsync(p => Products.Remove(p)); var demoCustomers = new[] { new Customer() { CompanyName = "Corina Air Conditioning", CountryIsoCode = "AT" }, new Customer() { CompanyName = "Fernando Engineering", CountryIsoCode = "AT" }, new Customer() { CompanyName = "Murakami Plumbing", CountryIsoCode = "CH" }, new Customer() { CompanyName = "Naval Metal Construction", CountryIsoCode = "DE" } }; Customers.AddRange(demoCustomers); var demoProducts = new[] { new Product() { Description = "Mountain Bike", IsAvailable = true, CategoryCode = "BIKE", PricePerUom = 2500 }, new Product() { Description = "Road Bike", IsAvailable = true, CategoryCode = "BIKE", PricePerUom = 2000 }, new Product() { Description = "Skate Board", IsAvailable = true, CategoryCode = "BOARD", PricePerUom = 100 }, new Product() { Description = "Long Board", IsAvailable = true, CategoryCode = "BOARD", PricePerUom = 250 }, new Product() { Description = "Scooter", IsAvailable = false, CategoryCode = "OTHERS", PricePerUom = 150 } }; Products.AddRange(demoProducts); var rand = new Random(); for (var i = 0; i < 100; i++) { var order = new OrderHeader() { OrderDate = new DateTimeOffset(new DateTime(2014, rand.Next(1, 12), rand.Next(1, 28))), Customer = demoCustomers[rand.Next(demoCustomers.Length - 1)] }; Orders.Add(order); for (var j = 0; j < 3; j++) { OrderDetails.Add(new OrderDetail() { Order = order, Product = demoProducts[rand.Next(demoProducts.Length - 1)], Amount = rand.Next(1, 5) }); } } await SaveChangesAsync(); }
public void Update() { Products.Clear(); Products.AddRange(GetProducts(MainViewModel.Context)); }
private Products GetProducts() { Products result = new Products(); try { _httpClient = new HttpClient(); string url = String.Format("{0}?ProductName={1}&Version={2}", this.Config.UpdateUrl, this.ProductName, this.ProductVersion); byte[] data = _httpClient.Get(url); using (MemoryStream memoryStream = new MemoryStream(data)) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateResult)); UpdateResult updateResult = (UpdateResult)serializer.Deserialize(memoryStream); //has error ? if (!String.IsNullOrEmpty(updateResult.Error)) { throw new Exception(updateResult.Error); } //find new version .. result.AddRange(updateResult.Products.FindAll(obj => obj.ProductName.Equals(this.ProductName) && (new Version(obj.ProductVersion) > ProductVersion))); } } catch (Exception exception) { OnError(new UpdateErrorArgs(exception)); } //has a new version .. if (result.Count > 0) { //tigger callback method . OnNewVersion(new NewVersionEventArgs(result)); } else { OnError(new UpdateErrorArgs("hav't a new version .",-1)); } return result; }
public ProcessOrder SetProducts(IEnumerable <ProcessOrderProduct> products) { Products.Clear(); Products.AddRange(products); return(this); }
async Task GetData() { try { ActiveIn.IsVisible = true; if (CrossConnectivity.Current.IsConnected) { var nsAPI = RestService.For <IApiService>("https://ittezanmobilepos.com/"); RootObject data = await nsAPI.GetSettings(); var eachCategories = new ObservableCollection <Category>(data.message.categories); Categories = eachCategories; foreach (var item in eachCategories) { foreach (var item2 in item.category.list_of_products) { item2.product_id = item2.id; } Products.AddRange(item.category.list_of_products); } if (Device.RuntimePlatform == Device.iOS) { var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyDb.db"); var db = new SQLiteConnection(dbpath); var info = db.GetTableInfo("Product"); if (!info.Any()) { db.CreateTable <Product>(); } else { db.CreateTable <Product>(); } db.DeleteAll <Product>(); db.InsertAll(Products); } else { var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyDb.db"); var db = new SQLiteConnection(dbpath); var info = db.GetTableInfo("Product"); db.DeleteAll <Product>(); db.CreateTable <Product>(); db.CreateTable <Category>(); foreach (var item in Products) { db.InsertOrReplace(item); } db.InsertAll(Categories); } ProductsList.FlowItemsSource = products; ActiveIn.IsVisible = false; } else { ActiveIn.IsVisible = false; if (Device.RuntimePlatform == Device.iOS) { var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyDb.db"); var db = new SQLiteConnection(dbpath); var info = db.GetTableInfo("Product"); if (!info.Any()) { db.CreateTable <Product>(); } db.CreateTable <Category>(); Products = (db.Table <Product>().ToList()); Categories = new ObservableCollection <Category>(db.Table <Category>().ToList()); } else { var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyDb.db"); var db = new SQLiteConnection(dbpath); var info = db.GetTableInfo("Product"); var info2 = db.GetTableInfo("Category"); Products = (db.Table <Product>().ToList()); Categories = new ObservableCollection <Category>(db.Table <Category>().ToList()); } ProductsList.FlowItemsSource = Products; } } catch (ValidationApiException validationException) { // handle validation here by using validationException.Content, // which is type of ProblemDetails according to RFC 7807 ActiveIn.IsVisible = false; await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok); } catch (ApiException exception) { ActiveIn.IsVisible = false; await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok); // other exception handling } catch (Exception ex) { ActiveIn.IsVisible = false; await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok); } }
/// <summary> /// Adds multiple products. /// </summary> /// <param name="products"></param> public void AddProducts(IEnumerable <ISellableProduct> products) { Products.AddRange(products); }