public static RequestResult GetCreateFormModel(Account account) { RequestResult requestResult = new RequestResult(); try { requestResult = GetWebPermissions(); if (requestResult.IsSuccess) { requestResult.ReturnData(new CreateFormModel() { AncestorOrganizationId = OrganizationDataAccessor.GetAncestorOrganizationId(account.OrganizationId).ToString(), WebPermissionFunction = new WebPermissionFunctionModel() { WebPermissions = requestResult.Data as List <WebPermissionModel> } }); } } catch (Exception e) { var error = new Error(MethodBase.GetCurrentMethod(), e); Logger.Log(error); requestResult.ReturnError(error); //throw; } return(requestResult); }
public static RequestResult GetEditFormModel(string roleId, Account account) { RequestResult requestResult = new RequestResult(); try { requestResult = GetWebPermissions(); if (requestResult.IsSuccess) { using (CFContext context = new CFContext()) { var role = context.Roles.First(r => r.RoleId == roleId); requestResult.ReturnData(new EditFormModel() { AncestorOrganizationId = OrganizationDataAccessor.GetAncestorOrganizationId(account.OrganizationId).ToString(), RoleId = role.RoleId, WebPermissionFunction = new WebPermissionFunctionModel() { WebPermissions = requestResult.Data as List <WebPermissionModel>, RoleWebPermissionFunctions = context.RolePermissionFunctions.Where(wpwf => wpwf.RoleId == role.RoleId).Select(wpwf => new Models.Role.RoleWebPermissionFunctionModel { RoleId = wpwf.RoleId, WebPermissionId = wpwf.WebPermissionId, WebFunctionId = wpwf.WebFunctionId }).ToList() }, FormInput = new FormInput() { RoleId = role.RoleId, Name = role.Name }, People = (from p in role.People join o in context.Organizations on p.OrganizationId equals o.OrganizationId select new Models.Role.PersonModel { OrganizationName = o.Name, PId = p.LoginId, PersonName = p.Name }).OrderBy(x => x.OrganizationName).ThenBy(x => x.PId).ToList() }); } } } catch (Exception e) { var error = new Error(MethodBase.GetCurrentMethod(), e); Logger.Log(error); requestResult.ReturnError(error); //throw; } return(requestResult); }
public static RequestResult Query(QueryParameters queryParameters, Account account) { RequestResult requestResult = new RequestResult(); try { using (CFContext context = new CFContext()) { var downStreamOrganizations = OrganizationDataAccessor.GetDownStreamOrganizationIds(new Guid(queryParameters.OrganizationId), true); var query = (from p in context.People join o in context.Organizations on p.OrganizationId equals o.OrganizationId where downStreamOrganizations.Contains(p.OrganizationId) && account.QueryableOrganizationIds.Contains(p.OrganizationId) select new { Person = p, OrganizationName = o.Name }).AsQueryable(); if (!string.IsNullOrEmpty(queryParameters.Keyword)) { query = query.Where(x => x.Person.Title.Contains(queryParameters.Keyword) || x.Person.LoginId.Contains(queryParameters.Keyword) || x.Person.Name.Contains(queryParameters.Keyword)); } var organization = OrganizationDataAccessor.GetOrganization(new Guid(queryParameters.OrganizationId)); var items = query.ToList(); var model = new GridViewModel() { Permission = account.OrganizationPermission(new Guid(queryParameters.OrganizationId)), OrganizationId = queryParameters.OrganizationId, OrganizationName = organization.Name, FullOrganizationName = organization.FullName, Items = items.Select(x => new GridItem() { Permission = account.OrganizationPermission(x.Person.OrganizationId), OrganizationName = x.OrganizationName, Title = x.Person.Title, Id = x.Person.LoginId, Name = x.Person.Name, Email = x.Person.Email, IsMobilePerson = x.Person.IsMobilePerson, RoleNameList = x.Person.Roles.Select(r => r.Name).ToList() }).OrderBy(x => x.OrganizationName).ThenBy(x => x.Title).ThenBy(x => x.Id).ToList() }; var ancestorOrganizationId = OrganizationDataAccessor.GetAncestorOrganizationId(new Guid(queryParameters.OrganizationId)); var downStreams = OrganizationDataAccessor.GetDownStreamOrganizations(ancestorOrganizationId, true); foreach (var downStream in downStreams) { if (account.EditableOrganizationIds.Any(x => x == downStream)) { model.MoveToTargets.Add(new MoveToTarget() { Id = downStream, Name = OrganizationDataAccessor.GetOrganizationFullName(downStream), Direction = Define.EnumMoveDirection.Down }); } } model.MoveToTargets = model.MoveToTargets.OrderBy(x => x.Name).ToList(); requestResult.ReturnData(model); } } catch (Exception e) { var error = new Error(MethodBase.GetCurrentMethod(), e); Logger.Log(error); requestResult.ReturnError(error); //throw; } return(requestResult); }