Пример #1
0
        public int Update(IdentityBranch branch)
        {
            string commandText = "Update branches set BranchName = @name, BranchCode = @code where Id = @id";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@id", branch.Id);
            parameters.Add("@name", branch.Name);
            parameters.Add("@code", branch.BranchCode);

            return(_database.Execute(commandText, parameters));
        }
Пример #2
0
        /// <summary>
        /// Inserts a new Branch in the branches table
        /// </summary>
        /// <param name="branchName">The branch's name</param>
        /// <returns></returns>
        public int Insert(IdentityBranch branch)
        {
            string commandText = "Insert into branches (Id, BranchName, BranchCode) values (@id, @name, @branchCode)";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@name", branch.Name);
            parameters.Add("@id", branch.Id);
            //parameters.Add("@glAccount", branch.GLAccount);
            parameters.Add("@branchCode", branch.BranchCode);

            return(_database.Execute(commandText, parameters));
        }
Пример #3
0
        /// <summary>
        /// Gets the IdentityBranch given the branch name
        /// </summary>
        /// <param name="branchName"></param>
        /// <returns></returns>
        public IdentityBranch GetBranchByName(string branchName)
        {
            var            branchDetail = GetBranchId(branchName);
            IdentityBranch branch       = null;

            if (branchDetail != null)
            {
                branch = new IdentityBranch(branchDetail["Id"], branchName, branchDetail["BranchCode"]);
            }

            return(branch);
        }
Пример #4
0
        /// <summary>
        /// Returns a list of user's branches
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public IdentityBranch FindByUserId(string userId)
        {
            IdentityBranch branch                  = new IdentityBranch();
            string         commandText             = "Select branches.Id, branches.BranchName from userbranches, branches where userbranches.UserId = @userId and userbranches.BranchId = branches.Id";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@userId", userId);

            var rows = _database.Query(commandText, parameters);

            foreach (var row in rows)
            {
                branch.Id   = row["Id"];
                branch.Name = row["BranchName"];
            }

            return(branch);
        }
Пример #5
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();
            }
        }