Esempio n. 1
0
 private void UploadDetails(object obj)
 {
     try
     {
         var        client     = obj as ClientModel;
         ToBuysData toBuysData = new ToBuysData();
         var        orders     = toBuysData.GetToBuysByClientId(new
         {
             ClientId = client.Id
         });
         ToBuysProductsData    toBuysProductsData = new ToBuysProductsData();
         List <WHProductModel> productsDB         = new List <WHProductModel>();
         orders.ForEach(x => productsDB.Add(toBuysProductsData.GetProductById(new
         {
             x.ProductId
         })));
         BindableCollection <WareHouseProductModel> products = new BindableCollection <WareHouseProductModel>(_mapper.Map <List <WareHouseProductModel> >(productsDB));
         _windowManager.ShowWindow(IoC.Get <ToBuyDetailsViewModel>());
         _events.PublishOnUIThread(new ToBuyDetailsEventModel(products, client, orders));
     }
     catch (Exception ex)
     {
         MessageBox.Show("Message: \n" + ex.Message + '\n' +
                         "StackTrase: \n" + ex.StackTrace + '\n' +
                         "InnerException: \n" + ex.InnerException);
     }
 }
        public void SaveChanges()
        {
            ToBuysData toBuysData = new ToBuysData();
            int        counter    = 0;

            foreach (var item in ProductsToBuy)
            {
                if (InputHelper.isCorrectWareHouseProductToBuy(item))
                {
                    OPostModel postModel = new OPostModel()
                    {
                        ProductId        = item.ProductId,
                        ProductQuantity  = item.QuantityInStock,
                        ProductNetPrice  = item.NetPrice,
                        ProductSellPrice = item.SellPrice,
                        ClientId         = SelectedClient.Id
                    };
                    toBuysData.UpdateToBuy(postModel);
                    counter++;
                }
                else
                {
                    MessageBox.Show(InputHelper.isWrongWareHouseProductMassageToBuy(item));
                    break;
                }
            }
            if (counter == ProductsToBuy.Count)
            {
                MessageBox.Show("Замовлення успішно оновлено.");
            }
        }
 private void ExecuteReverseOrder(object obj)
 {
     try
     {
         ToBuysData toBuysData = new ToBuysData();
         var        product    = obj as WareHouseProductModel;
         var        orders     = toBuysData.GetToBuyByClientId(new
         {
             ClientId = SelectedClient.Id
         });
         orders.Where(x => x.ProductId == product.ProductId).ToList().ForEach(x => toBuysData.ReverseToBuyByProduct(x));
         BindableCollection <WareHouseProductModel> found = new BindableCollection <WareHouseProductModel>();
         foreach (var item in ProductsToBuy)
         {
             if (item.ProductId != product.ProductId)
             {
                 found.Add(item);
             }
         }
         ProductsToBuy = found;
         if (ProductsToBuy.Count == 0)
         {
             this.TryClose();
             _events.PublishOnUIThread(new ToBuysAllProductsDeletedEventModel());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Message: \n" + ex.Message + '\n' +
                         "StackTrase: \n" + ex.StackTrace + '\n' +
                         "InnerException: \n" + ex.InnerException);
     }
 }
Esempio n. 4
0
        public async Task MakeToBuy()
        {
            bool isOrdarable = true;

            for (int i = 0; i < ProductsForOrder.Count; i++)
            {
                if (ProductsForOrder[i].QuantityInStock <= 0)
                {
                    isOrdarable = false;
                    MessageBox.Show($"Кількість товару '{ProductsForOrder[i].Name}' менша-рівна нулю.");
                }
            }
            if (isOrdarable)
            {
                try
                {
                    ToBuysData        toBuysData  = new ToBuysData();
                    List <OrderModel> orderModels = new List <OrderModel>();
                    foreach (var item in ProductsForOrder)
                    {
                        OrderModel order = new OrderModel()
                        {
                            ProductId        = item.ProductId,
                            ProductQuantity  = item.QuantityInStock,
                            ProductNetPrice  = item.NetPrice,
                            ProductSellPrice = item.SellPrice,
                            ClientId         = SelectedClient.Id
                        };
                        orderModels.Add(order);
                    }
                    var orders = _mapper.Map <List <OPostModel> >(orderModels);
                    foreach (var item in orders)
                    {
                        toBuysData.PostToBuy(item);
                    }
                    await _events.PublishOnUIThreadAsync(new MakeToBuyMadeEventModel());

                    MessageBox.Show("Замовлення успішно оформлено.");
                    this.TryClose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Message: \n" + ex.Message + '\n' +
                                    "StackTrase: \n" + ex.StackTrace + '\n' +
                                    "InnerException: \n" + ex.InnerException);
                }
            }
        }
Esempio n. 5
0
 private void ExecuteReverseOrder(object obj)
 {
     try
     {
         var        client      = obj as ClientModel;
         ToBuysData _toBuysData = new ToBuysData();
         var        toBuys      = _toBuysData.GetToBuysByClientId(new
         {
             ClientId = client.Id
         });
         toBuys.ForEach(x => _toBuysData.ReverseToBuys(x));
         RefreshView();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Message: \n" + ex.Message + '\n' +
                         "StackTrase: \n" + ex.StackTrace + '\n' +
                         "InnerException: \n" + ex.InnerException);
     }
 }
Esempio n. 6
0
        private void ExecuteFinishOrder(object obj)
        {
            var                   client              = obj as ClientModel;
            ToBuysData            _toBuysData         = new ToBuysData();
            ToBuysProductsData    _toBuysProductsData = new ToBuysProductsData();
            var                   orders              = _toBuysData.GetToBuysAllByClientId(new { ClientId = client.Id });
            List <WHProductModel> productModels       = new List <WHProductModel>();

            orders.ForEach(x => productModels.Add(_toBuysProductsData.GetProductById(new { x.ProductId })));
            List <HPostModel> historyPostModels = new List <HPostModel>();

            for (int i = 0; i < orders.Count; i++)
            {
                historyPostModels.Add(new HPostModel
                {
                    Sender             = false,
                    ProductId          = orders[i].ProductId,
                    FactoryNumber      = productModels[i].FactoryNumber,
                    Name               = productModels[i].Name,
                    Set                = productModels[i].Set,
                    Type               = productModels[i].Type,
                    Photo              = productModels[i].Photo,
                    ProductQuantity    = orders[i].ProductQuantity,
                    ProductDescription = productModels[i].ProductDescription,
                    ProductNetPrice    = orders[i].ProductNetPrice,
                    ProductSellPrice   = orders[i].ProductSellPrice,
                    OrderDateTime      = orders[i].OrderDateTime,
                    ClientId           = client.Id
                });
            }
            HistoryData historyData = new HistoryData();

            foreach (var item in historyPostModels)
            {
                historyData.PostHistory(item);
            }
            RefreshView();
        }