Beispiel #1
0
        public List <FunctionVM> GetAll(WCFAuthInfoVM entity_WCFAuthInfoVM)
        {
            try
            {
                //Retrieve Language And Session
                RetrieveLanguageAndSession(entity_WCFAuthInfoVM);

                if (entity_BaseSession != null)
                {
                    CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext();

                    FunctionRespository funRespo = new FunctionRespository(dbContext, entity_BaseSession.ID);

                    List <FunctionVM> entityList_OrgVM = new List <FunctionVM>();

                    List <string> strList_Error = new List <string>();

                    bool ret = false;

                    ret = CheckTokenOnly(entity_BaseSession, ref strList_Error);

                    if (ret)
                    {
                        IPrivilegeFun entity_IPrivilegeFun = WCFBootstrapper.Container.GetExportedValue <IPrivilegeFun>();

                        SessionWUserInfo entity_SessionWUserInfo = entity_IPrivilegeFun.getAuthorizedInfoByUserID(entity_BaseSession.ID);

                        entity_BaseSession = entity_SessionWUserInfo;

                        bool allowEdit = entity_BaseSession.CheckAccessRight("FManage", "Edit", "", null);
                        bool allowDel  = entity_BaseSession.CheckAccessRight("FManage", "Delete", "", null);

                        entityList_OrgVM = funRespo.GetFuns_All();

                        entityList_OrgVM.ForEach(current =>
                        {
                            current.FunctionName = MultilingualHelper.GetStringFromResource(languageKey, current.FunctionKey);
                            current.AllowDel     = allowDel;
                            current.AllowEdit    = allowEdit;
                        });
                    }

                    return(entityList_OrgVM);
                }
                return(new List <FunctionVM>());
            }
            catch (Exception ex)
            {
                throw new WebFaultException <WCFErrorContract>(new WCFErrorContract(ex), System.Net.HttpStatusCode.ExpectationFailed);
            }
        }
        public List <FunctionTypeVM> GetAllFunType(WCFAuthInfoVM entity_WCFAuthInfoVM)
        {
            try
            {
                //Retrieve Language And Session
                RetrieveLanguageAndSession(entity_WCFAuthInfoVM);

                List <FunctionTypeVM> returnResult = new List <FunctionTypeVM>();

                //Contruct Login User Respository
                CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext();

                FunctionTypeRespository Respo_FT = new FunctionTypeRespository(dbContext, entity_BaseSession.ID);

                List <string> strList_Error = new List <string>();

                bool ret = false;

                ret = CheckTokenOnly(entity_BaseSession, ref strList_Error);

                if (ret)
                {
                    IPrivilegeFun    entity_IPrivilegeFun    = WCFBootstrapper.Container.GetExportedValue <IPrivilegeFun>();
                    SessionWUserInfo entity_SessionWUserInfo = entity_IPrivilegeFun.getAuthorizedInfoByUserID(entity_BaseSession.ID);

                    entity_BaseSession = entity_SessionWUserInfo;

                    bool allowEdit = entity_BaseSession.CheckAccessRight("FTManage", "Edit", "", null);
                    bool allowDel  = entity_BaseSession.CheckAccessRight("FTManage", "Delete", "", null);

                    returnResult = Respo_FT.GetAllFunctionType();

                    foreach (var item in returnResult)
                    {
                        item.AllowEdit = allowEdit;
                        item.AllowDel  = allowDel;
                    }
                }

                return(returnResult);
            }
            catch (Exception ex)
            {
                throw new WebFaultException <WCFErrorContract>(new WCFErrorContract(ex), System.Net.HttpStatusCode.ExpectationFailed);
            }
        }
        public List <LUserRoleVM> GetAll(WCFAuthInfoVM entity_WCFAuthInfoVM)
        {
            try
            {
                //Retrieve Language And Session
                RetrieveLanguageAndSession(entity_WCFAuthInfoVM);

                List <string> strList_Error = new List <string>();

                bool ret_CheckPrivilege = false;

                ret_CheckPrivilege = CheckTokenOnly(entity_BaseSession, ref strList_Error);

                List <LUserRoleVM> entityList_RoleVM = new List <LUserRoleVM>();

                if (ret_CheckPrivilege)
                {
                    IPrivilegeFun entity_IPrivilegeFun = WCFBootstrapper.Container.GetExportedValue <IPrivilegeFun>();

                    SessionWUserInfo entity_SessionWUserInfo = entity_IPrivilegeFun.getAuthorizedInfoByUserID(entity_BaseSession.ID);

                    entity_BaseSession = entity_SessionWUserInfo;

                    bool allowEdit = entity_BaseSession.CheckAccessRight("LURoleManage", "Edit", "", null);
                    bool allowDel  = entity_BaseSession.CheckAccessRight("LURoleManage", "Delete", "", null);

                    CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext();

                    UserRoleRespository roleRespo = new UserRoleRespository(dbContext, entity_BaseSession.ID);

                    entityList_RoleVM = roleRespo.GetLURoleVM_All();

                    entityList_RoleVM.ForEach(current =>
                    {
                        current.AllowDel  = allowDel;
                        current.AllowEdit = allowEdit;
                    });
                }

                return(entityList_RoleVM);
            }
            catch (Exception ex)
            {
                throw new WebFaultException <WCFErrorContract>(new WCFErrorContract(ex), System.Net.HttpStatusCode.ExpectationFailed);
            }
        }
Beispiel #4
0
        public LUSerListResult GetListWithPaging(WCFAuthInfoVM entity_WCFAuthInfoVM, LoginUserVM entity_SearchCriteria, int int_CurrentPage, int int_PageSize, string str_SortColumn, string str_SortDir, List <string> str_CustomFilter, List <Guid> guidList_AccessedLUserID)
        {
            try
            {
                //Restore Server Session
                RetrieveServerSideSession(entity_WCFAuthInfoVM);

                bool ret_CheckPrivilege = false;

                List <string> strList_Error = new List <string>();

                LUSerListResult returnResult = new LUSerListResult();

                CoolPrivilegeControlContext dbContext             = CoolPrivilegeControlContext.CreateContext();
                LUserAccessPolicy           userAccessPolicy      = new LUserAccessPolicy();
                LUserAccessByOrgPolicy      userAccessByOrgPolicy = new LUserAccessByOrgPolicy();
                LoginUserRespository        entityRepos           = new LoginUserRespository(dbContext, entity_BaseSession.ID);

                #region [ Check Privilege ]
                ret_CheckPrivilege = CheckAccPrivilege(entity_BaseSession.ID, entity_WCFAuthInfoVM.RequestFunKey, entity_WCFAuthInfoVM.RequestFunTypeKey, ref strList_Error);
                #endregion

                returnResult.StrList_Error          = strList_Error;
                returnResult.Int_TotalRecordCount   = 0;
                returnResult.EntityList_LoginUserVM = new List <LoginUserVM>();

                if (ret_CheckPrivilege)
                {
                    Func <List <LUser>, List <LUser> > func_OtherFilter = (entityList_LUVM) =>
                    {
                        List <LUser> ret = entityList_LUVM;
                        if (entity_SearchCriteria.UserType.HasValue)
                        {
                            if (entity_SearchCriteria.UserType.Value == 1)
                            {
                                ret = ret.Where(current => current.LU_UserType.HasValue && current.LU_UserType.Value == 1).ToList();
                            }
                            else if (entity_SearchCriteria.UserType.Value == 2)
                            {
                                ret = ret.Where(current => current.LU_UserType.HasValue && current.LU_UserType.Value == 2).ToList();
                                if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.SC_RoleName))
                                {
                                    List <LoginUserVM> entityList_LoginUservm = userAccessPolicy.Get_LoginUser_RoleName(dbContext, entity_SearchCriteria.SC_RoleName.ToString());

                                    var IDList_LoginUserVM = entityList_LoginUservm.Select(current => current.ID).ToList();

                                    ret = ret.Where(current => IDList_LoginUserVM.Contains(current.ID)).ToList();
                                }
                            }
                            else if (entity_SearchCriteria.UserType.Value == 3)
                            {
                                ret = ret.Where(current => current.LU_UserType.HasValue && current.LU_UserType.Value == 3).ToList();
                                if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.SC_OrgKey))
                                {
                                    List <LoginUserVM> entityList_LoginUservm = userAccessByOrgPolicy.Get_LoginUser_OrgName(dbContext, entity_SearchCriteria.SC_OrgKey.ToString());

                                    var IDList_LoginUserVM = entityList_LoginUservm.Select(current => current.ID).ToList();

                                    ret = ret.Where(current => IDList_LoginUserVM.Contains(current.ID)).ToList();
                                }
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.LoginName))
                        {
                            ret = ret.Except(ret.Where(current => current.LU_Name.IndexOf(entity_SearchCriteria.LoginName) != 0)).ToList();
                        }

                        //AccessRight Checking
                        ret = ret.Where(current => guidList_AccessedLUserID.Contains(current.ID)).ToList();
                        return(ret);
                    };
                    int recordCount           = 0;
                    List <LoginUserVM> vmList = entityRepos.GetEntityListByPage(entity_SearchCriteria, int_CurrentPage, int_PageSize, str_SortColumn, str_SortDir, out recordCount, str_CustomFilter, func_OtherFilter, null, (entityList_VM) =>
                    {
                        foreach (var item in entityList_VM)
                        {
                            List <LUserRoleVM> entityList_RoleVM = userAccessPolicy.Get_RoleSettings_LUserID(dbContext, item.ID);

                            item.EntityList_Role = entityList_RoleVM;

                            List <LUserOrganizationVM> entityList_OrgVM = userAccessByOrgPolicy.Get_OrgSettings_LUserID(dbContext, item.ID);

                            item.EntityList_Org = entityList_OrgVM;
                        }
                        return(entityList_VM);
                    });

                    IPrivilegeFun entity_IPrivilegeFun = WCFBootstrapper.Container.GetExportedValue <IPrivilegeFun>();

                    SessionWUserInfo entity_SessionWUserInfo = entity_IPrivilegeFun.getAuthorizedInfoByUserID(entity_BaseSession.ID);

                    List <Guid> guidList_SpecificLUID = vmList.Select(current => current.ID).ToList();

                    IDictionary <Guid, bool> boolDic_Del  = new Dictionary <Guid, bool>();
                    IDictionary <Guid, bool> boolDic_Eidt = new Dictionary <Guid, bool>();
                    if (StaticContent.LockAdmin())
                    {
                        boolDic_Del  = CheckAccPrivilegeWSpecificUserIDList(entity_SessionWUserInfo, entity_WCFAuthInfoVM.RequestFunKey, "Delete", guidList_SpecificLUID);
                        boolDic_Eidt = CheckAccPrivilegeWSpecificUserIDList(entity_SessionWUserInfo, entity_WCFAuthInfoVM.RequestFunKey, "Edit", guidList_SpecificLUID);
                    }
                    else
                    {
                        boolDic_Del  = CheckAccPrivilegeWSpecificUserIDList(entity_SessionWUserInfo, entity_WCFAuthInfoVM.RequestFunKey, "Delete", guidList_SpecificLUID, true);
                        boolDic_Eidt = CheckAccPrivilegeWSpecificUserIDList(entity_SessionWUserInfo, entity_WCFAuthInfoVM.RequestFunKey, "Edit", guidList_SpecificLUID, true);
                    }
                    foreach (var vm in vmList)
                    {
                        if (boolDic_Eidt.ContainsKey(vm.ID))
                        {
                            vm.AllowEdit = boolDic_Eidt[vm.ID];
                        }
                        if (boolDic_Del.ContainsKey(vm.ID))
                        {
                            vm.AllowDel = boolDic_Del[vm.ID];
                        }
                    }

                    returnResult.EntityList_LoginUserVM = vmList;
                    returnResult.Int_TotalRecordCount   = recordCount;
                }
                return(returnResult);
            }
            catch (Exception ex)
            {
                throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message);
            }
        }