Beispiel #1
0
        public String Credit(Credit credit)
        {
            MakeNeedOperation();
            ViewBag.Title = "Взять кредит";
            ViewBag.Id    = TempData["Id"];
            var      clients         = _context.Residents;
            Resident currentResident = new Resident();
            Resident bank            = new Resident();

            foreach (var person in clients)
            {
                if (person.Surname == "Банк")
                {
                    bank = person;
                }
            }

            foreach (var person in clients)
            {
                if (person.Id == ViewBag.Id)
                {
                    TempData["Id"]            = person.Id;
                    TempData["Name"]          = person.Name;
                    TempData["Surname"]       = person.Surname;
                    TempData["Patronymic"]    = person.Patronymic;
                    TempData["Login"]         = person.Login;
                    TempData["Password"]      = person.Password;
                    TempData["Money"]         = person.Money;
                    TempData["MoneyInCourse"] = person.MoneyInCourse;
                    TempData.Keep();
                    currentResident = person;
                }
            }

            if (credit.Summa == 0)
            {
                return("Сумма кредита не может соствлять 0 рублей");
            }

            double summaForGetBank = Math.Round(credit.Summa + credit.Summa * credit.Duration * 13 / 36500, 2);

            if (summaForGetBank == credit.Summa)
            {
                return("Данная операция не имеет смысла - Банк получит ни 1 копейки");
            }
            _context.Credits.Add(credit);
            currentResident.Money = currentResident.Money + credit.Summa;
            bank.Money            = bank.Money - credit.Summa;
            NeedOperation newOperation = new NeedOperation();

            newOperation.Id        = 0;
            newOperation.Sender    = currentResident.Id;
            newOperation.Recipient = 1;
            newOperation.Money     = summaForGetBank;
            int currentTime    = credit.Duration * 24;
            int currentHours   = currentTime / 60;
            int currentMinutes = currentTime - currentHours * 60;

            newOperation.Time = DateTime.Now.AddHours(currentHours).AddMinutes(currentMinutes);
            _context.NeedOprerations.Add(newOperation);
            _context.SaveChanges();
            return("Вы получили кредит суммой " + credit.Summa + " рублей. Через " + credit.Duration + " дней Вы должны вернуть банку " + Convert.ToString(summaForGetBank) + " рублей.");
        }
Beispiel #2
0
        public String MoneyContribution(MoneyContribution moneyContribution)
        {
            MakeNeedOperation();
            ViewBag.Title = "Сделать вклад";
            ViewBag.Id    = TempData["Id"];
            var      clients         = _context.Residents;
            Resident currentResident = new Resident();
            Resident bank            = new Resident();

            foreach (var person in clients)
            {
                if (person.Surname == "Банк")
                {
                    bank = person;
                }
            }

            foreach (var person in clients)
            {
                if (person.Id == ViewBag.Id)
                {
                    TempData["Id"]            = person.Id;
                    TempData["Name"]          = person.Name;
                    TempData["Surname"]       = person.Surname;
                    TempData["Patronymic"]    = person.Patronymic;
                    TempData["Login"]         = person.Login;
                    TempData["Password"]      = person.Password;
                    TempData["Money"]         = person.Money;
                    TempData["MoneyInCourse"] = person.MoneyInCourse;
                    TempData.Keep();
                    currentResident = person;
                }
            }

            if (moneyContribution.Summa == 0)
            {
                return("Сумма вклада не может соствлять 0 рублей");
            }

            if (moneyContribution.Summa > currentResident.Money)
            {
                return("Вы не располагаете такой суммой");
            }

            if (moneyContribution.Duration > 31)
            {
                return("Вы указали слишком большой срок вклада");
            }


            double summaForGetClient = Math.Round(moneyContribution.Summa + moneyContribution.Summa * moneyContribution.Duration * 7 / 36500, 2);

            if (summaForGetClient == moneyContribution.Summa)
            {
                return("Данная операция не имеет смысла - Вы получите менее 1 копейки");
            }

            _context.MoneyContributions.Add(moneyContribution);
            currentResident.Money = currentResident.Money - moneyContribution.Summa;
            bank.Money            = bank.Money + moneyContribution.Summa;

            NeedOperation newOperation = new NeedOperation();

            newOperation.Id        = 0;
            newOperation.Sender    = 1;
            newOperation.Recipient = currentResident.Id;
            newOperation.Money     = summaForGetClient;

            int currentTime    = moneyContribution.Duration * 24;
            int currentHours   = currentTime / 60;
            int currentMinutes = currentTime - currentHours * 60;

            newOperation.Time = DateTime.Now.AddHours(currentHours).AddMinutes(currentMinutes);
            _context.NeedOprerations.Add(newOperation);
            _context.SaveChanges();

            return("Ваш вклад составил " + moneyContribution.Summa + " рублей. Через " + moneyContribution.Duration + " дней Вы получите " + Convert.ToString(summaForGetClient) + " рублей.");
        }