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; }
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; }
public ClientViewModel(Client client) : base(client.Contragent) { }