示例#1
0
        //it makes it eassier for the website to just pass theroleId and the username instead of passing a whole role dtetails and a whole user details.
        public void AllocateRole(int roleId, String username)
        {
            RolesRepository rr = new RolesRepository();
            Role            r  = rr.GetRoleById(roleId);//getting the role

            UsersRepository ur = new UsersRepository();

            ur.Entity = rr.Entity;             //we put the repositries  in the same locations so that we can call multiple repositories
                                               //it is important to do this line before you use the second method (getUSer)

            Client u = ur.GetClient(username); //getting the user

            if (rr.IsUserInRole(username, roleId) == false)
            {
                rr.AllocateRole(r, u);
            }
            else
            {
                throw new Exception("Role has been already allocated to the selected user");
            }
        }
示例#2
0
        public void RegisterUser(Client c)
        {
            UsersRepository ur = new UsersRepository();
            RolesRepository rr = new RolesRepository();

            ur.Entity = rr.Entity;

            if (ur.DoesUsernameExist(c.Username))//do or email aswell (do a method like the does username exists in the repository.. put the email verification in an else if statement
            {
                throw new Exception("Username already exists. Please input a different one");
            }
            else if (ur.DoesEmailExist(c.Email))
            {
                throw new Exception("Email already exists. Please input a different one");
            }
            else
            {
                c.UserType = 2;
                ur.AddClient(c);
                Role defaultRole = rr.GetRoleById(2); //getting the user role from the database
                rr.AllocateRole(defaultRole, c);      //allocating the role to the user
            }
        }