public LocationsViewModel() { locationApi = new LocationAPI(); var location = locationApi.GetAll().Select(x => new Model.Location { Id = x.Id, Name = x.Name, Detail = new Command((() => { Detail(x.Id); })) }); Locations = new ObservableCollection <Model.Location>(location); }
public RecipeCreateViewModel() { productApi = new ProductsAPI(); var products = productApi.GetAll().Select(x => new ProductRecipe() { ProductId = x.Id, ProductName = x.Name, Value = 0, AddCommand = new Command((() => { AddProduct(x.Id); })), RemoveCommand = new Command((() => { RemoveProduct(x.Id); })) }); Products = new ObservableCollection <ProductRecipe>(products); ProductsRecipe = new ObservableCollection <ProductRecipe>(); locationApi = new LocationAPI(); var locations = locationApi.GetAll().Select(x => new Model.Location() { Id = x.Id, Name = x.Name, AddCommand = new Command(() => { AddLocation(x.Id); }), RemoveCommand = new Command((() => { RemoveLocation(x.Id); })) }); Locations = new ObservableCollection <Model.Location>(locations); LocationsRecipe = new ObservableCollection <Model.Location>(); SaveCommand = new Command((() => { this.Save(); })); }
public RecipeEditViewModel(int recipeId) { this.recipeId = recipeId; recipeApi = new RecipeAPI(); var recipeProduct = recipeApi.Get(this.recipeId); this.name = recipeProduct.Name; this.description = recipeProduct.Description; SaveCommand = new Command(Save); #region Продукты var productsRecipe = recipeProduct.Products.Select(x => new Model.ProductRecipe() { ProductId = x.ProductId, ProductName = x.ProductName, Value = x.Value, AddCommand = new Command((() => AddProduct(x.ProductId))), RemoveCommand = new Command((() => RemoveProduct(x.ProductId))) }); ProductsRecipe = new ObservableCollection <ProductRecipe>(productsRecipe); var productsApi = new ProductsAPI(); var products = productsApi.GetAll().Select(x => new ProductRecipe() { ProductId = x.Id, ProductName = x.Name, Value = 0, AddCommand = new Command((() => AddProduct(x.Id))), RemoveCommand = new Command((() => RemoveProduct(x.Id))) }); Products = new ObservableCollection <ProductRecipe>(); foreach (var product in products) { if (ProductsRecipe.All(p => p.ProductId != product.ProductId)) { Products.Add(product); } } #endregion #region Локации var recipeLocations = recipeApi.GetLocations(this.recipeId); var locationsRecipe = recipeLocations.Locations.Select(x => new Model.Location() { Id = x.Id, Name = x.Name, AddCommand = new Command((() => AddLocation(x.Id))), RemoveCommand = new Command((() => RemoveLocation(x.Id))) }); LocationsRecipe = new ObservableCollection <Model.Location>(locationsRecipe); var locationApi = new LocationAPI(); var locations = locationApi.GetAll().Select(x => new Model.Location() { Id = x.Id, Name = x.Name, AddCommand = new Command((() => AddLocation(x.Id))), RemoveCommand = new Command((() => RemoveLocation(x.Id))) }); Locations = new ObservableCollection <Model.Location>(); foreach (var location in locations) { if (LocationsRecipe.All(l => l.Id != location.Id)) { Locations.Add(location); } } #endregion }