Beispiel #1
0
        public static List <Object> RolesObject()
        {
            try
            {
                List <Object> returnedRoles = new List <Object>();

                List <Role> roles = RoleDL.RetrieveRoles();

                foreach (Role role in roles)
                {
                    List <long> functions = new List <long>();

                    foreach (RoleFunction roleFunction in role.RoleFunctions)
                    {
                        functions.Add(roleFunction.FunctionID);
                    }

                    Object roleObj = new
                    {
                        ID        = role.ID,
                        Name      = role.Name,
                        Functions = functions
                    };

                    returnedRoles.Add(roleObj);
                }

                return(returnedRoles);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
 public static Role RetrieveRoleByID(long?roleID)
 {
     try
     {
         return(RoleDL.RetrieveRoleByID(roleID));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
 public static bool Update(Role role)
 {
     try
     {
         return(RoleDL.Update(role));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
 public static bool Save(Role role, out string message)
 {
     try
     {
         if (RoleDL.RoleExists(role))
         {
             message = string.Format("Role with name: {0} exists already", role.Name);
             return(false);
         }
         else
         {
             message = string.Empty;
             return(RoleDL.Save(role));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
        public static dynamic AuthenticateUser(string username, string password)
        {
            try
            {
                User user = UserDL.AuthenticateUser(username, password);
                if (user != null)
                {
                    dynamic userObj = new ExpandoObject();

                    List <dynamic> userFunctions = new List <dynamic>();

                    Role userRole = RoleDL.RetrieveRoleByID(user.UserRole);
                    foreach (RoleFunction roleFunction in userRole.RoleFunctions)
                    {
                        dynamic function = new
                        {
                            Name     = roleFunction.Function.Name,
                            PageLink = roleFunction.Function.PageLink
                        };

                        userFunctions.Add(function);
                    }

                    userObj.ID       = user.ID;
                    userObj.Username = user.Username;
                    userObj.Role     = userRole.Name;
                    userObj.Function = userFunctions;
                    userObj.BranchID = BranchDL.RetrieveBranchByID(user.UserBranch).ID;

                    return(userObj);
                }
                return(user);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }