public void ExecuteSaveCredit(object obj)
        {
            if (valDate && valFirm && valSum && valRate && Currency != null && !string.IsNullOrWhiteSpace(FirmId))
            {
                using (CreditsFirmsContext context = new CreditsFirmsContext())
                {
                    Credit creditUpdate = context.Credits.FirstOrDefault(c => c.Credit_agreement == Credit_agreement);
                    creditUpdate.Start_date  = StartDate;
                    creditUpdate.End_date    = EndDate;
                    creditUpdate.Currency_Id = Currency.Currency_Id;
                    if (creditUpdate.Sum != int.Parse(SumText))
                    {
                        Principal_balance balanceAdd = new Principal_balance();
                        balanceAdd.Credit_agreement = Credit_agreement;
                        balanceAdd.Date             = DateTime.Now;
                        balanceAdd.Currency_Id      = Currency.Currency_Id;
                        balanceAdd.Balance          = int.Parse(SumText);
                        context.Principal_balance.Add(balanceAdd);
                        creditUpdate.Sum = int.Parse(SumText);
                    }
                    creditUpdate.Id_Firm = FirmId;

                    if (creditUpdate.Interest_rate.OrderByDescending(d => d.Date).FirstOrDefault().Rate != double.Parse(RateText))
                    {
                        Interest_rate rateAdd = new Interest_rate();
                        rateAdd.Credit_agreement = Credit_agreement;
                        rateAdd.Date             = DateTime.Now;
                        rateAdd.Rate             = double.Parse(RateText);
                        context.Interest_rate.Add(rateAdd);
                    }
                    context.SaveChanges();
                    CloseWnd(this, new EventArgs());
                    MessageBox.Show("Операция проведена успешно", "Редактирование договора обеспечения",
                                    MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            else
            {
                MessageBox.Show("Не все поля заполены корректно", "Ошибка при регистрации договора",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        public void ExecuteSaveCredit(object obj)
        {
            if (valAgreement && valDate && valFirm && valSum && valRate && Currency != null && !string.IsNullOrWhiteSpace(Credit_agreement) &&
                !string.IsNullOrWhiteSpace(FirmId) && !string.IsNullOrWhiteSpace(SumText) && !string.IsNullOrWhiteSpace(RateText))
            {
                using (CreditsFirmsContext context = new CreditsFirmsContext())
                {
                    Credit creditAdd = new Credit();
                    creditAdd.Credit_agreement = Credit_agreement;
                    creditAdd.Start_date       = StartDate;
                    creditAdd.End_date         = EndDate;
                    creditAdd.Currency_Id      = Currency.Currency_Id;
                    creditAdd.Sum     = int.Parse(SumText);
                    creditAdd.Id_Firm = FirmId;
                    context.Credits.Add(creditAdd);

                    Principal_balance balanceAdd = new Principal_balance();
                    balanceAdd.Credit_agreement = Credit_agreement;
                    balanceAdd.Date             = StartDate;
                    balanceAdd.Currency_Id      = Currency.Currency_Id;
                    balanceAdd.Balance          = int.Parse(SumText);
                    context.Principal_balance.Add(balanceAdd);

                    Interest_rate rateAdd = new Interest_rate();
                    rateAdd.Credit_agreement = Credit_agreement;
                    rateAdd.Date             = StartDate;
                    rateAdd.Rate             = double.Parse(RateText);
                    context.Interest_rate.Add(rateAdd);

                    context.SaveChanges();
                    CloseWnd(this, new EventArgs());
                }
                MessageBox.Show("Операция проведена успешно", "Регистрация кредитного договора",
                                MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            else
            {
                MessageBox.Show("Не все поля заполены корректно", "Ошибка при регистрации договора",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }