Ejemplo n.º 1
0
        /*----------------------------------------------------------------------------------------------------------------------------------
        * Privileges
        *---------------------------------------------------------------------------------------------------------------------------------*/
        private questStatus create(FMSEntities dbContext, Privilege privilege, out PrivilegeId privilegeId)
        {
            // Initialize
            privilegeId = null;


            // Perform create
            try
            {
                Quest.Services.Dbio.FMS.Privileges _privilege = new Quest.Services.Dbio.FMS.Privileges();
                BufferMgr.TransferBuffer(privilege, _privilege);
                dbContext.Privileges.Add(_privilege);
                dbContext.SaveChanges();
                if (_privilege.Id == 0)
                {
                    return(new questStatus(Severity.Error, "Privilege not created"));
                }
                privilegeId = new PrivilegeId(_privilege.Id);
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 2
0
        private questStatus delete(FMSEntities dbContext, PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            try
            {
                // Read the record.
                Quest.Services.Dbio.FMS.Privileges _privilege = null;
                status = read(dbContext, privilegeId, out _privilege);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Delete the record.
                dbContext.Privileges.Remove(_privilege);
                dbContext.SaveChanges();
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 3
0
        public questStatus Read(PrivilegeId privilegeId, out PrivilegeEditorViewModel privilegeEditorViewModel)
        {
            // Initialize
            questStatus status = null;

            privilegeEditorViewModel = null;


            // Read
            Quest.Functional.ASM.Privilege privilege = null;
            PrivilegesMgr privilegesMgr = new PrivilegesMgr(this.UserSession);

            status = privilegesMgr.Read(privilegeId, out privilege);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            privilegeEditorViewModel = new PrivilegeEditorViewModel(this.UserSession);
            BufferMgr.TransferBuffer(privilege, privilegeEditorViewModel);



            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 4
0
        public int CompareTo(TargetPrivilegePair other)
        {
            var res = TargetId.CompareTo(other.TargetId);

            if (res == 0)
            {
                res = PrivilegeId.CompareTo(other.PrivilegeId);
            }
            return(res);
        }
        public questStatus Delete(DbMgrTransaction trans, PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            // Delete groupPrivilege
            status = _dbGroupPrivilegesMgr.Delete(trans, privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 6
0
        public questStatus Delete(PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            // Delete userPrivilege
            status = _dbUserPrivilegesMgr.Delete(privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 7
0
        public questStatus Read(PrivilegeId privilegeId, out Privilege privilege)
        {
            // Initialize
            privilege = null;
            questStatus status = null;


            // Read privilege
            status = _dbPrivilegesMgr.Read(privilegeId, out privilege);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 8
0
        /*==================================================================================================================================
        * Properties
        *=================================================================================================================================*/
        #endregion


        #region Public Methods

        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/
        public questStatus Create(Privilege privilege, out PrivilegeId privilegeId)
        {
            // Initialize
            privilegeId = null;
            questStatus status = null;


            // Create privilege
            status = _dbPrivilegesMgr.Create(privilege, out privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 9
0
        public questStatus Delete(DbMgrTransaction trans, PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            // Perform delete in this transaction.
            status = delete((FMSEntities)trans.DbContext, privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                RollbackTransaction(trans);
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 10
0
        public questStatus Read(PrivilegeId privilegeId, out PrivilegeUserList privilegeUserList)
        {
            // Initialize
            questStatus status = null;

            privilegeUserList = null;


            // Read userPrivilege
            status = _dbUserPrivilegesMgr.Read(privilegeId, out privilegeUserList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 11
0
        public questStatus Delete(PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            // Delete
            PrivilegesMgr privilegesMgr = new PrivilegesMgr(this.UserSession);

            status = privilegesMgr.Delete(privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus Read(DbMgrTransaction trans, PrivilegeId privilegeId, out PrivilegeGroupList privilegeGroupList)
        {
            // Initialize
            questStatus status = null;

            privilegeGroupList = null;


            // Read groupPrivilege
            status = _dbGroupPrivilegesMgr.Read(trans, privilegeId, out privilegeGroupList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 13
0
        public questStatus Delete(PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;


            // Perform delete.
            using (FMSEntities dbContext = new FMSEntities())
            {
                status = delete(dbContext, privilegeId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
        public ActionResult Read(PrivilegeEditorViewModel editorViewModel)
        {
            questStatus status = null;

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Log Operation
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = LogOperation();
            if (!questStatusDef.IsSuccess(status))
            {
                // TODO
                throw new Exception("LogOperation failed");
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Authorize
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = Authorize(editorViewModel._ctx);
            if (!questStatusDef.IsSuccess(status))
            {
                // TODO
                throw new Exception("Authorize failed");
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Perform operation.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            PrivilegeId privilegeId = new PrivilegeId(editorViewModel.Id);
            PrivilegeEditorViewModel privilegeEditorViewModel = null;
            PrivilegeEditorModeler   privilegeEditorModeler   = new Modelers.PrivilegeEditorModeler(this.Request, this.UserSession);

            status = privilegeEditorModeler.Read(privilegeId, out privilegeEditorViewModel);
            if (!questStatusDef.IsSuccess(status))
            {
                privilegeEditorViewModel.questStatus = status;
                return(Json(editorViewModel, JsonRequestBehavior.AllowGet));
            }

            /*----------------------------------------------------------------------------------------------------------------------------------
            * Return result.
            *---------------------------------------------------------------------------------------------------------------------------------*/
            status = new questStatus(Severity.Success);
            privilegeEditorViewModel.questStatus = status;
            return(Json(privilegeEditorViewModel, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
        public questStatus Read(PrivilegeId privilegeId, out PrivilegeUserList privilegeUserList)
        {
            // Initialize
            questStatus status = null;

            privilegeUserList = null;


            // Get privilege
            Privilege privilege = null;

            status = _dbPrivilegesMgr.Read(privilegeId, out privilege);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get privilege users
            using (FMSEntities dbContext = new FMSEntities())
            {
                List <Quest.Services.Dbio.FMS.UserPrivileges> _userPrivilegesList = null;
                status = read(dbContext, privilegeId, out _userPrivilegesList);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                privilegeUserList           = new PrivilegeUserList();
                privilegeUserList.Privilege = privilege;
                foreach (Quest.Services.Dbio.FMS.UserPrivileges _userPrivileges in _userPrivilegesList)
                {
                    // Get user
                    UserId userId = new UserId(_userPrivileges.PrivilegeId);
                    User   user   = null;
                    status = _dbUsersMgr.Read(userId, out user);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    privilegeUserList.UserList.Add(user);
                }
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 16
0
        public questStatus Read(PrivilegeId privilegeId, out PrivilegeGroupList privilegeGroupList)
        {
            // Initialize
            questStatus status = null;

            privilegeGroupList = null;


            // Get privilege
            Privilege privilege = null;

            status = _dbPrivilegesMgr.Read(privilegeId, out privilege);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get privilege groups
            using (FMSEntities dbContext = new FMSEntities())
            {
                List <Quest.Services.Dbio.FMS.GroupPrivileges> _groupPrivilegesList = null;
                status = read(dbContext, privilegeId, out _groupPrivilegesList);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                privilegeGroupList           = new PrivilegeGroupList();
                privilegeGroupList.Privilege = privilege;
                foreach (Quest.Services.Dbio.FMS.GroupPrivileges _groupPrivileges in _groupPrivilegesList)
                {
                    // Get group
                    GroupId groupId = new GroupId(_groupPrivileges.PrivilegeId);
                    Group   group   = null;
                    status = _dbGroupsMgr.Read(groupId, out group);
                    if (!questStatusDef.IsSuccess(status))
                    {
                        return(status);
                    }
                    privilegeGroupList.GroupList.Add(group);
                }
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 17
0
        public questStatus Create(DbMgrTransaction trans, Privilege privilege, out PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;

            privilegeId = null;


            // Data rules.
            privilege.Created = DateTime.Now;


            // Create the privilege in this transaction.
            status = create((FMSEntities)trans.DbContext, privilege, out privilegeId);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 18
0
        public questStatus Read(DbMgrTransaction trans, UserId userId, out UserPrivilegeList userPrivilegeList)
        {
            // Initialize
            questStatus status = null;

            userPrivilegeList = null;


            // Get user
            User user = null;

            status = _dbUsersMgr.Read(userId, out user);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get user privileges
            List <Quest.Services.Dbio.FMS.UserPrivileges> _userPrivilegeList = null;

            status = read((FMSEntities)trans.DbContext, userId, out _userPrivilegeList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            userPrivilegeList      = new UserPrivilegeList();
            userPrivilegeList.User = user;
            foreach (Quest.Services.Dbio.FMS.UserPrivileges _userPrivilege in _userPrivilegeList)
            {
                // Get privilege
                PrivilegeId privilegeId = new PrivilegeId(_userPrivilege.PrivilegeId);
                Privilege   privilege   = null;
                status = _dbPrivilegesMgr.Read(privilegeId, out privilege);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                userPrivilegeList.PrivilegeList.Add(privilege);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 19
0
        public questStatus Read(DbMgrTransaction trans, GroupId groupId, out GroupPrivilegeList groupPrivilegeList)
        {
            // Initialize
            questStatus status = null;

            groupPrivilegeList = null;


            // Get group
            Group group = null;

            status = _dbGroupsMgr.Read(groupId, out group);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Get group privileges
            List <Quest.Services.Dbio.FMS.GroupPrivileges> _groupPrivilegeList = null;

            status = read((FMSEntities)trans.DbContext, groupId, out _groupPrivilegeList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }
            groupPrivilegeList       = new GroupPrivilegeList();
            groupPrivilegeList.Group = group;
            foreach (Quest.Services.Dbio.FMS.GroupPrivileges _groupPrivilege in _groupPrivilegeList)
            {
                // Get privilege
                PrivilegeId privilegeId = new PrivilegeId(_groupPrivilege.PrivilegeId);
                Privilege   privilege   = null;
                status = _dbPrivilegesMgr.Read(privilegeId, out privilege);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                groupPrivilegeList.PrivilegeList.Add(privilege);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 20
0
        public questStatus Read(DbMgrTransaction trans, PrivilegeId privilegeId, out Privilege privilege)
        {
            // Initialize
            questStatus status = null;

            privilege = null;


            // Perform read.
            using (FMSEntities dbContext = new FMSEntities())
            {
                Quest.Services.Dbio.FMS.Privileges _privilege = null;
                status = read((FMSEntities)trans.DbContext, privilegeId, out _privilege);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                privilege = new Privilege();
                BufferMgr.TransferBuffer(_privilege, privilege);
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 21
0
        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/

        #region CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        // CRUD
        //----------------------------------------------------------------------------------------------------------------------------------
        public questStatus Save(PrivilegeEditorViewModel privilegeEditorViewModel)
        {
            // Initialize
            questStatus status = null;


            // Transfer model
            Quest.Functional.ASM.Privilege privilege = new Quest.Functional.ASM.Privilege();
            BufferMgr.TransferBuffer(privilegeEditorViewModel, privilege);


            // Determine if this is a create or update
            PrivilegesMgr privilegesMgr = new PrivilegesMgr(this.UserSession);

            if (privilegeEditorViewModel.Id < BaseId.VALID_ID)
            {
                // Create
                PrivilegeId privilegeId = null;
                status = privilegesMgr.Create(privilege, out privilegeId);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, privilegeEditorViewModel);
                    return(status);
                }
                privilegeEditorViewModel.Id = privilegeId.Id;
            }
            else
            {
                // Update
                status = privilegesMgr.Update(privilege);
                if (!questStatusDef.IsSuccess(status))
                {
                    FormatErrorMessage(status, privilegeEditorViewModel);
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 22
0
        /*==================================================================================================================================
        * Properties
        *=================================================================================================================================*/
        #endregion


        #region Public Methods

        /*==================================================================================================================================
        * Public Methods
        *=================================================================================================================================*/
        public questStatus Create(Privilege privilege, out PrivilegeId privilegeId)
        {
            // Initialize
            questStatus status = null;

            privilegeId = null;


            // Data rules.
            privilege.Created = DateTime.Now;


            // Create the privilege
            using (FMSEntities dbContext = new FMSEntities())
            {
                status = create(dbContext, privilege, out privilegeId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 23
0
        private questStatus read(FMSEntities dbContext, PrivilegeId privilegeId, out List <Quest.Services.Dbio.FMS.UserPrivileges> userPrivilegeList)
        {
            // Initialize
            userPrivilegeList = null;


            try
            {
                userPrivilegeList = dbContext.UserPrivileges.Where(r => r.PrivilegeId == privilegeId.Id).ToList();
                if (userPrivilegeList == null)
                {
                    return(new questStatus(Severity.Warning, String.Format("WARNING: {0}.{1}: {2}",
                                                                           this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                           String.Format("PrivilegeId {0} not found", privilegeId.Id))));
                }
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 24
0
        private questStatus read(FMSEntities dbContext, PrivilegeId privilegeId, out Quest.Services.Dbio.FMS.Privileges privilege)
        {
            // Initialize
            privilege = null;


            try
            {
                privilege = dbContext.Privileges.Where(r => r.Id == privilegeId.Id).SingleOrDefault();
                if (privilege == null)
                {
                    return(new questStatus(Severity.Error, String.Format("ERROR: {0}.{1}: {2}",
                                                                         this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                         String.Format("Id {0} not found", privilegeId.Id))));
                }
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Ejemplo n.º 25
0
 public override int GetHashCode()
 {
     return(PrivilegeId.GetHashCode());
 }