private void AddGuard()
        {
            FirstName = Trim(FirstName);
            LastName = Trim(LastName);

            Contragent contragent = new Contragent { FirstName = FirstName, LastName = LastName };
            Guard guard = new Guard { Contragent = contragent };

            try
            {
                _mainViewModel.Context.Guards.Add(guard);
                _mainViewModel.Context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(("Не удалось добавить нового мастера"), "Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);

                Logging.WriteToLog("Failed add new repairer" + e.Message);
            }

            _mainViewModel.GuardsViewModel.Update();

            _mainViewModel.GuardsViewModel.AddGuardDialogViewModel = null;
        }
示例#2
0
 public ContragentViewModel(Contragent contragent)
 {
     ID = contragent.ID;
     FirstName = contragent.FirstName;
     LastName = contragent.LastName;
 }
        private void AddProduct()
        {
            ModelName = Trim(ModelName);
            FirstName = Trim(FirstName);
            LastName = Trim(LastName);
            SerialNumber = Trim(SerialNumber);
            Notes = Trim(Notes);

            Product product = new Product {SerialNumber = SerialNumber, SellingPrice = SellingPrice, Notes = Notes};

            if (Models.Contains(ModelName)) product.Model = GetModelIDByName(ModelName);

            if (!Models.Contains(ModelName) || product.Model == null)
            {
                Model model = new Model {Name = ModelName, CategoryID = SelectedCategory.ID};

                _mainViewModel.Context.Models.Add(model);

                product.Model = model;
            }

            _mainViewModel.Context.Products.Add(product);

            var client = _mainViewModel.Context.Clients.FirstOrDefault(
                x => x.Contragent.FirstName == FirstName && x.Contragent.LastName == LastName);

            if (client == null)
            {
                var contragent = new Contragent
                {
                    LastName = LastName,
                    FirstName = FirstName
                };

                client = new Client
                {
                    Contragent = contragent
                };

                _mainViewModel.Context.Clients.Add(client);
            }

            Transaction transaction = new Transaction
            {
                Product = product,
                Date = DateTime.Now,
                TypeID = (int) TranType.ToRepair,
                OperatorID = OperatorManager.Instance.CurrentUserID,
                Contragent = client.Contragent,
                Price = 0
            };

            _mainViewModel.Context.Transactions.Add(transaction);
            try
            {
                _mainViewModel.Context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(("Не удалось добавить новый товар"), "Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);

                Logging.WriteToLog("Failed add new bought transaction. " + e.Message);
            }

            _mainViewModel.ToRepairProductsViewModel.Update();

            _mainViewModel.ToRepairProductsViewModel.AddDialogViewModel = null;
        }
        private void AddSalesman()
        {
            FirstName = Trim(FirstName);
            LastName = Trim(LastName);

            Contragent contragent = new Contragent{FirstName = FirstName, LastName = LastName};
            Salesman salesman = new Salesman {ProfitPercentage = ProfitPercentage, SalaryPerDay = SalaryPerDay, Login = Login, Contragent = contragent};

            try
            {
                _mainViewModel.Context.Salesmen.Add(salesman);
                _mainViewModel.Context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(("Не удалось добавить нового продавца"), "Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);

                Logging.WriteToLog("Failed add new salesman" + e.Message);
            }

            _mainViewModel.SalesmenViewModel.Update();
            _mainViewModel.SalesmenViewModel.AddSalesmanDialogViewModel = null;
        }
        private void Add()
        {
            if (SelectedOperator == null) _mainViewModel.MobileTransactionsViewModel.AddDialogViewModel = null;

            Transaction transaction = new Transaction
            {
                Date = DateTime.Now,
                TypeID = (int) TranType.TopUp,
                OperatorID = OperatorManager.Instance.CurrentUserID,
                Price = Price
            };

            LastName = Trim(LastName);
            FirstName = Trim(FirstName);
            if (!string.IsNullOrEmpty(LastName) && !string.IsNullOrEmpty(FirstName))
            {
                var client =_mainViewModel.Context.Clients.FirstOrDefault(
                    x => x.Contragent.FirstName == FirstName && x.Contragent.LastName == LastName);

                if (client == null)
                {
                    var contragent = new Contragent
                    {
                        LastName = LastName,
                        FirstName = FirstName
                    };

                    client = new Client
                    {
                        Contragent = contragent
                    };

                    _mainViewModel.Context.Clients.Add(client);
                }

                transaction.Contragent = client.Contragent;
            }

            MobileTransaction mobileTransaction = new MobileTransaction
            {
                Transaction = transaction,
                CreditSum = CreditSum,
                MobileOperatorID = SelectedOperator.ID
            };

            _mainViewModel.Context.MobileTransactions.Add(mobileTransaction);
            try
            {
                _mainViewModel.Context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(("Не удалось провести пополнение"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                Logging.WriteToLog("Failed add new mobile transaction. " + e.Message);
            }

            _mainViewModel.MobileTransactionsViewModel.Update();
            _mainViewModel.CashInHand += Price;

            _mainViewModel.MobileTransactionsViewModel.AddDialogViewModel = null;
        }