public void Add(int creditRequestId) { var creditRequest = Uow.CreditRequestRepository.Get(creditRequestId); var dateNow = GlobalValues.BankDateTime; var credit = new DomainCustomerCredit() { CreditId = creditRequest.CreditId, CreditSum = creditRequest.Sum, Currency = creditRequest.Currency, CustomerId = creditRequest.CustomerId, StartDate = dateNow.Date, EndDate = dateNow.Date.AddMonths(creditRequest.MonthCount), ContractNumber = GenerateContractNumber(), Bill = new DomainBill() { Number = GenerateBillNumber(), CustomerId = creditRequest.CustomerId, Sum = creditRequest.Sum }, CreditRequestId = creditRequestId }; var bankBill = Uow.BillRepository.GetByNumber(ConfigurationManager.AppSettings.Get("BankBillNumber")); if (bankBill.Sum - creditRequest.Sum < 0) { throw BankClientException.ThrowNotHaveMoney(); } bankBill.Sum -= creditRequest.Sum; var paymentPlan = new CalculationCreditService().CalculatePaymentPlan(credit.CreditSum, creditRequest.Credit.PercentRate, creditRequest.MonthCount, credit.StartDate).ToList(); credit.CreditPaymentPlanItems = paymentPlan; Uow.CustomerCreditRepository.Add(Mapper.Map <CustomerCredit>(credit)); Uow.SaveChanges(); credit.Customer = Mapper.Map <DomainCustomer>(Uow.CustomerRepository.Get(credit.CustomerId)); credit.Credit = Mapper.Map <DomainCredit>(Uow.CreditRepository.Get(credit.CreditId)); new CreditDocService().FillConcreteContract(credit); }
public void Add(int creditRequestId) { var creditRequest = Uow.CreditRequestRepository.Get(creditRequestId); var dateNow = GlobalValues.BankDateTime; var credit = new DomainCustomerCredit() { CreditId = creditRequest.CreditId, CreditSum = creditRequest.Sum, Currency = creditRequest.Currency, CustomerId = creditRequest.CustomerId, StartDate = dateNow.Date, EndDate = dateNow.Date.AddMonths(creditRequest.MonthCount), ContractNumber = GenerateContractNumber(), Bill = new DomainBill() { Number = GenerateBillNumber(), CustomerId = creditRequest.CustomerId, Sum = creditRequest.Sum }, CreditRequestId = creditRequestId }; var bankBill = Uow.BillRepository.GetByNumber(ConfigurationManager.AppSettings.Get("BankBillNumber")); if (bankBill.Sum - creditRequest.Sum < 0) { throw BankClientException.ThrowNotHaveMoney(); } bankBill.Sum -= creditRequest.Sum; var paymentPlan = new CalculationCreditService().CalculatePaymentPlan(credit.CreditSum, creditRequest.Credit.PercentRate, creditRequest.MonthCount, credit.StartDate).ToList(); credit.CreditPaymentPlanItems = paymentPlan; Uow.CustomerCreditRepository.Add(Mapper.Map<CustomerCredit>(credit)); Uow.SaveChanges(); credit.Customer = Mapper.Map<DomainCustomer>(Uow.CustomerRepository.Get(credit.CustomerId)); credit.Credit = Mapper.Map<DomainCredit>(Uow.CreditRepository.Get(credit.CreditId)); new CreditDocService().FillConcreteContract(credit); }