Exemplo n.º 1
0
        public ActionResult NewAccount(NewAccountModel model)
        {
            EventLogHandler Logger      = new EventLogHandler();
            var             sessionUser = Session["Username"] as string;

            string Normal = "";

            if (model.AccountType == "Asset" || model.AccountType == "Liability")
            {
                Normal = "Debit";
            }
            else
            {
                Normal = "Credit";
            }

            if (ModelState.IsValid)
            {
                using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString()))
                {
                    string sql = $"Insert into dbo.ChartOfAccounts (AccountNumber, AccountName, " +
                                 "AccountType, NormalSide, OriginalBalance, CurrentBalance, AccountDescription, CreatedBy, Active, DateCreated)" +
                                 "values(@AccountNumber, @AccountName, @AccountType,@NormalSide,@OriginalBalance," +
                                 "@CurrentBalance,@AccountDescription,@CreatedBy,@Active,@Date)";
                    db.Execute(sql, new
                    {
                        AccountNumber      = model.AccountNumber,
                        AccountName        = model.AccountName,
                        AccountType        = model.AccountType,
                        NormalSide         = Normal,
                        OriginalBalance    = model.OriginalBalance,
                        CurrentBalance     = 0,
                        AccountDescription = model.AccountDescription,
                        CreatedBy          = sessionUser,
                        Active             = model.Active,
                        Date = DateTime.Now
                    });
                }


                TempData["Message"] = "A new account was successfully created!";
                Logger.LogAdminCreateAccount(sessionUser, model.AccountName);

                return(RedirectToAction("ChartOfAccounts"));
            }

            return(View("NewAccount", new NewAccountModel()));
        }