Example #1
0
        public void EditLoginUser()
        {
            loginUserMgtController.FunTypeKey = "Edit";
            commonFixture.MockControllerInfo(loginUserMgtController, "http://localhost:50653/AccessControl/LoginUserManage/Edit");

            WCFSessionVM entity_WCFSessionVM = new WCFSessionVM("", "", commonFixture.StrToken, "LoginUserManage", "Edit", this.commonFixture.LanguageKey.ToString(), "");

            LUSerListResult entity_LUSerListResult = loginUserMgtController.loginUserMgtHelper.Value.GetListWithPaging(entity_WCFSessionVM, new LoginUserVM(), 1, 10, "", "", new List <string>(), loginUserMgtController.guidList_AccessedLUserID);

            LoginUserVM entity_LoginUserVM = null;

            if (entity_LUSerListResult != null)
            {
                entity_LoginUserVM = entity_LUSerListResult.EntityList_LoginUserVM.Where(current => current.LoginName == "Wells").FirstOrDefault();
            }

            Assert.NotNull(entity_LoginUserVM);

            entity_LoginUserVM.UserType       = 2;
            entity_LoginUserVM.roleListIDList = String.Join("|", entityList_LUserRoleVM.Select(current => current.ID.ToString()).ToArray());

            ActionResult actionResult = loginUserMgtController.Edit(entity_LoginUserVM);

            Assert.IsType <RedirectToRouteResult>(actionResult);
        }
        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)
        {
            LUSerListResult ret = null;

            ret = _client.GetListWithPaging(entity_WCFAuthInfoVM, entity_SearchCriteria, int_CurrentPage, int_PageSize, str_SortColumn, str_SortDir, str_CustomFilter, guidList_AccessedLUserID);
            return(ret);
        }
Example #3
0
        public void DeleteLoginUser()
        {
            loginUserMgtController.FunTypeKey = "Delete";
            commonFixture.MockControllerInfo(loginUserMgtController, "http://localhost:50653/AccessControl/LoginUserManage/Delete");

            WCFAuthInfoVM entity_WCFAuthInfoVM = new WCFAuthInfoVM("", "", commonFixture.StrToken, "LoginUserManage", "Delete", this.commonFixture.LanguageKey.ToString(), "");

            loginUserMgtController.guidList_AccessedLUserID = loginUserMgtController.GetLUserIDList(commonFixture.entity_BaseSession, "LoginUserManage", "Create", loginUserMgtController.loginUserMgtHelper.Value, entity_WCFAuthInfoVM);

            LUSerListResult entity_LUSerListResult = loginUserMgtController.loginUserMgtHelper.Value.GetListWithPaging(entity_WCFAuthInfoVM, new LoginUserVM(), 1, int.MaxValue, "", "", new List <string>(), loginUserMgtController.guidList_AccessedLUserID);

            Assert.NotEmpty(entity_LUSerListResult.EntityList_LoginUserVM);


            List <LoginUserVM> entityList_LUVM = entity_LUSerListResult.EntityList_LoginUserVM.Where(current => current.LoginName.IndexOf("Test") == 0).ToList();

            foreach (var item in entityList_LUVM)
            {
                FormCollection formCollection = new FormCollection(new NameValueCollection
                {
                    { "UserID", item.ID.ToString() }
                });

                JsonResult jsonResult = (JsonResult)loginUserMgtController.Delete(formCollection);

                Assert.NotNull(jsonResult.Data);

                Assert.IsType <CommonJsonResult>(jsonResult.Data);

                Assert.True(((CommonJsonResult)jsonResult.Data).Success);
            }
        }
        // GET: AccessControl/LoginUserManage/Index
        public ActionResult Index(int page = 1, string sort = "", string sortDir = "")
        {
            //Retrieve selection criteria from cache.
            LoginUserVM selectionCriteria = new LoginUserVM();

            //Message Box Title -- When Error occured, Message Box would be showed.
            string str_MsgBoxTitle = MultilingualHelper.GetStringFromResource(languageKey, "LoginUserManage");

            GetSelectionCriteriaFromViewData(ref selectionCriteria);

            //Define output variable(recordCount && entityList_Result)
            int recordCount = 0;

            List <LoginUserVM> entityList_Result = new List <LoginUserVM>();

            //Define wcf output object;
            LUSerListResult entity_LUSerListResult = null;

            //Instantiate WebCommonHelper in order to call wcf service
            WebCommonHelper webCommonHelper = new WebCommonHelper();

            //webCommonHelper.CallWCFHelper<ILoginUserMgtSer>(this, this.HttpContext, postOffice.LoginUserMgtSerPath, (entity_ILoginUserMgtSer, entity_WCFAuthInfoVM) =>
            //{
            //    entity_LUSerListResult = entity_ILoginUserMgtSer.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, page, PageSize, sort, sortDir, CustomFilter(selectionCriteria), guidList_AccessedLUserID);
            //});
            webCommonHelper.CallWCFHelper(this, (entity_WCFAuthInfoVM) =>
            {
                entity_LUSerListResult = loginUserMgtHelper.Value.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, page, PageSize, sort, sortDir, CustomFilter(selectionCriteria), guidList_AccessedLUserID);
            });

            if (entity_LUSerListResult != null)
            {
                recordCount       = entity_LUSerListResult.Int_TotalRecordCount;
                entityList_Result = entity_LUSerListResult.EntityList_LoginUserVM;
            }

            //Set paging bar info (Total Record Count and Page Index)
            StorePageInfo(recordCount, page);
            //Cache selection criteria
            StoreSelectionCriteria <LoginUserVM>(null);

            string strError = "";

            if (entity_LUSerListResult.StrList_Error.Count() > 0)
            {
                strError = string.Join("<br/>", entity_LUSerListResult.StrList_Error.ToArray());
            }

            if (entity_LUSerListResult.StrList_Error.Count > 0)
            {
                MsgInfo errorMsgInfo = new MsgInfo();
                errorMsgInfo.MsgTitle = str_MsgBoxTitle;
                errorMsgInfo.MsgDesc  = strError;
                errorMsgInfo.MsgType  = MessageType.ValidationError;
                ViewBag.ActionMessage = errorMsgInfo;
            }
            return(View(entityList_Result));
        }
Example #5
0
        public void DeleteLoginUser()
        {
            loginUserMgtController.FunTypeKey = "Delete";
            commonFixture.MockControllerInfo(loginUserMgtController, "http://localhost:50653/AccessControl/LoginUserManage/Delete");

            WCFSessionVM entity_WCFSessionVM = new WCFSessionVM("", "", commonFixture.StrToken, "LoginUserManage", "Delete", this.commonFixture.LanguageKey.ToString(), "");

            Random random = new Random();

            int         r             = random.Next(1, 1000);
            string      str_LoginName = "A" + r;
            LoginUserVM loginUserVM   = new LoginUserVM()
            {
                LoginName      = str_LoginName,
                NewPwd         = "A12346.b",
                ConfirmNewPwd  = "A12346.b",
                Status         = 1,
                UserType       = 2,
                roleListIDList = String.Join("|", entityList_LUserRoleVM.Select(current => current.ID.ToString()).ToArray())
            };

            WCFReturnResult createResult = loginUserMgtController.loginUserMgtHelper.Value.Create(entity_WCFSessionVM, loginUserVM);

            loginUserMgtController.guidList_AccessedLUserID = loginUserMgtController.GetLUserIDList(commonFixture.entity_ServerSideSession, "LoginUserManage", "Create", loginUserMgtController.loginUserMgtHelper.Value, entity_WCFSessionVM);

            LUSerListResult entity_LUSerListResult = loginUserMgtController.loginUserMgtHelper.Value.GetListWithPaging(entity_WCFSessionVM, new LoginUserVM(), 1, int.MaxValue, "", "", new List <string>(), loginUserMgtController.guidList_AccessedLUserID);

            Assert.NotEmpty(entity_LUSerListResult.EntityList_LoginUserVM);

            LoginUserVM entity_LoginUserVM = entity_LUSerListResult.EntityList_LoginUserVM.Where(current => current.LoginName == str_LoginName).FirstOrDefault();


            FormCollection formCollection = new FormCollection(new NameValueCollection
            {
                { "UserID", entity_LoginUserVM.ID.ToString() }
            });

            JsonResult jsonResult = (JsonResult)loginUserMgtController.Delete(formCollection);

            Assert.NotNull(jsonResult.Data);

            Assert.IsType <CommonJsonResult>(jsonResult.Data);

            Assert.True(((CommonJsonResult)jsonResult.Data).Success);
        }
Example #6
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);
            }
        }