Exemplo n.º 1
0
 public bool IsLoginNameExist(string loginName)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         return(db.SYSUsers.Where(o => o.LoginName.Equals(loginName)).Any());
     }
 }
Exemplo n.º 2
0
 public void DeleteUser(int userID)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 var SUR = db.SYSUserRoles.Where(o => o.SYSUserID == userID);
                 if (SUR.Any())
                 {
                     db.SYSUserRoles.Remove(SUR.FirstOrDefault());
                     db.SaveChanges();
                 }
                 var SUP = db.SYSUserProfiles.Where(o => o.SYSUserID == userID);
                 if (SUP.Any())
                 {
                     db.SYSUserProfiles.Remove(SUP.FirstOrDefault());
                     db.SaveChanges();
                 }
                 var SU = db.SYSUsers.Where(o => o.SYSUserID == userID);
                 if (SU.Any())
                 {
                     db.SYSUsers.Remove(SU.FirstOrDefault());
                     db.SaveChanges();
                 }
                 dbContextTransaction.Commit();
             }
             catch
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }
Exemplo n.º 3
0
        public UserProfileView GetUserProfile(int userID)
        {
            UserProfileView UPV = new UserProfileView();

            using (DemoDBEntities1 db = new DemoDBEntities1())
            {
                var user = db.SYSUsers.Find(userID);
                if (user != null)
                {
                    UPV.SYSUserID = user.SYSUserID;
                    UPV.LoginName = user.LoginName;
                    UPV.Password  = user.PasswordEncryptedText;
                    var SUP = db.SYSUserProfiles.Find(userID);
                    if (SUP != null)
                    {
                        UPV.FirstName = SUP.FirstName;
                        UPV.LastName  = SUP.LastName;
                        UPV.Gender    = SUP.Gender;
                    }

                    var SUR = db.SYSUserRoles.Find(userID);
                    if (SUR != null)
                    {
                        UPV.LOOKUPRoleID = SUR.LOOKUPRoleID;
                        UPV.RoleName     = SUR.LOOKUPRole.RoleName;
                        UPV.IsRoleActive = SUR.IsActive;
                    }
                }
            }
            return(UPV);
        }
Exemplo n.º 4
0
        public UserDataView GetUserDataView(string loginName)
        {
            UserDataView               UDV = new UserDataView();
            List <UserProfileView>     profiles = GetAllUserProfiles();
            List <LOOKUPAvailableRole> roles = GetAllRoles();
            int?   userAssignedRoleID = 0, userID = 0;
            string userGender = string.Empty;

            userID = GetUserID(loginName);
            using (DemoDBEntities1 db = new DemoDBEntities1())
            {
                userAssignedRoleID = db.SYSUserRoles.Where(o => o.SYSUserID == userID)?.FirstOrDefault().LOOKUPRoleID;
                userGender         = db.SYSUserProfiles.Where(o => o.SYSUserID == userID)?.FirstOrDefault().Gender;
            }
            List <Gender> genders = new List <Gender>();

            genders.Add(new Gender {
                Text = "Male", Value = "M"
            });
            genders.Add(new Gender {
                Text = "Female", Value = "F"
            });
            UDV.UserProfile = profiles;
            UDV.UserRoles   = new UserRoles {
                SelectedRoleID = userAssignedRoleID, UserRoleList = roles
            };
            UDV.UserGender = new UserGender {
                SelectedGender = userGender, Gender = genders
            };
            return(UDV);
        }
Exemplo n.º 5
0
        public List <UserProfileView> GetAllUserProfiles()
        {
            List <UserProfileView> profiles = new List <UserProfileView>();

            using (DemoDBEntities1 db = new DemoDBEntities1())
            {
                UserProfileView UPV;
                var             users = db.SYSUsers.ToList();
                foreach (SYSUser u in db.SYSUsers)
                {
                    UPV           = new UserProfileView();
                    UPV.SYSUserID = u.SYSUserID;
                    UPV.LoginName = u.LoginName;
                    UPV.Password  = u.PasswordEncryptedText;
                    var SUP = db.SYSUserProfiles.Find(u.SYSUserID);
                    if (SUP != null)
                    {
                        UPV.FirstName = SUP.FirstName;
                        UPV.LastName  = SUP.LastName;
                        UPV.Gender    = SUP.Gender;
                    }
                    var SUR = db.SYSUserRoles.Where(o => o.SYSUserID.Equals(u.SYSUserID));
                    if (SUR.Any())
                    {
                        var userRole = SUR.FirstOrDefault();
                        UPV.LOOKUPRoleID = userRole.LOOKUPRoleID;
                        UPV.RoleName     = userRole.LOOKUPRole.RoleName;
                        UPV.IsRoleActive = userRole.IsActive;
                    }
                    profiles.Add(UPV);
                }
            }
            return(profiles);
        }
        public string[] GetAllRole()
        {
            string[] roless = new string[10];

            using (DemoDBEntities1 db = new DemoDBEntities1())
            {
                var roles = db.LOOKUPRoles.Select(o => new LOOKUPAvailableRole
                {
                    LOOKUPRoleID    = o.LOOKUPRoleID,
                    RoleName        = o.RoleName,
                    RoleDescription = o.RoleDescription
                }).ToList();
                int i = roles.Count();
                int j = 0;
                foreach (LOOKUPAvailableRole role in roles)
                {
                    roless[j] = role.RoleName;
                    j++;
                    if (j > roles.Count - 1)
                    {
                        return(roless);
                    }
                }

                return(null);
            }
        }
Exemplo n.º 7
0
 public List <LOOKUPAvailableRole> GetAllRoles()
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         var roles = db.LOOKUPRoles.Select(o => new LOOKUPAvailableRole {
             LOOKUPRoleID = o.LOOKUPRoleID, RoleName = o.RoleName, RoleDescription = o.RoleDescription
         }).ToList();
         return(roles);
     }
 }
Exemplo n.º 8
0
 public int GetUserID(string loginName)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         var user = db.SYSUsers.Where(o => o.LoginName.Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().SYSUserID);
         }
     }
     return(0);
 }
Exemplo n.º 9
0
 public string GetUserPassword(string loginName)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1()) {
         var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().PasswordEncryptedText);
         }
         else
         {
             return(string.Empty);
         }
     }
 }
Exemplo n.º 10
0
        public void AddUserAccount(UserSignUpView user)
        {
            using (DemoDBEntities1 db = new DemoDBEntities1())
            {
                SYSUser SU = new SYSUser();
                SU.LoginName             = user.LoginName;
                SU.PasswordEncryptedText = user.Password;
                SU.RowCreatedSYSUserID   = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SU.RowModifiedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1;;
                SU.RowCreatedDateTime    = DateTime.Now;
                SU.RowMOdifiedDateTime   = DateTime.Now;

                db.SYSUsers.Add(SU);
                db.SaveChanges();

                SYSUserProfile SUP = new SYSUserProfile();
                SUP.SYSUserID            = SU.SYSUserID;
                SUP.FirstName            = user.FirstName;
                SUP.LastName             = user.LastName;
                SUP.Gender               = user.Gender;
                SUP.RowCreatedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowCreatedDateTime   = DateTime.Now;
                SUP.RowModifiedDateTime  = DateTime.Now;

                db.SYSUserProfiles.Add(SUP);
                db.SaveChanges();


                if (user.LOOKUPRoleID > 0)
                {
                    SYSUserRole SUR = new SYSUserRole();
                    SUR.LOOKUPRoleID        = user.LOOKUPRoleID;
                    SUR.SYSUserID           = user.SYSUserID;
                    SUR.IsActive            = true;
                    SUR.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID :
                                              1;
                    SUR.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID :
                                               1;
                    SUR.RowCreatedDateTime  = DateTime.Now;
                    SUR.RowModifiedDateTime = DateTime.Now;

                    db.SYSUserRoles.Add(SUR);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 11
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool authorize = false;

            using (DemoDBEntities1 db = new DemoDBEntities1()) {
                UserManager UM = new UserManager();
                foreach (var roles in userAssignedRoles)
                {
                    authorize = UM.IsUserInRole(httpContext.User.Identity.Name, roles);
                    if (authorize)
                    {
                        return(authorize);
                    }
                }
            }
            return(authorize);
        }
Exemplo n.º 12
0
 public bool IsUserInRole(string loginName, string roleName)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         SYSUser SU = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName))?.FirstOrDefault();
         if (SU != null)
         {
             var roles = from q in db.SYSUserRoles
                         join r in db.LOOKUPRoles on q.LOOKUPRoleID equals r.LOOKUPRoleID
                         where r.RoleName.Equals(roleName) && q.SYSUserID.Equals(SU.SYSUserID)
                         select r.RoleName;
             if (roles != null)
             {
                 return(roles.Any());
             }
         }
         return(false);
     }
 }
Exemplo n.º 13
0
 public void UpdateUserAccount(UserProfileView user)
 {
     using (DemoDBEntities1 db = new DemoDBEntities1())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 SYSUser SU = db.SYSUsers.Find(user.SYSUserID);
                 SU.LoginName             = user.LoginName;
                 SU.PasswordEncryptedText = user.Password;
                 SU.RowCreatedSYSUserID   = user.SYSUserID;
                 SU.RowModifiedSYSUserID  = user.SYSUserID;
                 SU.RowCreatedDateTime    = DateTime.Now;
                 SU.RowMOdifiedDateTime   = DateTime.Now;
                 db.SaveChanges();
                 var userProfile = db.SYSUserProfiles.Where(o => o.SYSUserID == user.SYSUserID);
                 if (userProfile.Any())
                 {
                     SYSUserProfile SUP = userProfile.FirstOrDefault();
                     SUP.SYSUserID            = SU.SYSUserID;
                     SUP.FirstName            = user.FirstName;
                     SUP.LastName             = user.LastName;
                     SUP.Gender               = user.Gender;
                     SUP.RowCreatedSYSUserID  = user.SYSUserID;
                     SUP.RowModifiedSYSUserID = user.SYSUserID;
                     SUP.RowCreatedDateTime   = DateTime.Now;
                     SUP.RowModifiedDateTime  = DateTime.Now;
                     db.SaveChanges();
                 }
                 if (user.LOOKUPRoleID > 0)
                 {
                     var         userRole = db.SYSUserRoles.Where(o => o.SYSUserID == user.SYSUserID);
                     SYSUserRole SUR      = null;
                     if (userRole.Any())
                     {
                         SUR = userRole.FirstOrDefault();
                         SUR.LOOKUPRoleID         = user.LOOKUPRoleID;
                         SUR.SYSUserID            = user.SYSUserID;
                         SUR.IsActive             = true;
                         SUR.RowCreatedSYSUserID  = user.SYSUserID;
                         SUR.RowModifiedSYSUserID = user.SYSUserID;
                         SUR.RowCreatedDateTime   = DateTime.Now;
                         SUR.RowModifiedDateTime  = DateTime.Now;
                     }
                     else
                     {
                         SUR = new SYSUserRole();
                         SUR.LOOKUPRoleID         = user.LOOKUPRoleID;
                         SUR.SYSUserID            = user.SYSUserID;
                         SUR.IsActive             = true;
                         SUR.RowCreatedSYSUserID  = user.SYSUserID;
                         SUR.RowModifiedSYSUserID = user.SYSUserID;
                         SUR.RowCreatedDateTime   = DateTime.Now;
                         SUR.RowModifiedDateTime  = DateTime.Now;
                         db.SYSUserRoles.Add(SUR);
                     }
                     db.SaveChanges();
                 }
                 dbContextTransaction.Commit();
             }
             catch
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }