예제 #1
0
        public bool UpdateRoleModuleForms(int roleID, BindingList <RoleModuleForm> roleModuleForms)
        {
            bool result      = false;
            int  selModuleID = 0;

            try
            {
                if (roleModuleForms.Count > 0)
                {
                    selModuleID = roleModuleForms[0].ModuleID;
                }

                // INSETRING MODULE NOT FOUND IN DATABASE
                foreach (RoleModuleForm item in roleModuleForms)
                {
                    if (item.Selected)
                    {
                        if (item.ID == 0)
                        {
                            TBL_MP_Master_RoleForm newItem = new TBL_MP_Master_RoleForm();
                            newItem.FK_RoleID   = roleID;
                            newItem.FK_ModuleId = item.ModuleID;
                            newItem.FK_FormId   = item.FormID;
                            newItem.CanAddNew   = newItem.CanApprove = newItem.CanAuthorize = newItem.CanCheck = newItem.CanDelete = newItem.CanModify = newItem.CanPrepare = newItem.CanPrint = newItem.CanView = false;
                            _dbContext.TBL_MP_Master_RoleForm.Add(newItem);
                            _dbContext.SaveChanges();
                            item.ID = newItem.PK_RoleFormID;
                        }
                    }
                }

                // DELETING MODULE NOT FOUND IN COLLECTION
                String deleteIDs = string.Empty;
                List <TBL_MP_Master_RoleForm> dbItems = (from xx in _dbContext.TBL_MP_Master_RoleForm where xx.FK_RoleID == roleID && xx.FK_ModuleId == selModuleID select xx).ToList();
                foreach (TBL_MP_Master_RoleForm item in dbItems)
                {
                    RoleModuleForm mItem = roleModuleForms.Where(x => x.ID == item.PK_RoleFormID).FirstOrDefault();
                    if (mItem != null)
                    {
                        if (!mItem.Selected)
                        {
                            deleteIDs += string.Format("{0}{1}", mItem.FormID, DefaultStringSeperator);
                        }
                    }
                }
                if (deleteIDs != string.Empty)
                {
                    deleteIDs = deleteIDs.TrimEnd(DefaultStringSeperator).Replace(DefaultStringSeperator, ',');
                    string strQuery = string.Format("DELETE FROM TBL_MP_Master_RoleForm WHERE FK_RoleID={0} AND FK_FormId IN ({1})", roleID, deleteIDs);
                    _dbContext.Database.ExecuteSqlCommand(strQuery);
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += "\n" + ex.InnerException.Message;
                }
                MessageBox.Show(errMessage, "ServiceRoles::UpdateRoleModuleForms", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
예제 #2
0
        public List <RoleModuleForm> GetFormsGridForRoleModule(int roleID, int moduleID)
        {
            List <RoleModuleForm> lstData = new List <RoleModuleForm>();

            try
            {
                // GET ALL FORMS FOR THE MODULE
                List <SelectListItem> lstForms = (new ServiceModules()).GetAllActiveFormsForModule(moduleID);
                foreach (SelectListItem form in lstForms)
                {
                    RoleModuleForm lstItem = new RoleModuleForm()
                    {
                        Description = form.Description, FormID = form.ID, ModuleID = moduleID
                    };
                    TBL_MP_Master_RoleForm dbRoleForm = (from xx in _dbContext.TBL_MP_Master_RoleForm where xx.FK_RoleID == roleID && xx.FK_FormId == form.ID select xx).FirstOrDefault();
                    if (dbRoleForm != null)
                    {
                        string strDescription = string.Empty;
                        if (dbRoleForm.CanAddNew)
                        {
                            strDescription += "Add ";
                        }
                        if (dbRoleForm.CanApprove)
                        {
                            strDescription += "Approve ";
                        }
                        if (dbRoleForm.CanAuthorize)
                        {
                            strDescription += "Authorize ";
                        }
                        if (dbRoleForm.CanCheck)
                        {
                            strDescription += "Check ";
                        }
                        if (dbRoleForm.CanDelete)
                        {
                            strDescription += "Delete ";
                        }
                        if (dbRoleForm.CanModify)
                        {
                            strDescription += "Modify ";
                        }
                        if (dbRoleForm.CanPrepare)
                        {
                            strDescription += "Prepare ";
                        }
                        if (dbRoleForm.CanPrint)
                        {
                            strDescription += "Print ";
                        }
                        if (dbRoleForm.CanView)
                        {
                            strDescription += "View ";
                        }
                        lstItem.Selected     = true;
                        lstItem.ID           = dbRoleForm.PK_RoleFormID;
                        lstItem.RoleID       = dbRoleForm.FK_RoleID;
                        lstItem.ModuleID     = (int)dbRoleForm.FK_ModuleId;
                        lstItem.FormID       = dbRoleForm.FK_FormId;
                        lstItem.Description += "\n" + strDescription.ToUpper();
                    }
                    lstData.Add(lstItem);
                }
            }
            catch (Exception ex)
            {
                string strError = ex.Message;
                if (ex.InnerException != null)
                {
                    strError += "\n" + ex.InnerException.Message;
                }
                MessageBox.Show(strError, "ServiceRoles::GetFormsGridForRoleModule", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(lstData);
        }