Пример #1
0
        private static List <Autocomplete> LoadPeople()
        {
            var results = new List <Autocomplete>();

            using (DbEntities db = new DbEntities())
            {
                results = db.Osoba
                          .Where(o => o.Status == (int)Osoba.StatusOsobyEnum.Politik ||
                                 o.Status == (int)Osoba.StatusOsobyEnum.Sponzor)
                          //.Take(100).ToList()
                          .AsParallel()
                          .Select(o => new Autocomplete()
                {
                    Id           = $"osobaid:{o.NameId}",
                    Text         = $"{o.Prijmeni} {o.Jmeno}{AppendTitle(o.TitulPred, o.TitulPo)}",
                    Priority     = o.Status == (int)Osoba.StatusOsobyEnum.Politik ? 1 : 0,
                    Type         = o.StatusOsoby().ToNiceDisplayName(),
                    ImageElement = $"<img src='{o.GetPhotoUrl(false)}' />",
                    Description  = InfoFact.RenderInfoFacts(
                        o.InfoFacts().Where(i => i.Level != InfoFact.ImportanceLevel.Stat).ToArray(),
                        2, true, false, "", "{0}", false)
                }).ToList();
            }
            return(results);
        }
Пример #2
0
        private static List <Autocomplete> LoadPeople()
        {
            List <Autocomplete> results = new List <Autocomplete>();

            using (DbEntities db = new DbEntities())
            {
                Devmasters.Batch.Manager.DoActionForAll <Osoba>(db.Osoba
                                                                .Where(o => o.Status == (int)Osoba.StatusOsobyEnum.Politik ||
                                                                       o.Status == (int)Osoba.StatusOsobyEnum.Sponzor),

                                                                o =>
                {
                    var synonyms = new Autocomplete[2];
                    synonyms[0]  = new Autocomplete()
                    {
                        Id           = $"osobaid:{o.NameId}",
                        Text         = $"{o.Prijmeni} {o.Jmeno}{AppendTitle(o.TitulPred, o.TitulPo)}",
                        Priority     = o.Status == (int)Osoba.StatusOsobyEnum.Politik ? 2 : 0,
                        Type         = o.StatusOsoby().ToNiceDisplayName(),
                        ImageElement = $"<img src='{o.GetPhotoUrl(false)}' />",
                        Description  = InfoFact.RenderInfoFacts(
                            o.InfoFacts().Where(i => i.Level != InfoFact.ImportanceLevel.Stat).ToArray(),
                            2, true, false, "", "{0}", false)
                    };

                    synonyms[1]      = (Autocomplete)synonyms[0].MemberwiseClone();
                    synonyms[1].Text = $"{o.Jmeno} {o.Prijmeni}{AppendTitle(o.TitulPred, o.TitulPo)}";

                    lock (_loadPlock)
                    {
                        results.Add(synonyms[0]);
                        results.Add(synonyms[1]);
                    }

                    return(new Devmasters.Batch.ActionOutputData());
                }
                                                                , true
                                                                );
            }
            return(results);
        }
        public ActionResult NasiPolitici_GetData(string _id)
        {
            string id = _id;

            if (!Framework.ApiAuth.IsApiAuth(this,
                                             parameters: new Framework.ApiCall.CallParameter[] {
                new Framework.ApiCall.CallParameter("id", id),
            })
                .Authentificated)
            {
                Response.StatusCode = 401;
                return(Json(ApiResponseStatus.ApiUnauthorizedAccess, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var o = Osoba.GetByNameId(id);
                if (o == null)
                {
                    Response.StatusCode = 404;
                    return(Json(ApiResponseStatus.Error(404, "Politik not found"), JsonRequestBehavior.AllowGet));
                }
                if (o.StatusOsoby() != Osoba.StatusOsobyEnum.Politik)
                {
                    Response.StatusCode = 404;
                    return(Json(ApiResponseStatus.Error(404, "Person is not marked as politician"), JsonRequestBehavior.AllowGet));
                }

                var vazby = o.AktualniVazby(Relation.AktualnostType.Nedavny)
                            .Where(v => v.Distance == 1 && v.To?.Type == Graph.Node.NodeType.Company)
                            .Take(10)
                            .Select(v => new
                {
                    company     = Firma.FromIco(v.To.Id).Jmeno,
                    ico         = v.To.Id,
                    since       = v.RelFrom,
                    until       = v.RelTo,
                    description = v.Descr
                }).ToList();


                var statDescription =
                    InfoFact.RenderInfoFacts(
                        o.InfoFacts().Where(i => i.Level != InfoFact.ImportanceLevel.Stat).ToArray()
                        , 4, true, true, "", "{0}");

                var angazovanost =
                    InfoFact.RenderInfoFacts(
                        o.InfoFacts().Where(m => m.Level == InfoFact.ImportanceLevel.Stat).ToArray()
                        , 4, true, true, "", "{0}");


                int[] types =
                {
                    (int)OsobaEvent.Types.VolenaFunkce,
                    (int)OsobaEvent.Types.PolitickaPracovni,
                    (int)OsobaEvent.Types.Politicka,
                    (int)OsobaEvent.Types.VerejnaSpravaJine,
                    (int)OsobaEvent.Types.VerejnaSpravaPracovni,
                };
                //var funkceOsoba = o.Description(true,
                //        m => types.Contains(m.Type),
                //        20);

                var roleOsoba = o.Events(m =>
                                         types.Contains(m.Type) &&
                                         m.Status != (int)OsobaEvent.Statuses.NasiPoliticiSkryte)
                                .Select(e => new {
                    role         = e.AddInfo,
                    dateFrom     = e.DatumOd,
                    dateTo       = e.DatumDo,
                    organisation = e.Organizace
                })
                                .ToArray();

                string registrOznameni = o.Events(m =>
                                                  m.Type == (int)OsobaEvent.Types.CentralniRegistrOznameni &&
                                                  m.Status != (int)OsobaEvent.Statuses.NasiPoliticiSkryte)
                                         .Select(m => m.AddInfo).FirstOrDefault();

                List <StatementDTO> statements = null;
                if (!string.IsNullOrWhiteSpace(registrOznameni))
                {
                    var ds    = DataSet.CachedDatasets.Get("centralniregistroznameni");
                    var value = ds.GetDataObj(registrOznameni);


                    //StatementDTO[] statements = (StatementDTO[])value.statements;
                    statements = value?.statements?.ToObject <List <StatementDTO> >();
                }

                string osobaInsQuery = $"{{0}}.osobaId:{o.NameId}";
                //var oinsRes = HlidacStatu.Lib.Data.Insolvence.Insolvence.SimpleSearch("osobaid:" + Model.NameId, 1, 5, (int)HlidacStatu.Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.LatestUpdateDesc, false, false);
                //query: dluznici.osobaId:{o.NameId}
                var oinsDluznik = Lib.Data.Insolvence.Insolvence.SimpleSearch(string.Format(osobaInsQuery, "dluznici"), 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);
                //query: veritele.osobaId:{o.NameId}
                var oinsVeritel = Lib.Data.Insolvence.Insolvence.SimpleSearch(string.Format(osobaInsQuery, "veritele"), 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);
                //query: spravci.osobaId:{o.NameId}
                var oinsSpravce = Lib.Data.Insolvence.Insolvence.SimpleSearch(string.Format(osobaInsQuery, "spravci"), 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);

                Dictionary <string, long> oinsolv = new Dictionary <string, long>();
                oinsolv.Add("dluznici|dlužník|dlužníka|dlužníkem", oinsDluznik.Total);
                oinsolv.Add("veritele|věřitel|věřitele|veřitelem", oinsVeritel.Total);
                oinsolv.Add("spravci|insolvenční správce|insolvenčního správce|insolvenčním správcem", oinsSpravce.Total);

                var insRes     = Lib.Data.Insolvence.Insolvence.SimpleSearch("osobaid:" + o.NameId, 1, 5, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.LatestUpdateDesc, false, true);
                var insDluznik = Lib.Data.Insolvence.Insolvence.SimpleSearch("osobaiddluznik:" + o.NameId, 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);
                var insVeritel = Lib.Data.Insolvence.Insolvence.SimpleSearch("osobaidveritel:" + o.NameId, 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);
                var insSpravce = Lib.Data.Insolvence.Insolvence.SimpleSearch("osobaidspravce:" + o.NameId, 1, 1, (int)Lib.Searching.InsolvenceSearchResult.InsolvenceOrderResult.FastestForScroll, false, true);

                Dictionary <string, long> insolv = new Dictionary <string, long>();
                insolv.Add("dluznik|dlužník|dlužníka|dlužníkem", insDluznik.Total);
                insolv.Add("veritel|věřitel|věřitele|veřitelem", insVeritel.Total);
                insolv.Add("spravce|insolvenční správce|insolvenčního správce|insolvenčním správcem", insSpravce.Total);

                var photo = o.GetPhotoUrl(false) + "?utm_source=nasipolitici&utm_medium=detail&utm_campaign=photo";

                var sponzorstvi = o.Events(m =>
                                           m.Type == (int)OsobaEvent.Types.Sponzor &&
                                           m.Status != (int)OsobaEvent.Statuses.NasiPoliticiSkryte)
                                  .Select(m => new
                {
                    party         = m.Organizace,
                    donatedAmount = m.AddInfoNum,
                    year          = m.DatumOd?.Year,
                    source        = m.Zdroj
                }
                                          ).ToArray();

                var insPerson = new
                {
                    debtorCount = oinsDluznik.Total,
                    debtorLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=dluznici.osobaId:{o.NameId}"
                                  + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=dluznikosoba",
                    creditorCount = oinsVeritel.Total,
                    creditorLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=veritele.osobaId:{o.NameId}"
                                    + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=veritelosoba",
                    bailiffCount = oinsSpravce.Total,
                    bailiffLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=spravci.osobaId:{o.NameId}"
                                   + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=spravceosoba",
                };

                var insCompany = new
                {
                    debtorCount = insDluznik.Total,
                    debtorLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=osobaiddluznik:{o.NameId}"
                                  + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=dluznikfirma",
                    creditorCount = insVeritel.Total,
                    creditorLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=osobaidveritel:{o.NameId}"
                                    + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=veritelfirma",

                    bailiffCount = insSpravce.Total,
                    bailiffLink  = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=osobaidspravce:{o.NameId}"
                                   + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=spravcefirma",
                };

                var lastUpdate = o.Events(m => true)
                                 .OrderByDescending(e => e.Created)
                                 .Select(e => e.Created)
                                 .FirstOrDefault();


                var result = new
                {
                    id                             = o.NameId,
                    lastUpdate                     = lastUpdate,
                    lastManualUpdate               = o.ManuallyUpdated,
                    namePrefix                     = o.TitulPred,
                    nameSuffix                     = o.TitulPo,
                    name                           = o.Jmeno,
                    surname                        = o.Prijmeni,
                    birthDate                      = o.Narozeni,
                    deathDate                      = o.Umrti,
                    status                         = o.StatusOsoby().ToString(),
                    hasPhoto                       = o.HasPhoto(),
                    photo                          = photo,
                    description                    = statDescription,
                    companyConnection              = angazovanost,
                    notificationRegisterId         = registrOznameni,
                    notificationRegisterStatements = statements,
                    //funkce = funkceOsoba,
                    roles             = roleOsoba,
                    insolvencyPerson  = insPerson,
                    insolvencyCompany = insCompany,
                    source            = o.GetUrl(false),
                    sponsor           = sponzorstvi,
                    currentParty      = o.CurrentPoliticalParty(),
                    contacts          = o.GetSocialContact(),
                    connections       = vazby,
                    wikiId            = o.WikiId,
                    //sources
                    sourceInsolvency = $"https://www.hlidacstatu.cz/insolvence/hledat?Q=osobaid:{o.NameId}"
                                       + "&utm_source=nasipolitici&utm_medium=detail&utm_campaign=osoba",
                    sourceSponzor = $"https://www.hlidacstatu.cz/osoba/{o.NameId}"
                                    + "?utm_source=nasipolitici&utm_medium=detail&utm_campaign=osoba",
                    sourceRegisterStatements = string.IsNullOrWhiteSpace(registrOznameni)
                            ? "https://www.hlidacstatu.cz" + "?utm_source=nasipolitici&utm_medium=detail&utm_campaign=osoba"
                            : $"https://www.hlidacstatu.cz/data/Detail/centralniregistroznameni/{registrOznameni}" + "?utm_source=nasipolitici&utm_medium=detail&utm_campaign=osoba",
                    sourceRoles = $"https://www.hlidacstatu.cz/osoba/{o.NameId}" + "?utm_source=nasipolitici&utm_medium=detail&utm_campaign=osoba",
                };

                return(Content(JsonConvert.SerializeObject(result), "application/json"));
                // return Json(result, JsonRequestBehavior.AllowGet);
            }
        }