Пример #1
0
        public CredentialResultDTO Get(string id)
        {
            var p = fcpa.fcpa_CredentialInfo.Find(new Guid(id));

            Mapper.Initialize(m => m.CreateMap <fcpa_DistributorInfo, DistributorResultDTO>());
            return(new CredentialResultDTO
            {
                ID = p.ID,
                Distributor = Mapper.Map <fcpa_DistributorInfo, DistributorResultDTO>(p.fcpa_DistributorInfo),
                DistributorName = p.fcpa_DistributorInfo.DistributorName,
                Certificate = p.Certificate,
                Status = p.Status,
                Name = p.Name,
                Department = p.Department,
                Title = p.Title,
                CompletedDate = p.CompletedDate,
                OffWork = p.OffWork,
                OffWorkDate = p.OffWorkDate,
                Domain1 = p.Domain1,
                Domain2 = p.Domain2,
                Domain = p.Domain1 + "," + p.Domain2,
                UpdateDate = p.UpdateDate,
                ExpireDate = p.ExpireDate,
                Remark = p.Remark,
                StatusDesc = Const.Status(p.Status),
                OffWorkDesc = Const.Offwork(p.OffWork, p.OffWorkDate),
                DomainDesc = Const.Domain(p.Domain1, p.Domain2)
            });
        }
Пример #2
0
        public PageableDTO <CredentialResultDTO> Query(FcpaSearchDTO q)
        {
            var token = q.UserInfo;

            q.InitQuery("ID");
            var status   = q.Status.ToIntArray();
            var offworks = q.OffWork.ToBoolArray();
            var areas    = q.Area.ToStringArray();

            q.UserDistributorIDs = string.Join(",", token.DistributorIDs);
            var queryable = fcpa.fcpa_CredentialInfo.Where(p =>
                                                           (string.IsNullOrEmpty(q.Status) ? true : status.Any(a => p.Status == a)) &&
                                                           (q.Year.HasValue ? p.UpdateDate.HasValue && p.UpdateDate.Value.Year == q.Year : true) &&
                                                           (q.Year.HasValue ? p.UpdateDate.HasValue && p.UpdateDate.Value.Year == q.Year : true) &&
                                                           (string.IsNullOrEmpty(q.Area) ? true : areas.Any(a => p.fcpa_DistributorInfo.AreaName == a)) &&
                                                           (string.IsNullOrEmpty(q.Region) ? true : p.fcpa_DistributorInfo.RegionName.Contains(q.Region)) &&
                                                           (string.IsNullOrEmpty(q.DistributorName) ? true : p.fcpa_DistributorInfo.DistributorName.Contains(q.DistributorName)) &&
                                                           (string.IsNullOrEmpty(q.Name) ? true : p.Name.Contains(q.Name)) &&
                                                           (string.IsNullOrEmpty(q.Department) ? true : p.Department.Contains(q.Department)) &&
                                                           (string.IsNullOrEmpty(q.Title) ? true : p.Title.Contains(q.Title)) &&
                                                           (q.CompletedDateFrom.HasValue ? p.CompletedDate >= q.CompletedDateFrom : true) &&
                                                           (q.CompletedDateTo.HasValue ? p.CompletedDate <= q.CompletedDateTo : true) &&
                                                           (q.UpdateDateFrom.HasValue ? p.UpdateDate >= q.UpdateDateFrom : true) &&
                                                           (q.UpdateDateTo.HasValue ? p.UpdateDate <= q.UpdateDateTo : true) &&
                                                           (string.IsNullOrEmpty(q.OffWork) ? true : offworks.Any(a => p.OffWork.HasValue && p.OffWork.Value == a)) &&
                                                           (q.Domain1.HasValue ? p.Domain1 == q.Domain1 : true) &&
                                                           (q.Domain2.HasValue ? p.Domain2 == q.Domain2 : true) &&
                                                           (string.IsNullOrEmpty(q.Remark) ? true : p.Remark.Contains(q.Remark))
                                                           )
                            .Where(p => token.Role == 0 ? true : q.UserDistributorIDs.Contains(p.fcpa_DistributorInfo.DistributorID))
                            .Where(p => string.IsNullOrEmpty(q.DistributorID) ? true : q.DistributorID.Contains(p.fcpa_DistributorInfo.DistributorID));
            var res = queryable.ToPageable(q);

            Mapper.Initialize(m => m.CreateMap <fcpa_DistributorInfo, DistributorResultDTO>());
            var resultList = res.rows.Select(p => new CredentialResultDTO
            {
                ID              = p.ID,
                Distributor     = Mapper.Map <fcpa_DistributorInfo, DistributorResultDTO>(p.fcpa_DistributorInfo),
                DistributorName = p.fcpa_DistributorInfo.DistributorName,
                Certificate     = p.Certificate,
                Status          = p.Status,
                Name            = p.Name,
                Department      = p.Department,
                Title           = p.Title,
                CompletedDate   = p.CompletedDate,
                OffWork         = p.OffWork,
                OffWorkDate     = p.OffWorkDate,
                Domain1         = p.Domain1,
                Domain2         = p.Domain2,
                Domain          = p.Domain1 + "," + p.Domain2,
                UpdateDate      = p.UpdateDate,
                ExpireDate      = p.ExpireDate,
                Remark          = p.Remark,
                StatusDesc      = Const.Status(p.Status),
                OffWorkDesc     = Const.Offwork(p.OffWork, p.OffWorkDate),
                DomainDesc      = Const.Domain(p.Domain1, p.Domain2)
            }).ToList();

            return(new PageableDTO <CredentialResultDTO>
            {
                rows = resultList,
                total = res.total
            });
        }