예제 #1
0
        public static bool LoginUser(string userName, string password)
        {
            bool IsValidLogin = false;

            using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
            {
                if (IsValidUserName(userName))
                {
                    user loggedInUser = (from users in mtiUserRolesEntityDataModel.users
                                         where (users.email != null) && (users.email.Trim().ToLower() == userName.Trim().ToLower())
                                         select users).FirstOrDefault();

                    if((loggedInUser != null) && (!string.IsNullOrEmpty(loggedInUser.password)) &&
                        (!string.IsNullOrWhiteSpace(loggedInUser.password)) &&
                        (loggedInUser.password == EncryptDecryptPassword(password.ToString())))
                    {
                        IsValidLogin = true;
                        SessionData.Current.LoggedInUser.LoggedInUserId = loggedInUser.userId;
                        SessionData.Current.LoggedInUser.UserName = loggedInUser.email;
                    }
                }
            }

            return IsValidLogin;
        }
        public user SaveUser(user userToSave)
        {
            using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
            {
                userToSave = _userAdministrationRepository.SaveUser(userToSave, mtiUserRolesEntityDataModel);
            }

            return userToSave;
        }
        public user GetUserFromEmail(string eMailAddress)
        {
            user userWithEmail = null;

            using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
            {
                userWithEmail = _userAdministrationRepository.GetUserFromEmail(eMailAddress, mtiUserRolesEntityDataModel);
            }

            return userWithEmail;
        }
        public user GetUserFromEmail(string eMailAddress, MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel)
        {
            user userFromEmail = null;

            if ((!String.IsNullOrEmpty(eMailAddress)) && (!String.IsNullOrWhiteSpace(eMailAddress)))
            {
                userFromEmail = (from user in mtiUserRolesEntityDataModel.users
                                where ((user.email != null) && (user.email.Trim().ToUpper() == eMailAddress.Trim().ToUpper()))
                                select user).FirstOrDefault();
            }

            return userFromEmail;
        }
        public void SaveUserRoles(Guid userId, List<BoundUserRole> boundUserRolesListForSelectedUser)
        {
            using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
            {
                _userAdministrationRepository.DeleteAllRolesForUser(userId, mtiUserRolesEntityDataModel);

                foreach(BoundUserRole boundUserRole in boundUserRolesListForSelectedUser)
                {
                    if (boundUserRole.UserIsInRole == true)
                    {
                        _userAdministrationRepository.AddUserRole(userId, boundUserRole.RoleId, mtiUserRolesEntityDataModel);
                    }
                }
            }
        }
        public user SaveUser(user userToSave, MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel)
        {
            user existingUser = null;

            try
            {
                if (userToSave.userId != Guid.Empty)
                {
                    existingUser = (from user in mtiUserRolesEntityDataModel.users
                                    where user.userId == userToSave.userId
                                    select user).SingleOrDefault();
                }

                if (existingUser == null)
                {
                    userToSave.createDate = DateTime.Now;
                    userToSave.createdBy = SessionData.Current.LoggedInUser.LoggedInUserId;
                    mtiUserRolesEntityDataModel.users.Add(userToSave);
                }
                else
                {
                    existingUser.email = userToSave.email;
                    existingUser.firstname = userToSave.firstname;
                    existingUser.lastname = userToSave.lastname;
                    existingUser.password = userToSave.password;
                    existingUser.createDate = DateTime.Now;
                    existingUser.createdBy = SessionData.Current.LoggedInUser.LoggedInUserId;
                }

                mtiUserRolesEntityDataModel.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }

            return GetUserFromEmail(userToSave.email, mtiUserRolesEntityDataModel);
        }
        public void DeleteAllRolesForUser(Guid userId, MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel)
        {
            if (userId != Guid.Empty)
            {
                var existingUserRolesForUser = (from userrolesforuser in mtiUserRolesEntityDataModel.userroles
                                                where userrolesforuser.userId == userId
                                                select userrolesforuser);

                foreach(userrole existingUserRole in existingUserRolesForUser)
                {
                    mtiUserRolesEntityDataModel.userroles.Remove(existingUserRole);
                }

                mtiUserRolesEntityDataModel.SaveChanges();
            }
        }
예제 #8
0
        public static bool IsValidUserName(string userName)
        {
            bool isValidUserName = false;

            using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
            {
                var user = (from users in mtiUserRolesEntityDataModel.users
                                            where (users.email != null) && (users.email.Trim().ToLower() == userName.Trim().ToLower())
                                            select users).FirstOrDefault();

                if (user != null)
                {
                    isValidUserName = true;
                }
            }

            return isValidUserName;
        }
        public userrole AddUserRole(Guid userId, Guid roleId, MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel)
        {
            userrole addedUserRole = null;

            if ((userId != Guid.Empty) && (roleId != Guid.Empty))
            {
                addedUserRole = new userrole();
                addedUserRole.userId = userId;
                addedUserRole.roleId = roleId;
                addedUserRole.createDate = DateTime.Now;
                addedUserRole.createdBy = SessionData.Current.LoggedInUser.LoggedInUserId;

                mtiUserRolesEntityDataModel.userroles.Add(addedUserRole);

                mtiUserRolesEntityDataModel.SaveChanges();
            }

            return addedUserRole;
        }
            private List<Permissions> GetLoggedInUsersPermissions()
            {
                List<Permissions> userPermissions = new List<Permissions>();

                if (_loggedInUserId != Guid.Empty)
                {
                    using (MTIUserRolesEntityDataModel mtiUserRolesEntityDataModel = new MTIUserRolesEntityDataModel())
                    {
                        List<string> loggedInUsersRoles = (from rolesforuser in mtiUserRolesEntityDataModel.userroles
                                                           join rolesofuser in mtiUserRolesEntityDataModel.roles on rolesforuser.roleId equals rolesofuser.roleId
                                                           where rolesforuser.userId == _loggedInUserId
                                                           select rolesofuser.roleName).ToList();

                        foreach(string userRole in loggedInUsersRoles)
                        {
                            if(userRole == "Admin")
                            {
                                userPermissions.Add(Permissions.Admin);
                            }
                            else if(userRole == "Report")
                            {
                                userPermissions.Add(Permissions.ViewReports);
                            }
                            else if (userRole == "DM View")
                            {
                                userPermissions.Add(Permissions.ViewDataManagement);
                            }
                            else if (userRole == "DM Edit")
                            {
                                userPermissions.Add(Permissions.EditDataManagement);
                            }
                            else if (userRole == "RawVisit Edit")
                            {
                                userPermissions.Add(Permissions.EditVisit);
                            }
                        }
                    }
                }

                return userPermissions;
            }