Exemple #1
0
        public ActionResult EditBranch(int?id)
        {
            ViewBag.Msg = "";
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Branch branch = branchRepo.GetById((int)id);// = db.Customers.Find(id);

            if (branch == null)
            {
                return(HttpNotFound());
            }
            return(View(branch));
        }
Exemple #2
0
 public Branch GetById(int id)
 {
     try
     {
         return(branchRepository.GetById(id));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
        public ActionResult Create(AddGlActViewModel model)
        {
            ViewBag.GlCategoryId = new SelectList(glCatRepo.GetAll(), "ID", "Name", model.GlCategoryId);
            ViewBag.BranchId     = new SelectList(branchRepo.GetAll(), "ID", "Name", model.BranchId);

            if (ModelState.IsValid)
            {
                try
                {
                    var            category     = glCatRepo.GetById(model.GlCategoryId);
                    var            branch       = branchRepo.GetById(model.BranchId);
                    MainGlCategory mainCategory = (MainGlCategory)((int)category.MainCategory);

                    //if is unique account name
                    if (!gllogic.IsUniqueName(model.AccountName))
                    {
                        ViewBag.Msg = "Account name must be unique";
                        return(View(model));
                    }

                    GlAccount glAccount = new GlAccount()
                    {
                        AccountName = model.AccountName, GlCategory = category, Branch = branch, CodeNumber = gllogic.GenerateGLAccountNumber(mainCategory)
                    };
                    glactRepo.Insert(glAccount);
                    //ViewBag.Msg = "successfully added account";

                    return(RedirectToAction("Create", new { message = "successfully added account" }));
                }
                catch (Exception ex)
                {
                    //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n");
                    return(PartialView("Error"));
                }
            }

            ViewBag.Msg = "Please enter correct data";
            return(View(model));
        }
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new BranchRepository(context);
            int id         = 1;

            // Act
            branch result = repository.GetById(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.id);
        }
        public ActionResult Create(AddNewUserViewModel model)
        {
            ViewBag.Msg      = "";
            ViewBag.Branches = branchRepo.GetAll().AsEnumerable().Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.ID.ToString()
            });

            ViewBag.Roles = roleRepo.GetAll().AsEnumerable().Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.ID.ToString()
            });

            if (ModelState.IsValid)
            {
                //unique username and email
                if (!userLogic.IsUniqueUsername(model.Username))
                {
                    ViewBag.Msg = "Username must be unique";
                    return(View());
                }
                if (!userLogic.IsUniqueEmail(model.Email))
                {
                    ViewBag.Msg = "Email must be unique";
                    return(View());
                }

                string autoGenPassword = utilLogic.GetRandomPassword();
                string hashedPassword  = UserLogic.HashPassword(autoGenPassword);
                User   user            = new Core.Models.User {
                    FirstName = model.FirstName, LastName = model.LastName, Username = model.Username, PasswordHash = hashedPassword, Email = model.Email, PhoneNumber = model.PhoneNumber, Role = roleRepo.GetById(model.RoleId), Branch = branchRepo.GetById(model.BranchId)
                };

                userRepo.Insert(user);

                userLogic.SendPasswordToUser(model.LastName + " " + model.FirstName, model.Email, model.Username, autoGenPassword);

                return(RedirectToAction("Create", new { message = "User added" }));
            }
            ViewBag.Msg = "Please enter a valid name";
            return(View());
        }
Exemple #6
0
        //get id

        public Branch GetById(int id)
        {
            return(_branchReository.GetById(id));
        }
Exemple #7
0
        public ActionResult Create(AddNewUserViewModel model)
        {
            ViewBag.Msg      = "";
            ViewBag.Branches = branchRepo.GetAll().AsEnumerable().Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.ID.ToString()
            });

            ViewBag.Roles = roleRepo.GetAll().AsEnumerable().Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.ID.ToString()
            });

            if (ModelState.IsValid)
            {
                //unique username and email that has been been confirmed by any user.
                if (!userLogic.IsUniqueUsername(model.Username))
                {
                    ViewBag.Msg = "Username must be unique";
                    return(View());
                }
                if (!userLogic.IsUniqueEmail(model.Email))
                {
                    // edit, email musn't be unique
                    // only if email has been confirmed by another user.
                    // if email has been confirmed by any user.
                    // check if anyone with email has confirmed it.
                    if (userLogic.IsEmailConfirmed(model.Email))
                    {
                        ViewBag.Msg = "Email must be unique";
                        return(View());
                    }
                }

                string autoGenPassword  = utilLogic.GetRandomPassword();
                string hashedPassword   = UserLogic.HashPassword(autoGenPassword);
                string verificationCode = Guid.NewGuid().ToString();

                User user = new Core.Models.User {
                    TokenExpiryDate = DateTime.Now.AddMinutes(tokenExpiryMinutes), VerificationCode = verificationCode, FirstName = model.FirstName, LastName = model.LastName, Username = model.Username, PasswordHash = hashedPassword, Email = model.Email, PhoneNumber = model.PhoneNumber, EmailConfirmed = false, Role = roleRepo.GetById(model.RoleId), Branch = branchRepo.GetById(model.BranchId)
                };

                userRepo.Insert(user);

                // send email confirmation
                var callbackUrl = Url.Action("ConfirmEmail", "UserManager", new { userId = user.ID, code = verificationCode }, protocol: Request.Url.Scheme);

                try
                {
                    userLogic.SendEmailConfirmationTokenToUser(callbackUrl, model.Email);
                    userLogic.SendPasswordToUser(model.LastName + " " + model.FirstName, model.Email, model.Username, autoGenPassword);
                }
                catch (Exception)
                {
                    return(RedirectToAction("Create", new { message = "[User added : " + autoGenPassword + "][ CallbackUrl : " + callbackUrl + " ] .Send Mail Failed." }));
                }

                // tell them confirmation link has been sent to user mail
                // you dont need to show the user pass and call back since mail send was successful.
                return(RedirectToAction("Create", new { message = "[User added : " + model.Username + "][Confirmation link and password has been sent to user mail]" }));
            }
            ViewBag.Msg = "Please enter a valid name";
            return(View());
        }
Exemple #8
0
 public Branch GetBranch(int Id)
 {
     return(BranchRepository.GetById(Id));
 }
Exemple #9
0
        public ActionResult AddAccount(CustomerAccount model, string BranchId, string InterestRate, string NumberOfYears)
        {
            ViewBag.BranchId = new SelectList(branchRepo.GetAll(), "ID", "Name", model.BranchId);

            if (ModelState.IsValid)
            {
                try
                {
                    var customer = custRepo.GetById(model.CustId);
                    if (customer == null)
                    {
                        ViewBag.Msg = "Incorrect customer Id";
                        return(View());
                    }

                    var act = new CustomerAccount();
                    act.AccountName   = model.AccountName;
                    act.AccountType   = model.AccountType;
                    act.Customer      = customer;
                    act.AccountNumber = logic.GenerateCustomerAccountNumber(model.AccountType, customer.ID);
                    act.DateCreated   = DateTime.Now;

                    int bid = 0;
                    if (!int.TryParse(BranchId, out bid))
                    {
                        ViewBag.Msg = "Branch cannot be null";
                        return(View());
                    }
                    var branch = branchRepo.GetById(bid); //db.Branches.Where(b => b.BranchId == bid).SingleOrDefault();
                    if (branch == null)
                    {
                        ViewBag.Msg = "Branch cannot be null";
                        return(View());
                    }
                    act.Branch = branch;

                    if (!(model.AccountType == AccountType.Loan))   //for savings and current
                    {
                        actRepo.Insert(act);
                        ViewBag.Msg = "Account successfully created";
                        return(RedirectToAction("Index"));
                    }
                    else   //   FOR LOAN ACCOUNTS
                    {
                        if (model.LoanAmount < 1000 || model.LoanAmount >= decimal.MaxValue)
                        {
                            ViewBag.Msg = "Loan amount must be between #1,000 and a maximum reasonable amount";
                            return(View(model));
                        }
                        act.LoanAmount  = model.LoanAmount;
                        act.TermsOfLoan = model.TermsOfLoan;
                        var servAct = actRepo.GetByAccountNumber(model.ServicingAccountId);
                        if (servAct == null || servAct.AccountType == AccountType.Loan)
                        {
                            ViewBag.Msg = "Invalid account selected";
                            return(View(model));
                        }
                        act.ServicingAccount = servAct;

                        double interestRate = 0;
                        double nyears       = 0;

                        if (!(double.TryParse(InterestRate, out interestRate) && double.TryParse(NumberOfYears, out nyears)))
                        {
                            ViewBag.Msg = "Number of years or Interest rate value is incorrect";
                            return(View(model));
                        }
                        act.LoanInterestRatePerMonth = Convert.ToDecimal(InterestRate);
                        if (!(interestRate > 0 && nyears > 0 && model.LoanAmount > 0))
                        {
                            ViewBag.Msg = "Please enter positive values";
                            return(View(model));
                        }
                        switch (act.TermsOfLoan)
                        {
                        case TermsOfLoan.Fixed:
                            logic.ComputeFixedRepayment(act, nyears, interestRate);
                            break;

                        case TermsOfLoan.Reducing:
                            logic.ComputeReducingRepayment(act, nyears, interestRate);
                            break;

                        default:
                            break;
                        }

                        busLogic.DebitCustomerAccount(act, (decimal)act.LoanAmount);                   //debit the loan act (An Asset to the Bank)
                        busLogic.CreditCustomerAccount(act.ServicingAccount, (decimal)act.LoanAmount); //credit the loan's servicing account
                        new FinancialReportLogic().CreateTransaction(act, act.LoanAmount, TransactionType.Debit);
                        new FinancialReportLogic().CreateTransaction(act.ServicingAccount, act.LoanAmount, TransactionType.Credit);

                        actRepo.Update(act.ServicingAccount);
                        actRepo.Insert(act);
                        ViewBag.Msg = "Account successfully created";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception)
                {
                    //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n");
                    return(View(model));
                }
            }//end if ModelState
            else
            {
                ViewBag.Msg = "Please enter correct data";
                return(View(model));
            }

            // return View(model);
        }// end addAccount