Пример #1
0
        public async Task <JsonResult> RegisterNewBranch(BranchModel model)
        {
            if (ModelState.IsValid)
            {
                var branchExist = BranchManager.BranchExists(model.BranchName);
                if (branchExist)
                {
                    throw new Exception("Branch already exist");
                }

                var branchCodeExist = BranchManager.BranchExists(model.BranchCode);
                if (branchCodeExist)
                {
                    throw new Exception("Branch Code already exist");
                }

                var branch = new IdentityBranch(model.BranchName, model.BranchCode);
                var result = await BranchManager.CreateAsync(branch);

                if (result)
                {
                    return(Json(new { code = "00", message = "Sucessfull" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    throw new Exception("Branch creation failed");
                }
            }
            throw new Exception("Invalid Data Submitted");
        }
Пример #2
0
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager   = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager   = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            var branchManager = new BranchManager <IdentityBranch>(new BranchStore <IdentityBranch>(context));
            var bankManager   = new BankManager <IdentityBank>(new BankStore <IdentityBank>(context));

            var user = new ApplicationUser();

            //branchManager.CreateUploadStatus();
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new AspNet.Identity.MySQL.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "password77$";

                var chkUser = UserManager.Create(user, userPWD);

                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("BranchOperator"))
            {
                var role = new AspNet.Identity.MySQL.IdentityRole();
                role.Name = "BranchOperator";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("BranchVerifier"))
            {
                var role = new AspNet.Identity.MySQL.IdentityRole();
                role.Name = "BranchVerifier";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("HeadOfficeOperator"))
            {
                var role = new AspNet.Identity.MySQL.IdentityRole();
                role.Name = "HeadOfficeOperator";
                roleManager.Create(role);
            }

            if (!branchManager.BranchExists("Head Office"))
            {
                user = UserManager.FindByName("administrator");

                var bank = new AspNet.Identity.MySQL.IdentityBank();
                bank.Name = ConfigurationManager.AppSettings["OwnerBankName"];
                bankManager.Create(bank);

                var branch = new AspNet.Identity.MySQL.IdentityBranch();
                branch.Name       = "Head Office";
                branch.BranchCode = "HeadOffice";
                //branch.GLAccount = ConfigurationManager.AppSettings["DefaultGLAccount"];
                branchManager.Create(branch);
                branchManager.AddUserToBranch(user.Id, branch.Id);
                //branchManager.CreateUploadStatus();
            }
        }