Ejemplo n.º 1
0
        public CustomerDepositResult Add(DomainCustomerDeposit customerDeposit, int monthCount, string email, string baseLocalhostUrl, ModelStateDictionary modelState)
        {
            var domainDeposit = Mapper.Map<DomainDeposit>(Uow.DepositRepository.Get(customerDeposit.DepositId));
            _iValidationService.ValidateSum(customerDeposit.InitialSum, domainDeposit.MinSum, domainDeposit.MaxSum, modelState, true);
            _iValidationService.ValidateMonthCount(monthCount, domainDeposit.MinMonthPeriod, domainDeposit.MaxMonthPeriod, modelState);

            customerDeposit.StartDate = GlobalValues.BankDateTime;
            customerDeposit.EndDate = customerDeposit.StartDate.AddMonths(monthCount);
            if (!modelState.IsValid)
            {
                return new CustomerDepositResult
                {
                    ModelState = modelState
                };
            }

            var customer = customerDeposit.Customer;//_iUnitOfWork.CustomerRepository.GetCustomerByUserId(userId);
            var customerDb = Uow.CustomerRepository.GetAll()
                .FirstOrDefault(c => c.IdentificationNumber == customerDeposit.Customer.IdentificationNumber);
            if (customerDb == null)
            {
                var id = _iCustomerService.Register(customer, email);
                customerDeposit.CustomerId = id;
            }
            else
            {
                customerDeposit.CustomerId = customerDb.Id;
            }

            customerDeposit.StartDate = GlobalValues.BankDateTime;
            customerDeposit.ContractNumber = GenerateContractNumber();
            customerDeposit.Bill = new DomainBill
            {
                Number = GenerateBillNumber(),
                CustomerId = customerDeposit.CustomerId,
                Sum = customerDeposit.InitialSum
            };

            customerDeposit.DepositPayments = new List<DomainDepositPayment>()
            {
                new DomainDepositPayment()
                {
                    Currency = Currency.Blr,
                    DateTime = customerDeposit.StartDate,
                    Sum = customerDeposit.InitialSum,
                    DestinationBill = customerDeposit.Bill
                }
            };
            var bankBill = Uow.BillRepository
                .GetByNumber(ConfigurationManager.AppSettings.Get("BankBillNumber"));
            bankBill.Sum += customerDeposit.InitialSum;

            var dbDeposit = Mapper.Map<CustomerDeposit>(customerDeposit);
            dbDeposit.Customer = null;
            Uow.CustomerDepositRepository.Add(dbDeposit);
            Uow.SaveChanges();

            //            Uow.Reload(dbDeposit);
            //            deposit = Mapper.Map<DomainCustomerDeposit>(Uow.DepositRepository.Get(dbDeposit.Id));
            customerDeposit.Deposit = Mapper.Map<DomainDeposit>(Uow.DepositRepository.Get(customerDeposit.DepositId));
            new DepositDocService().FillConcreteContract(customerDeposit);
            return new CustomerDepositResult()
            {
                ModelState = null,
                DocPath = GetContract(dbDeposit.ContractNumber, baseLocalhostUrl)
            };
        }
Ejemplo n.º 2
0
 public void Update(DomainCustomerDeposit domainCredit)
 {
     var deposit = Mapper.Map<CustomerDeposit>(domainCredit);
     Uow.CustomerDepositRepository.Update(deposit);
     Uow.SaveChanges();
 }
Ejemplo n.º 3
0
        private void Validate(DomainCustomerDeposit customerDeposit, DomainDeposit deposit, int monthCount)
        {
            if (customerDeposit.InitialSum < deposit.MinSum)
            {
                throw BankClientException.ThrowSumLessThanMin();
            }

            if (customerDeposit.InitialSum > deposit.MaxSum)
            {
                throw BankClientException.ThrowSumMoreThanMax();
            }

            if (monthCount < deposit.MinMonthPeriod)
            {
                throw BankClientException.ThrowMonthLessThanMin();
            }

            if (monthCount > deposit.MaxMonthPeriod)
            {
                throw BankClientException.ThrowMonthMoreThanMax();
            }
        }
Ejemplo n.º 4
0
        public void FillConcreteContract(DomainCustomerDeposit customerDeposit)
        {
            if (!File.Exists(_templateDocPath))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(_templateDocPath));
                GenerateContractTemplate();
            }

            var byteArray = File.ReadAllBytes(_templateDocPath);

            using (var stream = new MemoryStream())
            {
                stream.Write(byteArray, 0, byteArray.Length);
                using (var wordDoc = WordprocessingDocument.Open(stream, true))
                {
                    var body = wordDoc.MainDocumentPart.Document.Body;
                    var runs = body.Descendants<Run>().ToList();
                    var i = 0;

                    //contract number
                    FindAndReplace(ref i, runs, ContractNumberPlace, " " + customerDeposit.ContractNumber);

                    //day & month
                    FindAndReplace(ref i, runs, DaymonthPlace, customerDeposit.StartDate.ToString("dd MM"));//customerDeposit.StartDate.ToString("M"));

                    //year
                    FindAndReplace(ref i, runs, YearPlace, " " + customerDeposit.StartDate.ToString("yyyy"));

                    //customerPlace
                    FindAndReplace(ref i, runs, CustomerPlace,
                        string.Format("{0} {1}{2}", customerDeposit.Customer.Lastname,
                            customerDeposit.Customer.Firstname,
                            customerDeposit.Customer.Patronymic != null
                                ? " " + customerDeposit.Customer.Patronymic
                                : ""), UnderlineValues.None);

                    //credit name
            //                    FindAndReplace(ref i, runs, CreditPlace, customerDeposit.Deposit.Name);

                    //sum
                    FindAndReplace(ref i, runs, SumPlace, customerDeposit.InitialSum.ToString());

                    //since
                    FindAndReplace(ref i, runs, SincePlace, customerDeposit.StartDate.ToString("dd.MM.yyyy"));

                    //end date
                    FindAndReplace(ref i, runs, UntilPlace, customerDeposit.EndDate.ToString("dd.MM.yyyy"));

                    //percent rate
                    FindAndReplace(ref i, runs, PercentRatePlace, customerDeposit.Deposit.InterestRate.ToString());

                    //payment day
                    FindAndReplace(ref i, runs, PaymentDayPlace, customerDeposit.StartDate.ToString("dd"));

                    wordDoc.MainDocumentPart.Document.Save();
                    //                        wordDoc.MainDocumentPart.Document.Save(fs);
                    File.WriteAllBytes(
                        string.Format("{0}{1}.docx", _creditContractsDocPath, customerDeposit.ContractNumber),
                        stream.ToArray());
                }
            }
        }