コード例 #1
0
        public ActionResult Update(FormCollection form)
        {
            string button = form["Update"];

            int id = int.Parse(form["Id"]);
            Client client = _clientsRepository.Objects.SingleOrDefault(c => c.Id == id);

            if (client == null)
            {
                return View();
            }

            if (button == "CreditsMoney")
            {
                List<Credit> credits = client.GetObjects(_creditsRepository);

                if (client.AccountType == "Usual" || credits.Count == 0)
                {
                    ErrorNotifier notifier = new ErrorNotifier
                    {
                        Source = "updateCredits"
                    };
                    notifier.SetDescription();
                    return RedirectToAction("Error", "Admin", notifier);
                }

                MoneyOperations moneyOperation = new MoneyOperations(client);
                moneyOperation.UpdateClientCredits(credits);

                foreach (Credit credit in credits)
                {
                    Operation operation = new Operation(DateTime.Now, client.Id,
                        string.Format("Update credit for {0}", credit.Type),
                        String.Empty, String.Empty, client.State.BankId, String.Empty, credit.Money*credit.Procents/100);
                    _operationsRepository.SaveObject(operation);
                }
                _clientsRepository.SaveObject(client);

            }

            if (button == "BankMoney")
            {
                if (client.State.BankMoney == 0)
                {
                    ErrorNotifier notifier = new ErrorNotifier
                    {
                        Source = "updateBank"
                    };
                    notifier.SetDescription();
                    return RedirectToAction("Error", "Admin", notifier);
                }

                int procents = client.State.BankMoney * client.State.BankProcents / 100;
                MoneyOperations moneyOperation = new MoneyOperations(client);
                moneyOperation.UpdateClientBankMoney();

                Operation operation = new Operation(DateTime.Now, client.Id,
                    string.Format("Update bank money"),
                    String.Empty, String.Empty, client.State.BankId, String.Empty, procents);
                _operationsRepository.SaveObject(operation);

                _clientsRepository.SaveObject(client);
            }
            return RedirectToAction("OperationsLog", "Admin");
        }
コード例 #2
0
 public ActionResult Error(ErrorNotifier notifier)
 {
     return View(notifier);
 }