private ExceptionTypes CreateSession(WorkBasket objWorkBasket) { ExceptionTypes result = ExceptionTypes.UnauthorizedAccessException; string[] strLoginName = System.Web.HttpContext.Current.User.Identity.Name.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); string domain = strLoginName[0]; string loginName = strLoginName[1]; string errorMessage = string.Empty; try { if (IsUserInADGroup()) { if (Session[ConstantTexts.CurrentUserSessionKey] == null) { BLUserAdministration objBLUserAdministration = new BLUserAdministration(); UserAdminstrationController objUserAdminstrationController = new UserAdminstrationController(); //check user access result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out UIUserLogin loggedInUser); if (result == ExceptionTypes.ZeroRecords) { //insert new User to DB, get details from LDAP bool isUserFound = objUserAdminstrationController.GetUserDetails(loginName, true, out DOADM_UserMaster objDOADM_UserMaster); if (isUserFound) { objDOADM_UserMaster.CreatedByRef = _currentLoginUserId; objDOADM_UserMaster.MSID = loginName; objDOADM_UserMaster.StartDate = DateTime.UtcNow.AddYears(-1); objDOADM_UserMaster.EndDate = DateTime.UtcNow.AddYears(30); objDOADM_UserMaster.lstDOADM_AccessGroupUserCorrelation = new List <DOADM_AccessGroupUserCorrelation>(); //AddAccessGroups(objDOADM_UserMaster); result = objBLUserAdministration.SaveUser(objDOADM_UserMaster, out errorMessage); } else { //user details not found in LDAP MIIMServiceLog(MethodBase.GetCurrentMethod().Name, "", "Session Creation failed for new User. LDAP details not found", _currentLoginUserId, TarceMethodLkup.Completed.ToLong(), (long)MIIMServiceMethod.GetCaseDetails); BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, "Session Creartion failed, LDAP Details not found", "CREATE session failed"); return(ExceptionTypes.UnknownError); } result = objBLUserAdministration.GetUserAccessPermission(loginName, null, null, null, out loggedInUser); } else if (result != ExceptionTypes.Success) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); return(result); } // Not adding access groups to MIIM user, so they should not be able to access ERS web application. //adding access groups if no access groups assigned //if (loggedInUser.UserSkills == null || loggedInUser.UserSkills.Count <= 0) //{ // DOADM_UserMaster objDOADM_UserMaster = new DOADM_UserMaster(); // objDOADM_UserMaster.IsActive = true; // objDOADM_UserMaster.MSID = loginName; // objDOADM_UserMaster = objUserAdminstrationController.GetUserSearchResult(objDOADM_UserMaster, out errorMessage).FirstOrDefault(); // AddAccessGroups(objDOADM_UserMaster); // objBLUserAdministration.SaveUser(objDOADM_UserMaster, out errorMessage); //} _currentLoginUserId = loggedInUser.ADM_UserMasterId; loggedInUser.WorkBasketLkup = (long)objWorkBasket; loggedInUser.BusinessSegmentLkup = (long)BusinessSegment.MNR; loggedInUser.RoleLkup = (long)RoleLkup.Processor; //login user result = objBLUserAdministration.LoginUser(loginName); if (result != (long)ExceptionTypes.Success) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, string.Empty, "Error while fetching logged in user data"); } //create session Session[ConstantTexts.CurrentUserSessionKey] = loggedInUser; return(ExceptionTypes.Success); } else { UIUserLogin loggedInUser = (UIUserLogin)Session[ConstantTexts.CurrentUserSessionKey]; _currentLoginUserId = loggedInUser.ADM_UserMasterId; //pick current user object and check access group is assigned //check user has access to AD group return(ExceptionTypes.Success); } } else { return(ExceptionTypes.UnauthorizedAccessException); } } catch (Exception ex) { BLCommon.LogError(_currentLoginUserId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.MIIMConnector, (long)ExceptionTypes.Uncategorized, ex.ToString(), ex.Message); return(ExceptionTypes.UnknownError); } }
public ActionResult Add(DOADM_UserMaster objDOADM_UserMaster) { string errorMessage = string.Empty; ExceptionTypes result = new ExceptionTypes(); string returnMessage = string.Empty; try { //check if this call is to update record or save new record if (objDOADM_UserMaster.ADM_UserMasterId > 0) { //if old record is to be updated BLCommon objCommon = new BLCommon(); //check if record is locked by current user if (!objCommon.ValidateLockBeforeSave(currentUser.ADM_UserMasterId, (long)ScreenType.UserAdmin, objDOADM_UserMaster.ADM_UserMasterId)) { //if record is not locked by current user dont save record and return error. errorMessage = "Record not locked, please reload the page."; result = ExceptionTypes.UnknownError; return(Json(new { ID = result, Message = errorMessage })); } returnMessage = "Record updated successfully."; } else { objDOADM_UserMaster.CreatedByRef = currentUser.ADM_UserMasterId; //If new record to be saved returnMessage = "Record saved successfully."; } objDOADM_UserMaster.FullName = objDOADM_UserMaster.FirstName != null ? objDOADM_UserMaster.LastName + ", " + objDOADM_UserMaster.FirstName : objDOADM_UserMaster.LastName; objDOADM_UserMaster.SpecialistFax = String.IsNullOrEmpty(objDOADM_UserMaster.SpecialistFax) ? "" : String.Join("", objDOADM_UserMaster.SpecialistFax.Split('-')); objDOADM_UserMaster.SpecialistPhone = String.IsNullOrEmpty(objDOADM_UserMaster.SpecialistPhone) ? "" : String.Join("", objDOADM_UserMaster.SpecialistPhone.Split('-')); objDOADM_UserMaster.UserZip = String.IsNullOrEmpty(objDOADM_UserMaster.UserZip) ? "" : String.Join("", objDOADM_UserMaster.UserZip.Split('-')); objDOADM_UserMaster.IsActive = objDOADM_UserMaster.IsActive; objDOADM_UserMaster.IsManager = objDOADM_UserMaster.IsManager; objDOADM_UserMaster.CreatedByRoleLkup = currentUser.RoleLkup; objDOADM_UserMaster.UpdatedByRoleLkup = currentUser.RoleLkup; objDOADM_UserMaster.LastUpdatedByRef = currentUser.ADM_UserMasterId; if (Session[ConstantTexts.UserAccessGroupSessionKey] != null) { objDOADM_UserMaster.lstDOADM_AccessGroupUserCorrelation = Session[ConstantTexts.UserAccessGroupSessionKey] as List <DOADM_AccessGroupUserCorrelation>; } BLUserAdministration objBLUserAdministration = new BLUserAdministration(); result = objBLUserAdministration.SaveUser(objDOADM_UserMaster, out errorMessage); if (result != (long)ExceptionTypes.Success) { BLCommon.LogError(currentUser.ADM_UserMasterId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.ManageUsers, (long)ExceptionTypes.Uncategorized, string.Empty, "error occured while saving data"); return(Json(new { ID = result, Message = "An error occured while updating DB." })); } return(Json(new { ID = result, Message = returnMessage })); } catch (Exception ex) { BLCommon.LogError(currentUser.ADM_UserMasterId, MethodBase.GetCurrentMethod().Name, (long)ErrorModuleName.ManageUsers, (long)ExceptionTypes.Uncategorized, string.Empty, ex.ToString()); return(RedirectToAction("Maintenance", "Error", new { Error = MethodBase.GetCurrentMethod().Name + " Action terminated and redirected to Maintenance. Error:" + ex.ToString() })); } }