Пример #1
0
        public Guid? CreateCreditForRequest(Guid requestId)
        {
            try
            {
                var request = _requestDao.Get(requestId);
                if (request == null)
                {
                    return null;
                }

                var debts = new Debts()
                {
                    Id = Guid.NewGuid(),
                    Debt = 0
                };
                _debtDao.CreateOrUpdate(debts);

                //startSum - cумма запрошеная пользователем
                int allSum = 0;
                //TODO
                var payMounth = (int)((request.StartSum + (request.StartSum * request.CreditTypes.Percent)) / request.CreditTypes.PayCount);
                var dateStart = _creditDao.GetTimeTable().Date;

                var credit = new Credit()
                {
                    Id = Guid.NewGuid(),
                    DateStart = dateStart,
                    DateEnd = dateStart.AddMonths(request.CreditTypes.PayCount),
                    Percent = request.CreditTypes.Percent,
                    StartSum = request.StartSum,
                    AllSum = allSum,
                    PayCount = request.CreditTypes.PayCount,
                    Penya = 0.04, /*belarus magic*/
                    PayMounth = payMounth,
                    PersonId = request.PersonId,
                    ManagerId = request.ManagerId.Value,
                    CreditTypeId = request.CreditTypeId,
                    DebtsId = debts.Id,
                    Status = "0",
                    RequestId = requestId
                };

                _creditDao.CreateOrUpdate(credit);

                var bankBook = new BankBook()
                {
                    Id = Guid.NewGuid(),
                    CreditId = credit.Id,
                    cache = 0
                };
                _bankBookDao.CreateOrUpdate(bankBook);

                _debtDao.SaveToBase();

                if (request.CreditTypes.CreditSubType.Abbreviation.Equals("Ann"))
                {
                    AnnuityCreadit.ProcessHistory(credit.Id);
                }
                if (request.CreditTypes.CreditSubType.Abbreviation.Equals("Grad"))
                {

                    GradedCredit.ProcessHistory(credit.Id);
                }

                request.CreditId = credit.Id;
                _requestDao.CreateOrUpdate(request);

                return credit.Id;
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #2
0
        public void Process(Object obj)
        {
            if (_mut.WaitOne())
            {
                var bankBook = (BankBook) obj;

                Console.WriteLine("поток CerditType1_Thread {0} работает", this._number);

                var credit = _creditDao.Get(bankBook.CreditId);
                Console.WriteLine("{0}", credit.AllSum);

                bankBook.cache = (short) (bankBook.cache - credit.PayMounth);

                if (_creditDao.Get(bankBook.CreditId).PayCount == 0)
                    if ((short) (_debtDao.Get(credit.DebtsId.Value).Debt) == (0))
                    {
                        Console.WriteLine("Время кредита истекло, долг = 0, кредит закрыть");
                        credit.Status = "1";
                        _creditDao.CreateOrUpdate(credit);
                        _mut.ReleaseMutex();
                        return;
                    } // если кредит закрыт и долг равен 0
                    else
                    {
                        Console.WriteLine("Время кредита истекло, долг != 0, кредит открыт");
                        _mut.ReleaseMutex();
                        return;
                    }
                if (credit.PayCount != 0) // кредит открыт
                {

                    if (bankBook.cache <= 0)
                    {
                        Debts debt = _debtDao.Get(credit.DebtsId.Value);
                        if (debt != null)
                        {
                            debt.Debt = (short) (debt.Debt + (-1)*bankBook.cache);
                            bankBook.cache = 0;
                            _bookDao.CreateOrUpdate(bankBook);
                            _debtDao.CreateOrUpdate(debt);

                        }
                        else
                        {
                            debt = new Debts
                            {
                                Id = Guid.NewGuid(),
                                Debt = (short) ((-1)*bankBook.cache)
                            };
                            bankBook.cache = 0;
                            _bookDao.CreateOrUpdate(bankBook);
                            credit.DebtsId = debt.Id;

                            _creditDao.CreateOrUpdate(credit);
                            _debtDao.CreateOrUpdate(debt);
                        }

                        credit.PayCount--;
                        _creditDao.CreateOrUpdate(credit);
                        if (credit.PayCount == 0)
                        {
                            if ((short) (_debtDao.Get(credit.DebtsId.Value).Debt) == (0))
                            {
                                Console.WriteLine("Время кредита истекло, долг = 0, кредит закрыть");
                                credit.Status = "1";
                                _creditDao.CreateOrUpdate(credit);
                            } // если кредит закрыт и долг равен 0
                            else
                            {
                                Console.WriteLine("Время кредита истекло, долг != 0({0}), кредит открыт", debt.Debt);
                                //Console.WriteLine("долг != 0, кредит открыт");
                            }

                        }
                    }
                }
            }
            _mut.ReleaseMutex();
        }