Esempio n. 1
0
 public ProductCreateViewModel()
 {
     unitAPI            = new UnitAPI();
     productCategoryAPI = new ProductCategoryAPI();
     productsAPI        = new ProductsAPI();
     Units = unitAPI.GetAll().Select(x => new Model.Unit()
     {
         Name   = x.Symbol,
         UnitId = x.Id
     }).ToList();
     ProductCategories = productCategoryAPI.GetAll().Select(x => new ProductCategory()
     {
         Name = x.Name,
         Id   = x.Id
     }).ToList();
     Create = new Command(() =>
     {
         var model               = new ProductDTO();
         model.Name              = this.name;
         model.Description       = this.description;
         model.UnitId            = SelectedUnit.UnitId;
         model.ProductCategoryId = SelectProductCategory.Id;
         var resultFlag          = productsAPI.Create(model);
         if (resultFlag)
         {
             MessageBox.Show("Продукт успешно создан");
         }
         if (!resultFlag)
         {
             MessageBox.Show("Во время создания произошла ошибка");
         }
     });
 }
Esempio n. 2
0
 public ProductEditViewModel(Product product)
 {
     UnitAPI            = new UnitAPI();
     ProductCategoryAPI = new ProductCategoryAPI();
     this.id            = product.ProductId;
     this.name          = product.Name;
     this.description   = product.Description;
     this.Units         = UnitAPI.GetAll().Select(x => new Model.Unit()
     {
         UnitId = x.Id,
         Name   = x.Name
     }).ToList();
     this.SelectedUnit    = Units.Single(x => x.UnitId == product.UnitId);
     this.ProductCategory = ProductCategoryAPI.GetAll().Select(x => new ProductCategory()
     {
         Name = x.Name,
         Id   = x.Id
     }).ToList();
     this.SelectedCategory = ProductCategory.Single(x => x.Id == product.CategoryId);
     Update = new Command(() =>
     {
         ProductsAPI productAPI       = new ProductsAPI();
         var productDTO               = new ProductDTO();
         productDTO.Name              = Name;
         productDTO.Description       = Description;
         productDTO.Id                = id;
         productDTO.UnitId            = SelectedUnit.UnitId;
         productDTO.ProductCategoryId = SelectedCategory.Id;
         var resultFlag               = productAPI.Update(productDTO);
         if (resultFlag)
         {
             MessageBox.Show("Успешно сохранено.");
         }
         if (!resultFlag)
         {
             MessageBox.Show("Во время сохранения произошла ошибка.");
         }
     });
 }