Example #1
0
        public async Task<IHttpActionResult> GetPerson(int id)
        {
            var person = await _repPeople.FindAsync(p => p.Id == id);
            if (person == null)
            {
                return NotFound();
            }

            var pvm = new PersonViewModel(person);

            pvm.Facts = (from fn in _repParameterFactNames.GetAll()
                         join f in (from pf in _repPersonFacts.GetAll()
                                    join pfg in (from pf in _repPersonFacts.GetAll()
                                                 where pf.PersonId == person.Id
                                                 group pf by pf.FactId into g
                                                 select new GroupPersonFact { FactId = g.Key, FactDate = g.Max(e => e.FactDate) }) on pf.FactId equals pfg.FactId
                                    where pf.FactDate == pfg.FactDate && pf.PersonId == id
                                    select pf) on fn.Id equals f.FactId into ft
                         from fl in ft.DefaultIfEmpty()
                         where (fn.PersonCategory & person.Category) > 0 && fn.IsFact == true && fn.Category == ParameterCategory.Person
                         select new FactViewModel
                         {
                             Id = fl.Id,
                             PrmId = fn.Id,
                             FactDate = fl.FactDate,
                             Name = fn.Name,
                             MiscId = fl.IntValue,
                             DicId = fn.MiscParentId,
                             StringValue = fl.StringValue,
                             DateValue = fl.DateValue,
                             FloatValue = fl.FloatValue,
                             PrmCategory = fn.Category,
                             PrmType = fn.Type
                         }).ToDictionary(k => k.Name, v => v);

            pvm.Parameters = (from pn in _repParameterFactNames.GetAll()
                              join pp in _repPersonParams.GetAll().Where(p => p.PersonId == id) on pn.Id equals pp.ParameterId into pt
                              from pl in pt.DefaultIfEmpty()
                              where (pn.PersonCategory & person.Category) > 0 && pn.IsFact == false && pn.Category == ParameterCategory.Person
                              select new ParameterViewModel
                              {
                                  Id = pl.Id,
                                  PrmId = pn.Id,
                                  Name = pn.Name,
                                  MiscId = pl.IntValue,
                                  DicId = pn.MiscParentId,
                                  StringValue = pl.StringValue,
                                  FloatValue = pl.FloatValue,
                                  DateValue = pl.DateValue,
                                  PrmCategory = pn.Category,
                                  PrmType = pn.Type
                              }).ToDictionary(k => k.Name, v => v);

            pvm.DocsCount = (from d in _repDocs.GetAll()
                             where d.HostPersonId == id || d.ApplicantPersonId == id
                             group d by d.Type into g
                             select new { Type = g.Key, Count = g.Count() }).ToDictionary(k => k.Type.ToString(), v => v.Count);

            return Ok(pvm);
        }
Example #2
0
        public async Task<IHttpActionResult> GetPerson(int id)
        {
            var person = await _repPeople.FindAsync(p => p.Id == id);
            if (person == null)
            {
                return NotFound();
            }

            var pvm = new PersonViewModel(person);

            pvm.Facts = (from pf in _repPersonFacts.GetAll()
                         join pfn in _repParameterFactNames.GetAll() on pf.FactId equals pfn.Id
                         join pfg in GetAllPersonFactsSubQuery(id) on pf.FactId equals pfg.FactId
                         join m in _repMisc.GetAll() on pf.IntValue equals m.Id into mlj
                         from x in mlj.DefaultIfEmpty()
                         where pf.FactDate == pfg.FactDate && pf.PersonId == id
                         select new FactViewModel
                         {
                             Id = pf.Id,
                             FactId = pf.FactId,
                             FactDate = pf.FactDate,
                             FactName = pfn.Name,
                             FactNameRu = pfn.NameRu,
                             MiscId = pf.IntValue,
                             MiscValue = x.MiscValue,
                             StringValue = pf.StringValue,
                             DateValue = pf.DateValue,
                             FloatValue = pf.FloatValue,
                             FactCategory = pfn.Category,
                             FactType = pfn.Type
                         }).ToDictionary(k => k.FactName, v => v);

            pvm.Parameters = (from pp in _repPersonParams.GetAll()
                              join ppn in _repParameterFactNames.GetAll() on pp.ParameterId equals ppn.Id
                              join m in _repMisc.GetAll() on pp.IntValue equals m.Id into mlj
                              from x in mlj.DefaultIfEmpty()
                              where pp.PersonId == id
                              select new ParameterViewModel
                              {
                                  Id = pp.Id,
                                  PrmId = pp.ParameterId,
                                  PrmName = ppn.Name,
                                  PrmNameRu = ppn.NameRu,
                                  MiscId = pp.IntValue,
                                  MiscValue = x.MiscValue,
                                  StringValue = pp.StringValue,
                                  FloatValue = pp.FloatValue,
                                  DateValue = pp.DateValue,
                                  PrmCategory = ppn.Category,
                                  PrmType = ppn.Type
                              }).ToDictionary(k => k.PrmName, v => v);

            pvm.DocsCount.Add(DocumentType.AdministrativePractice.ToString(),
                _repDocs.GetAll().Count(d => d.Type == DocumentType.AdministrativePractice && (d.HostPersonId == id || d.ApplicantPersonId == id)));
            pvm.DocsCount.Add(DocumentType.Citizenship.ToString(),
                _repDocs.GetAll().Count(d => d.Type == DocumentType.Citizenship && (d.HostPersonId == id || d.ApplicantPersonId == id)));

            return Ok(pvm);
        }