public async Task <IEnumerable <CaseListResponseModel> > GetExpertList(CaseListRequestModel request)
        {
            var result = await this.GetCaseList(request, MetadataTypes.ExpertMaterials);

            return(result);
        }
        public async Task <IEnumerable <CaseListResponseModel> > GetCaseList(CaseListRequestModel request,
                                                                             MetadataTypes type = MetadataTypes.CaseLaw)
        {
            var isSuper = this.currentUserService.IsSuperAdmin();
            var isAdmin = this.currentUserService.IsAdmin();

            this.context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            IQueryable <IMetaCase> query;

            if (type == MetadataTypes.Legislation)
            {
                query = this.context.Metadata.Include(x => x.User).ThenInclude(x => x.Organization)
                        .Where(c => c.IsDeleted == false);
            }
            else if (type == MetadataTypes.CaseLaw)
            {
                query = this.context.Cases.Include(x => x.User).ThenInclude(x => x.Organization)
                        .Where(c => c.IsDeleted == false);
            }
            else
            {
                query = this.context.ExpertMaterials.Include(x => x.User).ThenInclude(x => x.Organization)
                        .Where(c => c.IsDeleted == false);
            }

            if (request.Filter.IsNotNull() && isAdmin)
            {
                query = query.Where(x => EF.Functions.Like(x.User.UserName, $"%{request.Filter}%") ||
                                    EF.Functions.Like(x.Caption, $"%{request.Filter}%"));
            }

            //            else
            //            {
            //                if (!isAdmin)
            //                {
            //                    var userId = this.currentUserService.GetCurrentUserIdClaim();
            //                    query = query.Where(x => x.UserId == userId);
            //                }
            //            }
            //
            if (request.Organization.IsNotNull() && isSuper)
            {
                query = query.Where(x => x.User.Organization.ShortName == request.Organization);
            }
            //            else if (!isSuper)
            //            {
            //                var orgClaim = this.currentUserService.GetCurrentUserOrgClaim();
            //                query = query.Where(x => x.User.Organization.ShortName == orgClaim);
            //            }


            var tempRes = (from item in query
                           let content = JObject.Parse(item.Content)
                                         select new
            {
                item.Id,
                item.LastChange,
                item.Caption,
                item.User.UserName,
                Editable = this.HasEditDeleteRights(item.UserId, item.User.Organization.ShortName),
                OrgShortName = item.User.Organization.ShortName,
                Content = content,
                DocDate = content["dateOfDocument"]
            }).AsEnumerable();

            if (!string.IsNullOrWhiteSpace(request.JurisdictionCode))
            {
                tempRes = tempRes.Where(x =>
                {
                    var juri = x.Content["jurisdiction"];
                    if (juri != null && juri.Type != JTokenType.Null)
                    {
                        var jurisdictionCode = (string)juri["code"];
                        if (jurisdictionCode == request.JurisdictionCode)
                        {
                            return(true);
                        }
                    }

                    return(false);
                });
            }


            var result = tempRes.OrderByDescending(x =>
            {
                if (x.DocDate != null && x.DocDate.Type != JTokenType.Null)
                {
                    return((DateTime)x.DocDate);     // trusting JsonConvert for now >_>
                }

                return(x.LastChange);
            })
                         .Select(x => new CaseListResponseModel
            {
                CaseId       = x.Id,
                LastChange   = x.LastChange,
                Title        = x.Caption,
                UserName     = x.UserName,
                Editable     = x.Editable,
                Organization = x.OrgShortName,
                DocDate      = (x.DocDate != null && x.DocDate.Type != JTokenType.Null)
                        ? (DateTime)x.DocDate
                        : (DateTime?)null
            });


            return(result.ToList());
        }
        public async Task <IActionResult> GetExpertListAsync([FromBody] CaseListRequestModel request)
        {
            var data = await this.service.GetExpertList(request);

            return(this.Ok(data));
        }
        public async Task <IEnumerable <CaseListResponseModel> > GetMetadataList(CaseListRequestModel request)
        {
            var result = await this.GetCaseList(request, MetadataTypes.Legislation);

            return(result);
        }
Пример #5
0
        public async Task <object> GetMetadataList(CaseListRequestModel request)
        {
            var result = await this.GetCaseList(request, true);

            return(result);
        }