コード例 #1
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
 public bool IsLoginNameExist(string loginName)
 {
     using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
     {
         return(db.SYSUsers.Where(o => o.LoginName.Equals(loginName)).Any());
     }
 }
コード例 #2
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
 public int GetUserID(string loginName)
 {
     using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
     {
         var user = db.SYSUsers.Where(o => o.LoginName.Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().SYSUserID);
         }
     }
     return(0);
 }
コード例 #3
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public List <LOOKUPAvailableRole> GetAllRoles()
        {
            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                var roles = db.LOOKUPRoles.Select(o => new LOOKUPAvailableRole
                {
                    LOOKUPRoleID    = o.LOOKUPRoleID,
                    RoleName        = o.RoleName,
                    RoleDescription = o.RoleDescription
                }).ToList();

                return(roles);
            }
        }
コード例 #4
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public void AddUserAccount(UserSignUpView user)
        {
            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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;
                SUP.DateOfBirth          = user.DateOfBirth;
                SUP.BronzeBalance        = SUP.BronzeBalance + user.BronzeBalance;
                SUP.SilverBalance        = SUP.SilverBalance + user.SilverBalance;
                SUP.GoldBalance          = SUP.GoldBalance + user.GoldBalance;
                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();
                }
            }
        }
コード例 #5
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
 public string GetUserPassword(string loginName)
 {
     using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
     {
         var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().PasswordEncryptedText);
         }
         else
         {
             return(string.Empty);
         }
     }
 }
コード例 #6
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool authorize = false;

            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                UserManager UM = new UserManager();
                foreach (var roles in userAssignedRoles)
                {
                    authorize = UM.IsUserInRole(httpContext.User.Identity.Name, roles);
                    if (authorize)
                    {
                        return(authorize);
                    }
                }
            }
            return(authorize);
        }
コード例 #7
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public List <UserProfileView> GetAllUserProfiles()
        {
            List <UserProfileView> profiles = new List <UserProfileView>();

            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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;
                        UPV.DateOfBirth   = SUP.DateOfBirth;
                        UPV.BronzeBalance = SUP.BronzeBalance;
                        UPV.SilverBalance = SUP.SilverBalance;
                        UPV.GoldBalance   = SUP.GoldBalance;
                    }

                    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);
        }
コード例 #8
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        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 (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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);
        }
コード例 #9
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public bool IsUserInRole(string loginName, string roleName)
        {
            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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);
            }
        }
コード例 #10
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public void DeleteUser(int userID)
        {
            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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();
                    }
                }
            }
        }
コード例 #11
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public UserProfileView GetUserProfile(int userID)
        {
            UserProfileView UPV = new UserProfileView();

            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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;
                        UPV.DateOfBirth   = SUP.DateOfBirth;
                        UPV.BronzeBalance = SUP.BronzeBalance;
                        UPV.SilverBalance = SUP.SilverBalance;
                        UPV.GoldBalance   = SUP.GoldBalance;
                    }

                    var SUR = db.SYSUserRoles.Find(userID);
                    if (SUR != null)
                    {
                        UPV.LOOKUPRoleID = SUR.LOOKUPRoleID;
                        UPV.RoleName     = SUR.LOOKUPRole.RoleName;
                        UPV.IsRoleActive = SUR.IsActive;
                    }
                }
            }
            return(UPV);
        }
コード例 #12
0
ファイル: UserManager.cs プロジェクト: vkozmina/MVCtest
        public void UpdateUserAccount(UserProfileView user)
        {
            using (DB_A11531_francistestEntities db = new DB_A11531_francistestEntities())
            {
                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;
                            SUP.DateOfBirth          = user.DateOfBirth;
                            if (SUP.BronzeBalance == null)
                            {
                                SUP.BronzeBalance = 0;
                            }
                            if (SUP.SilverBalance == null)
                            {
                                SUP.SilverBalance = 0;
                            }
                            if (SUP.GoldBalance == null)
                            {
                                SUP.GoldBalance = 0;
                            }
                            SUP.BronzeBalance = user.BronzeBalance; // + SUP.BronzeBalance
                            SUP.SilverBalance = user.SilverBalance; // + SUP.SilverBalance
                            SUP.GoldBalance   = user.GoldBalance;   // + SUP.GoldBalance
                            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();
                    }
                }
            }
        }