コード例 #1
0
ファイル: PersonDataAccessor.cs プロジェクト: dvcsgit/CF
        public static RequestResult GetCreateFormModel(Guid organizationId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    requestResult.ReturnData(new CreateFormModel()
                    {
                        OrganizationId             = organizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(organizationId),
                        RoleModels = context.Roles.Select(r => new RoleModel {
                            RoleId = r.RoleId, RoleName = r.Name
                        }).OrderBy(r => r.RoleId).ToList()
                    });
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
コード例 #2
0
ファイル: PersonDataAccessor.cs プロジェクト: dvcsgit/CF
        public static RequestResult GetDetailViewModel(string pId, Account account)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.First(p => p.LoginId == pId);

                    requestResult.ReturnData(new DetailViewModel()
                    {
                        Permission                 = account.OrganizationPermission(person.OrganizationId),
                        OrganizationId             = person.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(person.OrganizationId),
                        PId            = person.LoginId,
                        Name           = person.Name,
                        EMail          = person.Email,
                        Title          = person.Title,
                        IsMobilePerson = person.IsMobilePerson,
                        RoleNames      = person.Roles.Select(r => r.Name).ToList()
                    });
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
コード例 #3
0
ファイル: PersonDataAccessor.cs プロジェクト: dvcsgit/CF
        public static RequestResult GetCopyFormModel(string pId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.First(p => p.LoginId == pId);

                    requestResult.ReturnData(new CreateFormModel()
                    {
                        OrganizationId             = person.Organization.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(person.OrganizationId),
                        RoleModels = context.Roles.Select(r => new RoleModel {
                            RoleId = r.RoleId, RoleName = r.Name
                        }).OrderBy(r => r.RoleId).ToList(),
                        FormInput = new FormInput()
                        {
                            Title          = person.Title,
                            IsMobilePerson = person.IsMobilePerson
                        }
                    });
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                throw;
            }

            return(requestResult);
        }
コード例 #4
0
ファイル: PersonDataAccessor.cs プロジェクト: dvcsgit/CF
        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);
        }