Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////////	
        ///<summary>
        ///ModifyUser: username must be an existent user. newuser must'n exist. 
        ///groupid must be an existent group
        ///</summary>
        public void ModifyUser(int userid, UserStruct newuser)
        {
            IDictionary userRecord, groupRecord, thisUserRecord, userFields;

            try
            {
                groupRecord = new Hashtable();
                groupRecord[AdminFields.GROUPID] = "= " +newuser.groupid;
                userRecord = new Hashtable();
                userRecord[AdminFields.USERNAME] = "= '" + newuser.name + "'";
                if (db.Exist(groupRecord, DBTables.GROUPS))
                {
                    if (!db.Exist(userRecord, DBTables.USERS))
                    {
                        thisUserRecord = new Hashtable();
                        thisUserRecord[AdminFields.ID] = "= " +userid;
                        userFields = new Hashtable();
                        userFields[AdminFields.USERNAME]  = newuser.name;
                        userFields[AdminFields.PASSWORD]  = newuser.password;
                        userFields[AdminFields.GROUPID]   = newuser.groupid;
                        userFields[AdminFields.PUBLISHED] = newuser.published;
                        db.SetFieldsWhereas(thisUserRecord, userFields, DBTables.USERS);
                    }
                    else
                    {
                        UserAlreadyExistException uae = new UserAlreadyExistException();
                        throw uae;
                    }
                }
                else
                {
                    NullGroupException nge = new NullGroupException();
                    throw nge;
                }
            }
            catch (UserAlreadyExistException uae)
            {
                UserAlreadyExistException wrappedEx = new
                    UserAlreadyExistException(
                        ErrorManager.AddLayer(uae,RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (NullGroupException nge)
            {
                NullGroupException wrappedEx = new
                    NullGroupException(
                        ErrorManager.AddLayer(nge,	RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                        ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////////////////	
        ///<summary>
        ///	CreateUsers: insert a new user into table users. username must'n exist. 
        ///	id_group must be an existent group
        ///	<param name="group"> id_group, must exists in groups table</param>
        ///	<return>New user id </return>
        ///</summary>	
        public int CreateUser(UserStruct user)
        {
            IDictionary groupRecord, userRecord, userFields;

            try
            {
                groupRecord = new Hashtable();
                groupRecord[AdminFields.ID] = "= " +user.groupid;
                userRecord = new Hashtable();
                userRecord[AdminFields.USERNAME] = "= '" + user.name + "'";
                if (db.Exist(groupRecord, DBTables.GROUPS))
                {
                    if (!db.Exist(userRecord, DBTables.USERS))
                    {
                        userFields = new Hashtable();
                        userFields[AdminFields.USERNAME]  = user.name;
                        userFields[AdminFields.PASSWORD]  = user.password;
                        userFields[AdminFields.GROUPID]   = user.groupid;
                        userFields[AdminFields.PUBLISHED] = user.published;
                        db.Insert(userFields, DBTables.USERS, ref user.id);
                        return user.id;
                    }
                    else
                    {
                        UserAlreadyExistException uae = new UserAlreadyExistException();
                        throw uae;
                    }
                }
                else
                {
                    NullGroupException nge = new NullGroupException();
                    throw nge;
                }
            }
            catch (UserAlreadyExistException uae)
            {
                UserAlreadyExistException wrappedEx = new
                    UserAlreadyExistException(
                        ErrorManager.AddLayer(uae, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (NullGroupException nge)
            {
                NullGroupException wrappedEx = new
                    NullGroupException(
                        ErrorManager.AddLayer(nge,	RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                        ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
        }
        public void ChangeUserToGroup(string sid, string userName, string dstGroup, string epriseName)
        {
            IDbTransaction t = null;
            try
            {
                int groupid = -1, enterpriseid = -1;

                if (ExistUser(sid, userName))
                {
                    UserStruct us = (UserStruct) cacheMem.GetCacheData(DBTables.USERS + userName);
                    if (ExistGroup(sid, dstGroup, ref groupid, epriseName, ref enterpriseid))
                    {
                        us.groupid = groupid;
                        us.name    = userName;
                        t = db.BeginTransaction();
                        users.DeleteUser(us.id);
                        users.CreateUser(us);
                        cacheMem.SetCacheData(us, DBTables.USERS + us.name);
                        if (t != null) db.Commit(t);
                    }
                    else
                    {
                        NullGroupException nge = new NullGroupException();
                        throw nge;
                    }
                }
                else
                {
                    NullUserException nue = new NullUserException();
                    throw nue;
                }
            }
            catch (NullGroupException nge)
            {
                NullGroupException wrappedEx = new
                    NullGroupException(
                        ErrorManager.AddLayer(nge,	RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (NullUserException nue)
            {
                NullUserException wrappedEx = new
                    NullUserException(
                        ErrorManager.AddLayer(nue,RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            catch (Exception ex)
            {
                Exception wrappedEx = new Exception(
                    ErrorManager.AddLayer(ex, RunningClass.GetName(this), RunningClass.GetMethod()));
                throw wrappedEx;
            }
            finally
            {
                if (t != null) db.Commit(t);
            }
        }