private void attach_Sys_UserPermission(Sys_UserPermission entity)
		{
			this.SendPropertyChanging();
			entity.Sys_Permission = this;
		}
		private void detach_Sys_UserPermission(Sys_UserPermission entity)
		{
			this.SendPropertyChanging();
			entity.Sys_User = null;
		}
 partial void DeleteSys_UserPermission(Sys_UserPermission instance);
 partial void UpdateSys_UserPermission(Sys_UserPermission instance);
 partial void InsertSys_UserPermission(Sys_UserPermission instance);
예제 #6
0
        public void SaveUser(Guid userGuid, string userName, string firstName, string lastName, List<Guid> permissionGuids)
        {
            using(var db = new IntiDataContext(_connectionString))
            {
                var user = db.Sys_User.Single(u => u.GUID == userGuid);

                //is user name still unique?
                if (userName != user.UserName)
                {
                    var users = from u in db.Sys_User
                                where u.UserName == userName &&
                                      u.GUID != userGuid
                                select u;

                    if(users.ToList().Count > 0)
                    {
                        throw new Exception(String.Format("The Username {0} not unique", userName));
                    }
                }

                var message = "";
                if (user.UserName != userName)
                {
                    message += String.Format("Changed {0} from {1} to {2}. ", "UserName", user.UserName, userName);
                    user.UserName = userName;
                }

                if (user.FirstName!= firstName)
                {
                    message += String.Format("Changed {0} from {1} to {2}. ", "FirstName", user.FirstName, firstName);
                    user.FirstName = firstName;
                }

                if (user.LastName != lastName)
                {
                    message += String.Format("Changed {0} from {1} to {2}. ", "LastName", user.LastName, lastName);
                    user.LastName = lastName;
                }

                if(!String.IsNullOrEmpty(message))
                    LogEvent(userGuid, user.GetType(), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Change, message);

                //clear permissions
                var userPermissions = from up in db.Sys_UserPermission
                                      where up.UserGUID == userGuid
                                      select up;

                foreach (Sys_UserPermission userPermission in userPermissions.ToList())
                {
                    if (permissionGuids.Contains(userPermission.PermissionGUID))
                    {
                        permissionGuids.Remove(userPermission.PermissionGUID);
                    }
                    else
                    {
                        db.Sys_UserPermission.DeleteOnSubmit(userPermission);
                        LogEvent(userGuid, user.GetType(), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Change, "Removed permission " + userPermission.Sys_Permission.Name);
                    }
                }

                foreach (Guid permissionGuid in permissionGuids)
                {
                    var userPermission = new Sys_UserPermission();
                    userPermission.UserGUID = userGuid;
                    userPermission.PermissionGUID = permissionGuid;

                    Guid guid = permissionGuid;
                    var permission = db.Sys_Permission.Single(p => p.GUID == guid);
                    LogEvent(userGuid, user.GetType(), SessionProperties.UserGuid, SessionProperties.ClientInfo, EventType.Change, "Added permission " + permission.Name);

                    db.Sys_UserPermission.InsertOnSubmit(userPermission);
                }

                db.SubmitChanges();

            }
        }
예제 #7
0
        public void RegisterUser(string firstName, string lastName, string email, string password)
        {
            if (String.IsNullOrEmpty(firstName))
                throw new IntiGeneralException("Du måste ange ett förnamn");

            if (String.IsNullOrEmpty(lastName))
                throw new IntiGeneralException("Du måste ange ett efternamn");

            if (String.IsNullOrEmpty(email))
                throw new IntiGeneralException("Du måste ange en epostadress");

            if (String.IsNullOrEmpty(password))
                throw new IntiGeneralException("Du måste ange ett lösenord");

            using (var db = new IntiDataContext(_connectionString))
            {
                //username/email must be unique
                var users = from u in db.Sys_User
                            where u.UserName.ToLower() == email.ToLower()
                            select u;

                if (users.ToList().Count > 0)
                    throw new IntiGeneralException("Det finns redan en användare med den epostadressen");

                var user = new Sys_User { FirstName = firstName, LastName = lastName, UserName = email, Password = password };

                db.Sys_User.InsertOnSubmit(user);

                //default permissions
                var defaultPermissions = from p in db.Sys_Permission
                                         where p.Name == "USER" || p.Name == "USER_PVTTOUR"
                                         select p;

                foreach (var perm in defaultPermissions.ToList())
                {
                    var userPerm = new Sys_UserPermission();
                    userPerm.UserGUID = user.GUID;
                    userPerm.PermissionGUID = perm.GUID;
                    db.Sys_UserPermission.InsertOnSubmit(userPerm);
                }

                db.SubmitChanges();
            }
        }