public ActionResult Approve(long id)
        {
            ICollection<ValidationResult> error = new List<ValidationResult>();
            CommitteeResolution committeeResolution;

            try
            {
                using (var unitOfWork = new UnitOfWork(new BankModuleFactory()))
                {
                    var Service = new CommitteeResolutionService(unitOfWork);
                    committeeResolution = Service.Get(sr => sr.LoanApplicationId == id).First();
                    committeeResolution.UserId = Authentication.User.Id;
                    Service.ApproveResolution(committeeResolution);
                    error = unitOfWork.Commit();
                }
                if (error.Any())
                {
                    ModelState.AddModelError(string.Empty, error.First().ErrorMessage);
                    return View();
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return View();
            }
            return RedirectToAction("LoanApplicationList");
        }
        static void Main(string[] args)
        {
            using (var studContext = new StudBankContext(true))
            {
                var AccountService = new AccountService(studContext);
                Console.WriteLine("Accounts:");
                foreach(var account in AccountService.Get())
                {
                    System.Console.WriteLine(string.Format("{0} {1} {2} {3} Transfers From: {4}  Transfers To:{5}",
                        account.IBAN, account.AccountType, account.MoneyAmount, account.Currency, account.BankTransfersFrom.Count, account.BankTransfersTo.Count));
                }

                var BankTransferService = new BankTransferService(studContext);
                Console.WriteLine("Transfers:");
                foreach (var transfer in BankTransferService.Get(includeProperties: "AccountFrom,AccountTo"))
                    Console.WriteLine(string.Format("From: {0} To: {1} {2} {3} {4}", transfer.AccountFrom.IBAN, transfer.AccountTo.IBAN,
                        transfer.Amount, transfer.Currency, transfer.TransferDate.ToShortDateString()));

                var LoanAgreementService = new LoanAgreementService(studContext);
                Console.WriteLine("Loan Agreements:");
                foreach (var loanAgreement in LoanAgreementService.Get(includeProperties: "PayoutStatus"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", loanAgreement.Client.FirstName, loanAgreement.LoanType,
                        loanAgreement.LoanProviding, loanAgreement.LoanRepayment, loanAgreement.Term, loanAgreement.Amount, loanAgreement.Currency));

                var PayoutService = new PayoutService(studContext);
                Console.WriteLine("Payouts:");
                foreach (var payout in PayoutService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", payout.PayoutWay, payout.LoanAmount, payout.ProcessingFee,
                        payout.InterestAmount, payout.TotalAmount, payout.Currency));

                var FineService = new FineService(studContext);
                Console.WriteLine("Fines:");
                foreach (var fine in FineService.Get(includeProperties: "LoanAgreement"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3}", fine.LoanAgreement.Id,
                        fine.DeadLineDate.ToShortDateString(), fine.FineRateOfInterest, fine.IsClosed));

                var WithdrawalService = new WithdrawalService(studContext);
                Console.WriteLine("Withdrawals:");
                foreach (var withdrawal in WithdrawalService.Get(includeProperties: "ClientAccount,LoanAgreement"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", withdrawal.ClientAccount.Id, withdrawal.MoneyAmount,
                        withdrawal.Currency, withdrawal.WithdrawalWay, withdrawal.Date.ToShortDateString()));

                var PersonService = new PersonService(studContext);
                Console.WriteLine("Persons:");
                foreach (var person in PersonService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} Documents: {3} Records: {4}", person.FirstName, person.IdentificationNumber,
                        person.MonthlyIncome, person.Documents.Count, person.CreditHistoryRecords.Count));

                var HistoryService = new CreditHistoryRecordService(studContext);
                Console.WriteLine("Records:");
                foreach (var record in HistoryService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", record.Person.FirstName, record.BankConstants.BIC,
                        record.Amount, record.Currency, record.Interest));

                var LoanService = new LoanService(studContext);
                Console.WriteLine("Loan programs:");
                foreach (var program in LoanService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", program.Name, program.LoanProviding,
                        program.LoanGuarantee, program.LoanRepayment, program.LoanType, program.MaxAmount));

                var LoanApplicationService = new LoanApplicationService(studContext);
                Console.WriteLine("Loan applications:");
                foreach (var loanApplication in LoanApplicationService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} First surety:{5}", loanApplication.Client.FirstName, loanApplication.Loan.Name,
                        loanApplication.Amount, loanApplication.Currency, loanApplication.Term, loanApplication.Sureties.FirstOrDefault().FirstName));

                var SuretyAgreementService = new SuretyAgreementService(studContext);
                Console.WriteLine("Surety agreements:");
                foreach (var suretyAgreement in SuretyAgreementService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", suretyAgreement.Client.FirstName, suretyAgreement.Guarantor.FirstName,
                        suretyAgreement.Amount, suretyAgreement.Currency, suretyAgreement.LoanTerm, suretyAgreement.SuretyTerm));

                var BailAgreementService = new BailAgreementService(studContext);
                Console.WriteLine("Bail agreements:");
                foreach (var bailAgreement in BailAgreementService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", bailAgreement.Client.FirstName, bailAgreement.BailObject,
                        bailAgreement.Amount, bailAgreement.Currency, bailAgreement.LoanTerm, bailAgreement.BailTerm));

                var SystemService = new SystemResolutionService(studContext);
                Console.WriteLine("System resolutions:");
                foreach (var resolution in SystemService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.MaxLoanAmount,
                        resolution.ScoringPoint));

                var SecurityService = new SecurityResolutionService(studContext);
                Console.WriteLine("Security resolutions:");
                foreach (var resolution in SecurityService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Property,
                        resolution.PropertyEstimate));

                var ExpertService = new ExpertResolutionService(studContext);
                Console.WriteLine("Expert resolutions:");
                foreach (var resolution in ExpertService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Property,
                        resolution.PropertyEstimate));

                var CommitteeService = new CommitteeResolutionService(studContext);
                Console.WriteLine("Committee resolutions:");
                foreach (var resolution in CommitteeService.Get())
                    Console.WriteLine(string.Format("Link: {0} {1}", resolution.ProtocolDocument.Link, resolution.Resolution));
            }

            Console.WriteLine("\nAuthentification: ");
            using (var authContext = new StudAuthorizeContext(true))
            {
                var userService = new EntityService<User>(authContext);
                var roleService = new EntityService<Role>(authContext);
                foreach (var user in userService.Get(includeProperties: "Roles"))
                {
                    System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName,
                        user.MiddleName, user.LastName, user.Roles.First().Name));
                }
                System.Console.WriteLine();

                userService.Get(user => user.FirstName == "Ivan").First().FirstName = "Vano";
                authContext.SaveChanges();

                foreach (var user in userService.Get(includeProperties: "Roles"))
                {
                    System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName,
                        user.MiddleName, user.LastName, user.Roles.First().Name));
                }
            }

            System.Console.ReadKey(true);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            bool useAutoGeneration = false;
            bool useTests = false;
            bool useInitializers = true;

            if(useAutoGeneration)
            {
                using (var unitOfWork = new UnitOfWork(new BankModuleFactory(useInitializers)))
                {
                    var LoanApplicationService = new LoanApplicationService(unitOfWork);
                    var LoanAgreementService = new LoanAgreementService(unitOfWork);

                    Console.WriteLine("Автогенерация для заявок:");
                    foreach (var loanApplication in LoanApplicationService.Get())
                    {
                        if (loanApplication.Goal == "Смена гардероба" || loanApplication.Goal == "Пластическая операция" || loanApplication.Additional == "Car loan test"
                            || loanApplication.Additional == "Grad loan test 1" || loanApplication.Additional == "Grad loan test 2")
                        {
                            Console.WriteLine(string.Format("{0} {1} {2}", loanApplication.Client.FirstName, loanApplication.Goal, loanApplication.Term));

                            loanApplication.Status.Stage = ApplicationConsiderationStages.ApplicationConfirmationQueue;
                            LoanApplicationService.ApproveApplication(loanApplication);
                            loanApplication.Status.Stage = ApplicationConsiderationStages.Providing;
                            LoanAgreementService.CompleteAgreement(loanApplication.LoanAgreements.First());
                            unitOfWork.Commit();
                        }
                    }

                    Console.WriteLine("\nРезультаты:\n");
                    foreach (var loanApplication in LoanApplicationService.Get())
                    {
                        if (loanApplication.Goal == "Смена гардероба" || loanApplication.Goal == "Пластическая операция" || loanApplication.Additional == "Car loan test"
                            || loanApplication.Additional == "Grad loan test 1" || loanApplication.Additional == "Grad loan test 2")
                        {
                            Console.WriteLine(string.Format("{0} {1} {2}", loanApplication.Client.FirstName, loanApplication.Goal, loanApplication.Term));
                            Console.WriteLine("Создан кредитный договор:");
                            var loanAgreement = loanApplication.LoanAgreements.First();
                            Console.WriteLine(string.Format("Номер:{0} Кредитный аккаунт:{1} Аккаунт для оплаты:{2}", loanAgreement.Id, loanAgreement.LoanAccount.IBAN,
                                loanAgreement.RepaymentAccount.IBAN));
                            foreach(var bailAgreement in loanApplication.BailAgreements)
                            {
                                Console.WriteLine("Создан договор залога:");
                                Console.WriteLine(string.Format("Номер:{0} Объект:{1} Владелец:{2}", bailAgreement.Id, bailAgreement.BailObject,
                                    bailAgreement.BailObjectHolder));
                            }
                            foreach (var suretyAgreement in loanApplication.SuretyAgreements)
                            {
                                Console.WriteLine("Создан договор поручительства:");
                                Console.WriteLine(string.Format("Номер:{0} Поручитель:{1} Должник:{2}", suretyAgreement.Id, suretyAgreement.Guarantor.FirstName + " " + suretyAgreement.Guarantor.LastName,
                                    suretyAgreement.Client.FirstName));
                            }
                            Console.WriteLine();
                        }
                    }
                }
                System.Console.ReadKey(true);
                return;
            }

            if(useTests)
            {
                Console.WriteLine(new LoanTest().RunTest());
                Console.WriteLine(new UserTest().RunTest());
                System.Console.ReadKey(true);
                return;
            }

            List<LoanApplication> archiveApplications;

            using (var unitOfWork = new UnitOfWork(new BankModuleFactory(useInitializers)))
            {
                var AccountService = new AccountService(unitOfWork);
                Console.WriteLine("Accounts:");
                foreach(var account in AccountService.Get())
                {
                    System.Console.WriteLine(string.Format("{0} {1} {2} {3} Transfers From: {4}  Transfers To:{5}",
                        account.IBAN, account.AccountType, account.MoneyAmount, account.Currency, account.BankTransfersFrom.Count, account.BankTransfersTo.Count));
                }

                var BankTransferService = new BankTransferService(unitOfWork);
                Console.WriteLine("Transfers:");
                foreach (var transfer in BankTransferService.Get(includeProperties: "AccountFrom,AccountTo"))
                    Console.WriteLine(string.Format("From: {0} To: {1} {2} {3} {4}", transfer.AccountFrom.IBAN, transfer.AccountTo.IBAN,
                        transfer.Amount, transfer.Currency, transfer.TransferDate.ToShortDateString()));

                var LoanAgreementService = new LoanAgreementService(unitOfWork);
                Console.WriteLine("Loan Agreements:");
                foreach (var loanAgreement in LoanAgreementService.Get(includeProperties: "PayoutStatus"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", loanAgreement.Client.FirstName, loanAgreement.LoanType,
                        loanAgreement.LoanProviding, loanAgreement.LoanRepayment, loanAgreement.Term, loanAgreement.Amount, loanAgreement.Currency));

                var PayoutService = new PayoutService(unitOfWork);
                Console.WriteLine("Payouts:");
                foreach (var payout in PayoutService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", payout.PayoutWay, payout.LoanAmount, payout.ProcessingFee,
                        payout.InterestAmount, payout.TotalAmount, payout.Currency));

                var FineService = new FineService(unitOfWork);
                Console.WriteLine("Fines:");
                foreach (var fine in FineService.Get(includeProperties: "LoanAgreement"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3}", fine.LoanAgreement.Id,
                        fine.DeadLineDate.ToShortDateString(), fine.FineRateOfInterest, fine.IsClosed));

                var WithdrawalService = new WithdrawalService(unitOfWork);
                Console.WriteLine("Withdrawals:");
                foreach (var withdrawal in WithdrawalService.Get(includeProperties: "ClientAccount,LoanAgreement"))
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", withdrawal.ClientAccount.Id, withdrawal.MoneyAmount,
                        withdrawal.Currency, withdrawal.WithdrawalWay, withdrawal.Date.ToShortDateString()));

                var PersonService = new PersonService(unitOfWork);
                Console.WriteLine("Persons:");
                foreach (var person in PersonService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} Documents: {3} Records: {4}", person.FirstName, person.IdentificationNumber,
                        person.MonthlyIncome, person.Documents.Count, person.CreditHistoryRecords.Count));

                var HistoryService = new CreditHistoryRecordService(unitOfWork);
                Console.WriteLine("Records:");
                foreach (var record in HistoryService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", record.Person.FirstName, record.BankConstants.BIC,
                        record.Amount, record.Currency, record.Interest));

                var LoanService = new LoanService(unitOfWork);
                Console.WriteLine("Loan programs:");
                foreach (var program in LoanService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", program.Name, program.LoanProviding,
                        program.LoanGuarantee, program.LoanRepayment, program.LoanType, program.MaxAmount));

                var LoanApplicationService = new LoanApplicationService(unitOfWork);
                Console.WriteLine("Loan applications:");
                foreach (var loanApplication in LoanApplicationService.Get())
                {
                    Console.WriteLine(string.Format("{0} {1} {2} {3} Time: {4}", loanApplication.Client.FirstName, loanApplication.Loan.Name,
                        loanApplication.Amount, loanApplication.Term, loanApplication.Status.ChangedDate.TimeOfDay.ToString()));
                }
                unitOfWork.Commit();

                var SuretyAgreementService = new SuretyAgreementService(unitOfWork);
                Console.WriteLine("Surety agreements:");
                foreach (var suretyAgreement in SuretyAgreementService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", suretyAgreement.Client.FirstName, suretyAgreement.Guarantor.FirstName,
                        suretyAgreement.Amount, suretyAgreement.Currency, suretyAgreement.LoanTerm, suretyAgreement.SuretyTerm));

                var BailAgreementService = new BailAgreementService(unitOfWork);
                Console.WriteLine("Bail agreements:");
                foreach (var bailAgreement in BailAgreementService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", bailAgreement.Client.FirstName, bailAgreement.BailObject,
                        bailAgreement.Amount, bailAgreement.Currency, bailAgreement.LoanTerm, bailAgreement.BailTerm));

                var BailObjectService = new BailObjectsService(unitOfWork);
                Console.WriteLine("Bail objects:");
                foreach (var bailObject in BailObjectService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3}", bailObject.Object, bailObject.ClientIdentificationNumber,
                        bailObject.BailObjectEstimate, bailObject.Currency));

                var SystemService = new SystemResolutionService(unitOfWork);
                Console.WriteLine("System resolutions:");
                foreach (var resolution in SystemService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.MaxLoanAmount,
                        resolution.ScoringPoint));

                 var SecurityService = new SecurityResolutionService(unitOfWork);
                Console.WriteLine("Security resolutions:");
                foreach (var resolution in SecurityService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}{3}", resolution.LoanApplication.Id, resolution.Income,
                        Environment.NewLine,
                        resolution.IncomeEstimate));

                var ExpertService = new ExpertResolutionService(unitOfWork);
                Console.WriteLine("Expert resolutions:");
                foreach (var resolution in ExpertService.Get())
                    Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Social,
                        resolution.SocialEstimate));

                var CommitteeService = new CommitteeResolutionService(unitOfWork);
                Console.WriteLine("Committee resolutions:");
                foreach (var resolution in CommitteeService.Get())
                    Console.WriteLine(string.Format("Link: {0} {1}", resolution.ProtocolDocument.Link, resolution.Resolution));

                archiveApplications = LoanApplicationService.Get
                    (app => app.Id < 5, app => app.OrderBy(p => p.Id),
                    app => app.Client,
                    app => app.LoanAgreements,
                    app => app.LoanAgreements.Select(l => l.BankConstants),
                    app => app.LoanAgreements.Select(l => l.Payouts),
                    app => app.LoanAgreements.Select(l => l.ClientWithdrawals),
                    app => app.BailAgreements.Select(b => b.AgreementDocument),
                    app => app.BailAgreements.Select(b => b.EstimationDocument),
                    app => app.BailAgreements.Select(b => b.InsuranceDocument),
                    app => app.SuretyAgreements.Select(s => s.AgreementDocument),
                    app => app.SuretyAgreements.Select(s => s.Client),
                    app => app.SuretyAgreements.Select(s => s.Guarantor),
                    app => app.SuretyAgreements.Select(s => s.BankConstants)
                    ).ToList();
            }

            using (var archiveUnit = new UnitOfWork(new ArchiveModuleFactory(useInitializers)))
            {
                var ApplicationService = new ArchiveLoanApplicationService(archiveUnit);
                foreach(var arch in archiveApplications)
                    ApplicationService.ArchiveApplication(arch);

                archiveUnit.Commit();
            }

            using (var archiveUnit = new UnitOfWork(new ArchiveModuleFactory(false)))
            {
                var ApplicationService = new ArchiveLoanApplicationService(archiveUnit);

                Console.WriteLine("\nArchived applications:");
                foreach (var loanApplication in ApplicationService.Get())
                    Console.WriteLine(string.Format("{0} {1} {2} {3} Time: {4}", loanApplication.ClientIdentificationNumber, loanApplication.LoanAgreements.Count,
                        loanApplication.Amount, loanApplication.Term, loanApplication.ArchivedDate.TimeOfDay.ToString()));
            }

            Console.WriteLine("\nAuthentification: ");
            using (var unitOfWork = new UnitOfWork(new AuthorizationModuleFactory(useInitializers)))
            {
                var userService = new UserService(unitOfWork);
                foreach (var user in userService.Get(includeProperties: "Roles"))
                {
                    System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName,
                        user.MiddleName, user.LastName, user.Roles.First().Name));

                    var newUser = userService.GetLoggedUser(user.Login, "ivan_peresvetov_pass");
                    if(newUser != null)
                        Console.WriteLine("Found ivan!");
                }
            }

            System.Console.ReadKey(true);
        }