public JsonResult UserRoleChange(int id, string userRole) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int companyId = Convert.ToInt32(dictionary[1].Id == "" ? 0 : Convert.ToInt32(dictionary[1].Id)); if (companyId != 0) { _userGroupFactory = new UserGroupFactory(); _userFactory = new UserFactory(); int userId = Convert.ToInt32(dictionary[3].Id); SEC_UserInformation user = _userFactory.FindBy(x => x.ID == userId).FirstOrDefault(); SEC_UserGroup userGroup = _userGroupFactory.FindBy(x => x.ID == user.UserGroupID).FirstOrDefault(); if (userGroup != null && userGroup.IsAdmin) { SEC_UserGroup role = _userGroupFactory.FindBy(x => x.Name == userRole).FirstOrDefault(); _userFactory = new UserFactory(); SEC_UserInformation tblUserInformation = _userFactory.FindBy(x => x.ID == id).FirstOrDefault(); if (tblUserInformation != null) { tblUserInformation.UserGroupID = role.ID; _userFactory.Edit(tblUserInformation); } _userFactory.Save(); return(Json(new { success = true, message = "Sucessifuly changed the user role" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "You are not Admin User" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult UserGroupSave(SEC_UserGroup userGroup) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); int empId = Convert.ToInt32(dictionary[1].Id); if (userId != 0) { _securityFactory = new SecurityFactorys(); if (userGroup.ID < 1) { userGroup.CreatedBy = empId; userGroup.CreatedDate = DateTime.Now; } result = _securityFactory.SaveUserGroupWithPageMapping(userGroup); if (result.isSucess) { return(Json(result)); } return(Json(result)); } Session["logInSession"] = null; return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult ActiveDeActiveUser(int id, bool status) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupId = Convert.ToInt32(dictionary[6].Id == "" ? 0 : Convert.ToInt32(dictionary[6].Id)); if (userGroupId != 0) { ISecurityFactory _securityLogInFactory = new SecurityFactorys(); PagePermissionVM tblUserActionMapping = _securityLogInFactory.GetCrudPermission(userGroupId, "User"); if (tblUserActionMapping.Edit) { _userGroupFactory = new UserGroupFactory(); _userFactory = new UserFactory(); int userId = Convert.ToInt32(dictionary[3].Id); SEC_UserInformation user = _userFactory.FindBy(x => x.ID == userId).FirstOrDefault(); SEC_UserGroup userGroup = _userGroupFactory.FindBy(x => x.ID == user.UserGroupID).FirstOrDefault(); if (userGroup != null && userGroup.IsAdmin) { _userFactory = new UserFactory(); SEC_UserInformation tblUserInformation = _userFactory.FindBy(x => x.ID == id).FirstOrDefault(); if (tblUserInformation != null) { tblUserInformation.IsActive = status; _userFactory.Edit(tblUserInformation); } _userFactory.Save(); if (status) { return(Json(new { success = true, message = "Sucessifuly activeted the User" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, message = "Sucessifuly de-activeted the User" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "You are not Admin User" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "You has no permission for edit" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult EditUserGroupSave(SEC_UserGroup userGroup, List <MenuItemVM> userMappingVm = null) { try { _securityFactory = new SecurityFactorys(); Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); if (userId != 0) { result = _securityFactory.EditUserGroupPagePermission(userGroup, userMappingVm); if (result.isSucess) { return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); } Session["logInSession"] = null; return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public Result EditUserGroupPagePermission(SEC_UserGroup userGroup, List <MenuItemVM> userMappingVm = null) { Result _result = new Result(); using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); _userGroupFactory = new UserGroupFactory(); if (userGroup != null) { userGroup.UpdatedBy = userId; userGroup.UpdatedDate = DateTime.Now; _userGroupFactory.Edit(userGroup); _result = _userGroupFactory.Save(); } if (_result.isSucess) { if (userMappingVm != null) { _userActionMappingFactory = new UserActionMappingFactory(); int userGroupId = Convert.ToInt32(userGroup.ID); List <SEC_UserActionMapping> userMappingList = _userActionMappingFactory.FindBy(x => x.UserGroupID == userGroupId).ToList(); foreach (var item in userMappingVm) { SEC_UserActionMapping userMapping = userMappingList.FirstOrDefault(x => x.UIPageID == item.PageId); if (userMapping != null) { userMapping.IsSelect = item.Select != null ? (bool)item.Select : userMapping.IsSelect; userMapping.IsCreate = item.Create != null ? (bool)item.Create : userMapping.IsCreate; userMapping.IsEdit = item.Edit != null ? (bool)item.Edit : userMapping.IsEdit; userMapping.IsDelete = item.Delete != null ? (bool)item.Delete : userMapping.IsDelete; userMapping.UpdatedDate = DateTime.Now; userMapping.UpdatedBy = userId; _userActionMappingFactory.Edit(userMapping); } _result = _userActionMappingFactory.Save(); } if (_result.isSucess) { _result.message = _result.UpdateSuccessfull(tableName); dbContextTransaction.Commit(); } else { _result.isSucess = false; dbContextTransaction.Rollback(); } } } return(_result); } catch (Exception ex) { _result.isSucess = false; dbContextTransaction.Rollback(); return(_result); } } }
public Result SaveUserGroupWithPageMapping(SEC_UserGroup userGroup) { Result result = new Result(); using (var dbContextTransaction = context.Database.BeginTransaction()) { try { _userGroupFactory = new UserGroupFactory(); _userGroupFactory.Add(userGroup); bool isDuplicate = _userGroupFactory.FindBy(x => x.Name.ToLower().Trim() == userGroup.Name.ToLower().Trim()).Any(x => x.Name.ToLower() == userGroup.Name.ToLower()); if (!isDuplicate) { result = _userGroupFactory.Save(); _uiPageFactory = new UiPageFactory(); _userActionMappingFactory = new UserActionMappingFactory(); if (result.isSucess) { List <SEC_UIPage> uiPageList = _uiPageFactory.GetAll().ToList(); foreach (var item in uiPageList) { SEC_UserActionMapping userMappings = new SEC_UserActionMapping(); userMappings.UserGroupID = Convert.ToInt32(userGroup.ID); userMappings.UIModuleID = Convert.ToInt32(item.ModuleID); userMappings.UIPageID = item.ID; userMappings.IsSelect = false; userMappings.IsCreate = false; userMappings.IsEdit = false; userMappings.IsDelete = false; userMappings.CreatedDate = DateTime.Now; userMappings.CreatedBy = Convert.ToInt32(userGroup.CreatedBy); _userActionMappingFactory.Add(userMappings); } result = _userActionMappingFactory.Save(); } if (result.isSucess) { result.message = result.SaveSuccessfull(tableName); dbContextTransaction.Commit(); return(result); } else { result.isSucess = false; dbContextTransaction.Rollback(); return(result); } } result.message = "Your entared code is duplicate"; result.isSucess = false; dbContextTransaction.Commit(); return(result); } catch (Exception ex) { result.message = "Error occured"; result.isSucess = false; dbContextTransaction.Rollback(); } } return(result); }
public Result SaveUserGroupWithPagePermission(SEC_UserGroup userGroup, List <MenuItemVM> menuVm) { Result result = new Result(); using (var dbContextTransaction = context.Database.BeginTransaction()) { try { _userGroupFactory = new UserGroupFactory(); _userGroupFactory.Add(userGroup); bool isDuplicate = _userGroupFactory.FindBy(x => x.Name.ToLower().Trim() == userGroup.Name.ToLower().Trim()).Any(x => x.Name.ToLower() == userGroup.Name.ToLower()); if (!isDuplicate) { _userGroupFactory.Save(); _uiPageFactory = new UiPageFactory(); _userActionMappingFactory = new UserActionMappingFactory(); List <SEC_UIPage> uiPageList = _uiPageFactory.GetAll().ToList(); foreach (var item in uiPageList) { SEC_UserActionMapping userMappings = new SEC_UserActionMapping(); userMappings.UserGroupID = Convert.ToInt32(userGroup.ID); userMappings.UIModuleID = Convert.ToInt32(item.ModuleID); userMappings.UIPageID = item.ID; userMappings.IsSelect = false; userMappings.IsCreate = false; userMappings.IsEdit = false; userMappings.IsDelete = false; userMappings.CreatedDate = DateTime.Now; userMappings.CreatedBy = Convert.ToInt32(userGroup.CreatedBy); _userActionMappingFactory.Add(userMappings); } _userActionMappingFactory.Save(); if (menuVm != null) { int userGroupId = Convert.ToInt32(userGroup.ID); List <SEC_UserActionMapping> userMappingList = _userActionMappingFactory.FindBy(x => x.UserGroupID == userGroupId).ToList(); List <MenuItemVM> userMappingVmList = menuVm.Distinct().ToList(); foreach (var item in userMappingVmList) { SEC_UserActionMapping userMapping = new SEC_UserActionMapping(); userMapping = userMappingList.FirstOrDefault(x => x.UIPageID == item.PageId); if (userMapping != null) { userMapping.IsSelect = item.Select != null ? (bool)item.Select : userMapping.IsSelect; userMapping.IsCreate = item.Create != null ? (bool)item.Create : userMapping.IsCreate; userMapping.IsEdit = item.Edit != null ? (bool)item.Edit : userMapping.IsEdit; userMapping.IsDelete = item.Delete != null ? (bool)item.Delete : userMapping.IsDelete; _userActionMappingFactory.Edit(userMapping); } } _userActionMappingFactory.Save(); } result.message = "Saved Successfuly"; result.isSucess = true; dbContextTransaction.Commit(); return(result); } result.message = "Your entared code is duplicate"; result.isSucess = false; dbContextTransaction.Commit(); return(result); } catch (Exception ex) { result.message = "Error occured"; result.isSucess = false; dbContextTransaction.Rollback(); } } return(result); }
public Result PasswordChangeByAdminSave(ChangePasswordModel changePassword) { try { result = new Result(); result.isSucess = false; Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupID = Convert.ToInt32(dictionary[6].Id); int userId = Convert.ToInt32(dictionary[3].Id); string userName = dictionary[4].Id; if (userGroupID != 0) { _userFactory = new UserFactory(); _passwordFactory = new UserPasswordFactory(); _userGroup = new UserGroupFactory(); Encription encription = new Encription(); SEC_Password tblPassword; SEC_UserInformation tblUserInformation = new SEC_UserInformation(); SEC_UserGroup tblUserGroup = new SEC_UserGroup(); if (changePassword.FullName != "" || changePassword.UserName != "") { if (changePassword.UserName != null) { tblUserInformation = _userFactory.FindBy(x => x.UserName == changePassword.UserName).FirstOrDefault(); } tblUserGroup = _userGroup.FindBy(x => x.ID == userGroupID).FirstOrDefault(); if (tblUserGroup != null) { if (tblUserGroup.IsAdmin == false) { result.message = "You are not a Admin"; return(result); } tblPassword = _passwordFactory.GetAll().FirstOrDefault(x => x.ID == tblUserInformation.PasswordID); if (tblPassword != null) { tblPassword.OldPassword = tblPassword.NewPassword; tblPassword.NewPassword = encription.Encrypt(changePassword.NewPassword.Trim()); tblPassword.IsSelfChanged = false; tblPassword.UpdatedDate = DateTime.Now; tblPassword.UpdatedBy = userId; _passwordFactory.Edit(tblPassword); } result = _passwordFactory.Save(); if (result.isSucess) { result.message = "Changed Password Sucessfully"; return(result); } } result.message = "User cant found"; return(result); } result.message = "Password not Changed try again"; return(result); } result.message = "Logout"; } catch (Exception exception) { result.isSucess = false; result.message = exception.Message; return(result); } return(result); }