public int GetTotalAuthorizationCount(WCFAuthInfoVM entity_WCFAuthInfoVM) { try { WCFSesssionPolicy wcfPolicy = new WCFSesssionPolicy(); CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext(); BaseSession entity_BaseSession = wcfPolicy.RestoreWCFSesssion(entity_WCFAuthInfoVM); AuthorizedHistoryRespository authorizedHistoryRespo = new AuthorizedHistoryRespository(dbContext, entity_BaseSession.ID); int int_Counter = authorizedHistoryRespo.GetTotalAuthorizationCount(OperationType.L); return(int_Counter); } catch (Exception ex) { throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message); } }
public WCFReturnResult Logout(WCFAuthInfoVM entity_WCFAuthInfoVM) { try { //Retrieve Language And Session RetrieveLanguageAndSession(entity_WCFAuthInfoVM); WCFReturnResult returnResult = new WCFReturnResult(); string str_SaveAuthorizedHistory_Error = ""; if (entity_BaseSession != null) { CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext(); AuthorizedHistoryRespository authorityHistoryRespos = new AuthorizedHistoryRespository(dbContext, entity_BaseSession.ID); authorityHistoryRespos.Create(new AuthorizedHistoryVM(), languageKey, out str_SaveAuthorizedHistory_Error, false); wcfPolicy.RemoveWCFSession(entity_BaseSession); } else { str_SaveAuthorizedHistory_Error = MultilingualHelper.GetStringFromResource(languageKey, "E011"); } if (!string.IsNullOrWhiteSpace(str_SaveAuthorizedHistory_Error)) { returnResult.StrList_Error.Add(str_SaveAuthorizedHistory_Error); returnResult.IsSuccess = false; } else { returnResult.IsSuccess = true; } return(returnResult); } catch (Exception ex) { throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message); } }
public WCFReturnResult Delete(WCFAuthInfoVM entity_WCFAuthInfoVM, string str_AuthHisID) { try { //Retrieve Language And Session RetrieveLanguageAndSession(entity_WCFAuthInfoVM); WCFReturnResult returnResult = new WCFReturnResult(); //Contruct Login User Respository CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext(); AuthorizedHistoryRespository entityRepos_AH = new AuthorizedHistoryRespository(dbContext, entity_BaseSession.ID); List <string> strList_Error = new List <string>(); bool ret = false; ret = CheckAccPrivilege(entity_BaseSession.ID, entity_WCFAuthInfoVM.RequestFunKey, entity_WCFAuthInfoVM.RequestFunTypeKey, ref strList_Error); if (ret) { ret = entityRepos_AH.Delete(str_AuthHisID, languageKey, ref strList_Error); } returnResult.IsSuccess = ret; returnResult.StrList_Error = strList_Error; return(returnResult); } catch (Exception ex) { throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message); } }
AHSerListResult IAuthHisMgtSer.GetListWithPaging(WCFAuthInfoVM entity_WCFAuthInfoVM, AuthorizedHistoryVM entity_SearchCriteria, int int_CurrentPage, int int_PageSize, string str_SortColumn, string str_SortDir, List <string> str_CustomFilter) { try { //Restore Server Session RetrieveServerSideSession(entity_WCFAuthInfoVM); bool ret = false; List <string> strList_Error = new List <string>(); AHSerListResult returnResult = new AHSerListResult(); CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext(); AuthorizedHistoryRespository entityRepos_AH = new AuthorizedHistoryRespository(dbContext, entity_BaseSession.ID); #region [ Check Privilege ] ret = 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_AuthorizedHistoryVM = new List <AuthorizedHistoryVM>(); if (ret) { int recordCount = 0; List <AuthorizedHistoryVM> vmList = entityRepos_AH.GetEntityListByPage(entity_SearchCriteria, int_CurrentPage, int_PageSize, str_SortColumn, str_SortDir, out recordCount, str_CustomFilter, (entityList) => { List <AuthorizedHistory> entityList_AuthorizedHistory = new List <AuthorizedHistory>(); if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.LoginName)) { DBContextHelper.ExecuteSearchEvent(CoolPrivilegeControlContext.CreateContext(), dbContext_Temp => { List <LUser> entityList_LUser = dbContext_Temp.LUsers.Where(current => current.LU_Name.IndexOf(entity_SearchCriteria.LoginName) == 0).ToList(); if (entityList_LUser != null && entityList_LUser.Count > 0) { List <Guid> guidList_UserID = entityList_LUser.Select(current => current.ID).ToList(); entityList_AuthorizedHistory = entityList.Where(current => guidList_UserID.Contains(current.AH_UserID) && (!string.IsNullOrWhiteSpace(entity_SearchCriteria.OperationType) ? current.AH_EventType == entity_SearchCriteria.OperationType : true)).ToList(); } }); } else { DBContextHelper.ExecuteSearchEvent(CoolPrivilegeControlContext.CreateContext(), dbContext_Temp => { entityList_AuthorizedHistory = entityList.Where(current => !string.IsNullOrWhiteSpace(entity_SearchCriteria.OperationType) ? current.AH_EventType == entity_SearchCriteria.OperationType : true).ToList(); }); } return(entityList_AuthorizedHistory); }, null, (entityList) => { List <Guid> userIDList = entityList.Select(current => current.LoginUserID).ToList(); List <LUser> entityList_LUser_GetLoginName = new List <LUser>(); DBContextHelper.ExecuteSearchEvent(CoolPrivilegeControlContext.CreateContext(), dbContext_Temp => { entityList_LUser_GetLoginName = dbContext_Temp.LUsers.Where(current => userIDList.Contains(current.ID)).ToList(); }); foreach (var item in entityList) { var item_LUser = entityList_LUser_GetLoginName.Where(current => current.ID == item.LoginUserID).FirstOrDefault(); if (item_LUser != null) { item.LoginName = item_LUser.LU_Name; } if (item.OperationType == OperationType.L.ToString()) { item.OperationTypeName = MultilingualHelper.GetStringFromResource(languageKey, "Login"); } else if (item.OperationType == OperationType.O.ToString()) { item.OperationTypeName = MultilingualHelper.GetStringFromResource(languageKey, "Logout"); } } return(entityList); }); returnResult.EntityList_AuthorizedHistoryVM = vmList; returnResult.Int_TotalRecordCount = recordCount; } return(returnResult); } catch (Exception ex) { throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message); } }
public LUSerLoginResult Login(LoginUserVM entityInst, string str_Language, string str_IpAdd, string str_HostName) { try { LUSerLoginResult returnResult = new LUSerLoginResult(); SysParmRespository entityRepository = new SysParmRespository(); StaticContent.SystemInfoInst = entityRepository.RetrieveSystemInfo(); LanguageKey languageKey_Input = LanguageKey.en; Enum.TryParse <LanguageKey>(str_Language, out languageKey_Input); // Login Name cannot be empty if (string.IsNullOrWhiteSpace(entityInst.LoginName)) { string str_E001 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E001"); str_E001 = string.Format(str_E001, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginName")); returnResult.StrList_Error.Add(str_E001); } // Login Password cannot be empty if (string.IsNullOrWhiteSpace(entityInst.LoginPwd)) { string str_E001 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E001"); str_E001 = string.Format(str_E001, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginPwd")); returnResult.StrList_Error.Add(str_E001); } if (!string.IsNullOrWhiteSpace(entityInst.LoginName) && !string.IsNullOrWhiteSpace(entityInst.LoginPwd)) { string str_E008 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E008"); str_E008 = string.Format(str_E008, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginName"), MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginPwd")); string str_E009 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E009"); string str_E018 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E018"); CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext(); LoginUserRespository loginUserRespo = new LoginUserRespository(dbContext, null); LoginUserVM entityVM_exist = loginUserRespo.GetLoginUserInfo(entityInst.LoginName); if (entityVM_exist != null) { PwdPolicy pwdPolicy = new PwdPolicy(); if (!entityVM_exist.Status.HasValue || entityVM_exist.Status.Value == 2) { returnResult.StrList_Error.Add(str_E018); } else if (entityVM_exist.Status.HasValue && entityVM_exist.Status.Value == 3) { returnResult.StrList_Error.Add(str_E018); } else { if (entityVM_exist.LoginPwd == pwdPolicy.GetMD5(entityInst.LoginPwd)) { DateTime?dt_LastPwdMDT = entityVM_exist.LastPwdMDT; entityVM_exist.FailCount = 0; entityVM_exist.Status = 1; entityVM_exist.LastLoginDT = DateTime.Now; entityInst.LastPwdMDT = entityVM_exist.LastPwdMDT; List <string> strList_UpdateLastLoginDt_Error = new List <string>(); loginUserRespo.UpdateLastLoginDt(entityVM_exist, languageKey_Input, ref strList_UpdateLastLoginDt_Error); if (strList_UpdateLastLoginDt_Error.Count > 0) { foreach (var item in strList_UpdateLastLoginDt_Error) { returnResult.StrList_Error.Add(item); } } else { AuthorizedHistoryRespository authorityHistoryRespos = new AuthorizedHistoryRespository(dbContext, entityVM_exist.ID); string str_SaveAuthorizedHistory_Error = ""; //Create Login History authorityHistoryRespos.Create(new AuthorizedHistoryVM(), languageKey_Input, out str_SaveAuthorizedHistory_Error); if (!string.IsNullOrWhiteSpace(str_SaveAuthorizedHistory_Error)) { returnResult.StrList_Error.Add(str_SaveAuthorizedHistory_Error); } else { string sessionKey = Guid.NewGuid().ToString(); BaseSession entity_BaseSession = new BaseSession(); entity_BaseSession.ID = entityVM_exist.ID; entity_BaseSession.SessionKey = sessionKey; entity_BaseSession.IpAddress = str_IpAdd; entity_BaseSession.LastOperationDt = DateTime.Now; WCFAuthInfoVM entity_WCFAuthInfoVM = new WCFAuthInfoVM(str_IpAdd, str_HostName, "", "", "", "", ""); WCFSesssionPolicy wcfPolicy = new WCFSesssionPolicy(); wcfPolicy.StoreWCFSession(entity_WCFAuthInfoVM, entity_BaseSession); #region [ Set Client Authorized Info ] SessionWUserInfo entity_SessionWUserInfo = loginUserRespo.GetLoginUserAccRight(entity_BaseSession.ID); if (entity_SessionWUserInfo != null) { entity_SessionWUserInfo.SessionKey = Guid.NewGuid().ToString(); entity_SessionWUserInfo.IpAddress = entity_WCFAuthInfoVM.IpAddress; entity_SessionWUserInfo.LastOperationDt = DateTime.Now; } #endregion returnResult.Entity_SessionWUserInfo = entity_SessionWUserInfo; if (entityVM_exist.LastPwdMDT.HasValue) { returnResult.IsPWDExpire = entityVM_exist.LastPwdMDT.Value.AddDays(((SystemInfoVM)StaticContent.SystemInfoInst).Password_ExpireDays) <= DateTime.Now.Date; } returnResult.Str_ServerToken = entity_WCFAuthInfoVM.WCFAuthorizedKey; } } } else { List <string> strList_UpdateFailCount_Error = new List <string>(); loginUserRespo.UpdateFailCount(entityVM_exist, languageKey_Input, ref strList_UpdateFailCount_Error); returnResult.StrList_Error.Add(str_E008); if (strList_UpdateFailCount_Error.Count > 0) { foreach (var item in strList_UpdateFailCount_Error) { returnResult.StrList_Error.Add(item); } } } } } else { returnResult.StrList_Error.Add(str_E008); } } return(returnResult); } catch (Exception ex) { throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message); } }