Exemplo n.º 1
0
        public async Task <ApiResult <IEnumerable <CertificateViewModel> > > List(int pageIndex, string Title, int?ProviderID, string ProjectID, bool?IsEnable)
        {
            var res = new ApiResult <IEnumerable <CertificateViewModel> >()
            {
                statusCode = (int)ApiEnum.Status
            };

            if (pageIndex == 0)
            {
                pageIndex = 1;
            }
            var parm = Expressionable.Create <Certificate>()
                       .AndIF(ProviderID != null && ProviderID != 0, a => a.ProviderID == ProviderID)
                       .AndIF(!string.IsNullOrEmpty(Title), m => m.Title.Contains(Title))
                       .AndIF(!string.IsNullOrEmpty(ProjectID), m => m.ProjectID == ProjectID)
                       .AndIF(IsEnable != null, m => m.IsEnable == IsEnable);
            var list = Certificatedb.GetPages(parm.ToExpression(), new PageParm(pageIndex));
            List <CertificateViewModel> list2 = new List <CertificateViewModel>();

            if (list.DataSource != null && list.DataSource.Count > 0)
            {
                foreach (var item in list.DataSource)
                {
                    CertificateViewModel n           = IMapper.Map <CertificateViewModel>(item);
                    ProjectInfo          projectInfo = Projectdb.Get("Projects", item.ProjectID);
                    if (projectInfo != null)
                    {
                        n.ProjectName = projectInfo.Names;
                    }
                    Provider provider = providerdb.GetId(item.ProviderID);
                    if (provider != null)
                    {
                        n.ProviderName = provider.Title;
                    }
                    list2.Add(n);
                }
                res.success = true;
                res.data    = list2;
                res.index   = pageIndex;
                res.count   = list.TotalCount;
                res.size    = list.PageSize;
                res.pages   = list.TotalPages;
            }
            else
            {
                res.success    = false;
                res.statusCode = (int)ApiEnum.Status;
            }
            return(await Task.Run(() => res));
        }