protected void Button47_Click(object sender, EventArgs e) { BPrecard bus = new BPrecard(); IList <Role> roleList = new List <Role>(); roleList.Add(new Role() { ID = 2 }); roleList.Add(new Role() { ID = 4 }); roleList.Add(new Role() { ID = 5 }); roleList.Add(new Role() { ID = 6 }); bus.UpdateRoleAccess(2, roleList); NHibernateSessionManager.Instance.ClearSession(); BRole bus2 = new BRole(); Role r = bus2.GetByID(2); NHibernateSessionManager.Instance.ClearSession(); BRequest u2 = new BRequest(); u2.GetAllDailyLeaves(); }
/// <summary> /// ارسال پیام خرابی سیستم /// </summary> /// <param name="subject"></param> /// <param name="message"></param> public void NewMessage(string subject, string message) { try { IList <User> toPrsList = new BRole().GetUsersInSysAdminRole(); var persons = from o in toPrsList where o.Active && o.Person.Active && !o.Person.IsDeleted select o.Person; foreach (Person person in persons) { PrivateMessage msg = new PrivateMessage(); msg.Subject = subject; msg.Message = message; msg.FromPersonID = BUser.CurrentUser.Person.ID; msg.Date = DateTime.Now; msg.ToPersonID = person.ID; msg.ToActive = true; msg.FromActive = true; base.SaveChanges(msg, UIActionType.ADD); } } catch (Exception ex) { LogException(ex, "BPrivateMessage", "NewMessage To Sys Admin"); throw ex; } }
public RoleResult Edit(int id, BRole bRole) { RoleResult roleResult = new RoleResult(); using (_context = new GroupsManagementDbEntities()) { try { Role role = _context.Roles.FirstOrDefault(r => r.RoleId == id); if (role != null) { role.RoleName = bRole.Name; _context.SaveChanges(); roleResult.bRoles.Add(Conversions.ConvertRoleToBRole(role)); } else { roleResult.IsValid = false; roleResult.ErrorMessages.Add("This role doesn't exist."); } } catch (Exception e) { roleResult.IsValid = false; roleResult.ErrorMessages.Add(e.Message); } } return(roleResult); }
public RoleResult Add(BRole bRole) { RoleResult roleResult = new RoleResult(); using (_context = new GroupsManagementDbEntities()) { using (var transaction = _context.Database.BeginTransaction()) { try { Role role = new Role() { RoleName = bRole.Name }; _context.Roles.Add(role); _context.SaveChanges(); transaction.Commit(); roleResult.bRoles.Add(Conversions.ConvertRoleToBRole(role)); } catch (Exception e) { roleResult.IsValid = false; roleResult.ErrorMessages.Add(e.Message); } } } return(roleResult); }
public override void Validate(string userName, string password) { if (Utility.IsEmpty(userName) || Utility.IsEmpty(password)) { throw new IllegalServiceAccess("نام کاربری و یا کلمه عبور نا معتبر است", "Business WS"); } BLogin securitySerivce = new BLogin(); bool isAuthenticate = securitySerivce.IsAuthenticate(userName, password); if (!isAuthenticate) { throw new IllegalServiceAccess("کاربر قابل شناسایی نمیباشد", "Business WS Authentication"); } BRole busRole = new BRole(); if (!busRole.HasAccessToResource(userName, WebserivceResourceKey)) { throw new IllegalServiceAccess("اجازه دسترسی به سرویس را ندارید", "Business WS Authorization"); } else { return; } }
private List <Resource> getAccess() { personId = BUser.CurrentUser.Person.ID; roleId = BUser.CurrentUser.Role.ID; roleCustomeCode = BUser.CurrentUser.Role.CustomCode; #region GetAllowedResource BRole busRole = new BRole(); List <Resource> accessAllowedResourceList = new List <Resource>(); accessAllowedResourceList.AddRange(busRole.GetAlowedResourceList(roleId)); #region Apply Other Business Roles IList <RoleCustomCodeType> otherRoles = this.GetCurrentUserBusinessRole(); Dictionary <string, object> managementState = (Dictionary <string, object>)SessionHelper.GetSessionValue(SessionHelper.GTSCurrentUserManagmentState); if (otherRoles.Count > 0) { foreach (RoleCustomCodeType roleCode in otherRoles) { decimal tmpRoleId = 0; switch (roleCode) { case RoleCustomCodeType.Manager: if (managementState.ContainsKey("ManagerRoleId")) { tmpRoleId = Utility.ToDecimal(managementState["ManagerRoleId"]); } break; case RoleCustomCodeType.Substitute: if (managementState.ContainsKey("SubstituteRoleId")) { tmpRoleId = Utility.ToDecimal(managementState["SubstituteRoleId"]); } break; case RoleCustomCodeType.Operator: if (managementState.ContainsKey("OperatorRoleId")) { tmpRoleId = Utility.ToDecimal(managementState["OperatorRoleId"]); } break; } if (tmpRoleId > 0) { accessAllowedResourceList.AddRange(busRole.GetAlowedResourceList(tmpRoleId)); } } accessAllowedResourceList = accessAllowedResourceList.Distinct().OrderBy(c => c.ID).ToList(); } #endregion #endregion return(accessAllowedResourceList); }
public void TestSetup() { role_testObject = new Role(); busRole = new BRole(); DatabaseGateway.TA_SecurityRoleDataTable roleTable = new DatabaseGateway.TA_SecurityRoleDataTable(); roleTable = roleTA.GetRoot(); if (roleTable.Rows.Count == 0) { roleTA.Insert("TestLevel1", 0, true, "", "000-0"); roleTable = roleTA.GetRoot(); } ADORootRole.ID = Convert.ToInt32(roleTable.Rows[0]["role_ID"]); roleTA.Insert("TestRuleName1", ADORootRole.ID, true, "", "000-1"); roleTable = roleTA.GetDataByRoleName("TestRuleName1"); ADORole1.ID = Convert.ToInt32(roleTable.Rows[0]["role_ID"]); ADORole1.Name = Convert.ToString(roleTable.Rows[0]["role_name"]); ADORole1.CustomCode = Convert.ToString(roleTable.Rows[0]["role_customcode"]); roleTA.Insert("TestRuleName2", ADORole1.ID, true, "", "000-2"); roleTable = roleTA.GetDataByRoleName("TestRuleName2"); ADORole2.ID = Convert.ToInt32(roleTable.Rows[0]["role_ID"]); ADORole2.Name = Convert.ToString(roleTable.Rows[0]["role_name"]); ADORole2.CustomCode = Convert.ToString(roleTable.Rows[0]["role_customcode"]); DatabaseGateway.TA_SecurityResourceDataTable resourceTable = new DatabaseGateway.TA_SecurityResourceDataTable(); resourceTable = resourceTA.GetRoot(); if (resourceTable.Rows.Count == 0) { resourceTA.Insert("TestRootResource", 0, "", "", "", ""); resourceTable = resourceTA.GetRoot(); } ADORootResource.ID = Convert.ToInt32(resourceTable.Rows[0][0]); resourceTA.Insert("TestResource1", ADORootResource.ID, "", "", "", "," + ADORootResource.ID.ToString() + ","); resourceTable = resourceTA.GetDataByName("TestResource1"); ADORedource1.ID = Convert.ToInt32(resourceTable.Rows[0][0]); ADORedource1.ResourceID = Convert.ToString(resourceTable.Rows[0]["resource_ResourceID"]); resourceTA.Insert("TestResource2", ADORootResource.ID, "", "", "", "," + ADORootResource.ID.ToString() + ","); resourceTable = resourceTA.GetDataByName("TestResource2"); ADORedource2.ID = Convert.ToInt32(resourceTable.Rows[0][0]); ADORedource2.ResourceID = Convert.ToString(resourceTable.Rows[0]["resource_ResourceID"]); resourceTA.Insert("TestResource3", ADORedource1.ID, "", "", "", "," + ADORootResource.ID.ToString() + "," + ADORedource1.ID.ToString() + ","); resourceTable = resourceTA.GetDataByName("TestResource3"); ADORedource3.ID = Convert.ToInt32(resourceTable.Rows[0][0]); ADORedource3.ResourceID = Convert.ToString(resourceTable.Rows[0]["resource_ResourceID"]); //athorizeTA.Insert(ADORole1.ID, ADORootResource.ID,true); athorizeTA.Insert(ADORole1.ID, ADORedource1.ID, true); athorizeTA.Insert(ADORole1.ID, ADORedource2.ID, false); }
public static BRole ConvertRoleToBRole(Role role) { BRole bRole = new BRole() { RoleId = role.RoleId, Name = role.RoleName }; return(bRole); }
public HttpResponseMessage PostNewRole(BRole bRole) { RoleResult roleResult = roleService.Add(bRole); HttpResponseMessage response; if (roleResult.IsValid) { response = Request.CreateResponse(HttpStatusCode.OK, roleResult.bRoles.Single()); return(response); } response = Request.CreateResponse(HttpStatusCode.BadRequest, roleResult.ErrorMessages); return(response); }
public HttpResponseMessage UpdateRole(int id, BRole bRole) { RoleResult roleResult = roleService.Edit(id, bRole); HttpResponseMessage response; if (roleResult.IsValid) { response = Request.CreateResponse(HttpStatusCode.OK, roleResult.bRoles.Single()); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, roleResult.ErrorMessages); } return(response); }
public async Task <ActionResult> UpdateRole(int id, BRole bRole) { try { string apiUrl = string.Format("{0}/{1}", roleApiUrl, id); var content = new StringContent(JsonConvert.SerializeObject(bRole), Encoding.UTF8, "application/json"); var response = await client.PutAsync(apiUrl, content); response.EnsureSuccessStatusCode(); var data = response.Content.ReadAsStringAsync(); } catch (Exception e) { return(Content(e.Message)); } return(RedirectToAction("GetRole", new { id })); }
public async Task <ActionResult> EditRole(int id) { BRole bRole = null; try { string apiUrl = string.Format("{0}/{1}", roleApiUrl, id); var response = await client.GetAsync(apiUrl); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadAsStringAsync(); bRole = JsonConvert.DeserializeObject <BRole>(data); } catch (Exception e) { return(Content(e.Message)); } return(View(bRole)); }
public async Task <ActionResult> PostRole(BRole bRole) { BRole newBRole = null; try { var content = new StringContent(JsonConvert.SerializeObject(bRole), Encoding.UTF8, "application/json"); var response = await client.PostAsync(roleApiUrl, content); response.EnsureSuccessStatusCode(); var data = await response.Content.ReadAsStringAsync(); newBRole = JsonConvert.DeserializeObject <BRole>(data); } catch (Exception e) { ViewBag.error = true; return(Content(e.Message)); } return(RedirectToAction("GetRole", new { id = newBRole.RoleId })); }
/// <summary> /// چکیده اطلاعات پرسنل را بر می گرداند /// </summary> /// <returns>لیست چکیده اطلاعات پرسنل</returns> public IList <PersonInfoProxy> GetPersonInfo() { try { IList <PersonInfoProxy> list = new List <PersonInfoProxy>(); if (BUser.CurrentUser.Person != null) { Person currentPrs = new BPerson().GetByID(BUser.CurrentUser.Person.ID); PersonInfoProxy proxy = new PersonInfoProxy(); #region Person Name proxy.Active = true; proxy.Order = 1; proxy.Value = BUser.CurrentUser.Person.Name; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "نام"; } else { proxy.Title = "Name"; } proxy.Title += "<BR/>"; list.Add(proxy); #endregion #region Person Code proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 2; proxy.Value = currentPrs.PersonCode; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "شماره پرسنلی"; } else { proxy.Title = "Person Code"; } proxy.Title += "<BR/>"; list.Add(proxy); #endregion #region Employment Date proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 3; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Value = Utility.ToPersianDate(currentPrs.EmploymentDate); proxy.Title = "تاریخ استخدام"; } else { proxy.Value = Utility.ToString(currentPrs.EmploymentDate); proxy.Title = "Employ Date"; } if (currentPrs.EmploymentDate == Utility.GTSMinStandardDateTime) { proxy.Value = " --- "; } else { proxy.Title += "<BR/>"; list.Add(proxy); } #endregion #region Department Name if (currentPrs.Department != null) { proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 4; proxy.Value = currentPrs.Department.Name; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "نام بخش"; } else { proxy.Title = "Department Name"; } if (!Utility.IsEmpty(proxy.Value)) { proxy.Title += "<BR/>"; list.Add(proxy); } } #endregion #region Organization Unit Name /* * if (currentPrs.OrganizationUnit != null) * { * proxy = new PersonInfoProxy(); * proxy.Active = true; * proxy.Order = 5; * proxy.Value = currentPrs.OrganizationUnit.Name; * if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) * { * proxy.Title = "سمت"; * } * else * { * proxy.Title = "Organization Unit Name"; * } * list.Add(proxy); * } * */ #endregion #region Flow Manager GTS.Clock.Infrastructure.Repository.RequestStatusRepositiory reqStatusRep = new GTS.Clock.Infrastructure.Repository.RequestStatusRepositiory(false); IList <RegisteredRequestsFlowLevel> levels = reqStatusRep.GetRequestLevels(currentPrs.Department.ID, currentPrs.ID); if (levels != null && levels.Count > 0) { levels = levels.Where(x => x.FlowID == levels.First().FlowID).OrderBy(x => x.ManagerLevel).ToList(); proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 5; var managers = from manager in levels select manager.ManagerName; proxy.Value = string.Join(" , ", managers.ToArray <string>()); if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "مدیران"; } else { proxy.Title = "Managers"; } proxy.Title += "<BR/>"; list.Add(proxy); } #endregion #region UserRoles proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 6; proxy.Value = BUser.CurrentUser.Role.Name; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "نقش اصلی"; } else { proxy.Title = "Basic Role"; } proxy.Title += "<BR/>"; list.Add(proxy); if (SessionHelper.HasSessionValue(SessionHelper.GTSCurrentUserManagmentState)) { string separator = " , "; BRole bRole = new BRole(); Role role = null; proxy = new PersonInfoProxy(); proxy.Active = true; proxy.Order = 8; proxy.Value = string.Empty; if (BLanguage.CurrentLocalLanguage == LanguagesName.Parsi) { proxy.Title = "نقش های مجازی"; } else { proxy.Title = "Virtual Roles"; } proxy.Title += "<BR/>"; Dictionary <string, object> ManagementState = (Dictionary <string, object>)SessionHelper.GetSessionValue(SessionHelper.GTSCurrentUserManagmentState); if (ManagementState.ContainsKey("IsManager") && (bool)ManagementState["IsManager"] && ManagementState.ContainsKey("ManagerRoleId")) { role = bRole.GetByID((decimal)ManagementState["ManagerRoleId"]); proxy.Value = role.Name; this.NHSession.Evict(role); } if (ManagementState.ContainsKey("IsOperator") && (bool)ManagementState["IsOperator"] && ManagementState.ContainsKey("OperatorRoleId")) { role = bRole.GetByID((decimal)ManagementState["OperatorRoleId"]); if (proxy.Value != string.Empty) { proxy.Value += separator; } proxy.Value += role.Name; this.NHSession.Evict(role); } if (ManagementState.ContainsKey("IsSubstitute") && (bool)ManagementState["IsSubstitute"] && ManagementState.ContainsKey("SubstituteRoleId")) { role = bRole.GetByID((decimal)ManagementState["SubstituteRoleId"]); if (proxy.Value != string.Empty) { proxy.Value += separator; } proxy.Value += role.Name; this.NHSession.Evict(role); } if (proxy.Value != string.Empty) { list.Add(proxy); } } #endregion } return(list); } catch (Exception ex) { BaseBusiness <Entity> .LogException(ex, "BPersonInfoBoxService", "GetPersonInfo"); throw new Exception("خطا در بارگزاری اطلاعات شخصی"); } }
private IList <RoleCustomCodeType> GetCurrentUserBusinessRole() { try { IList <RoleCustomCodeType> roles = new List <RoleCustomCodeType>(); if (!SessionHelper.HasSessionValue(SessionHelper.GTSCurrentUserManagmentState)) { bool isManager = new BManager().GetManager(personId).ID > 0 ? true : false; bool isSubstitute = new BSubstitute().GetSubstituteManager(personId) > 0 ? true : false; bool isOperator = new BOperator().IsOperator(); Dictionary <string, object> ManagementState = new Dictionary <string, object>(); if (isManager) { Role role = new BRole().GetRoleByCode(RoleCustomCodeType.Manager); if (role != null) { ManagementState.Add("ManagerRoleId", role.ID); } } if (isOperator) { Role role = new BRole().GetRoleByCode(RoleCustomCodeType.Operator); if (role != null) { ManagementState.Add("OperatorRoleId", role.ID); } } if (isSubstitute) { Role role = new BRole().GetRoleByCode(RoleCustomCodeType.Substitute); if (role != null) { ManagementState.Add("SubstituteRoleId", role.ID); } } ManagementState.Add("IsManager", isManager); ManagementState.Add("IsOperator", isOperator); ManagementState.Add("IsSubstitute", isSubstitute); SessionHelper.SaveSessionValue(SessionHelper.GTSCurrentUserManagmentState, ManagementState); } Dictionary <string, object> managementState = (Dictionary <string, object>)SessionHelper.GetSessionValue(SessionHelper.GTSCurrentUserManagmentState); if (Utility.ToBoolean(managementState["IsManager"])) { roles.Add(RoleCustomCodeType.Manager); } if (Utility.ToBoolean(managementState["IsOperator"])) { roles.Add(RoleCustomCodeType.Operator); } if (Utility.ToBoolean(managementState["IsSubstitute"])) { roles.Add(RoleCustomCodeType.Substitute); } return(roles); } catch (Exception ex) { BaseBusiness <GTS.Clock.Model.Entity> .LogException(ex); throw ex; } }