Ejemplo n.º 1
0
        public ActionResult <List <CheckEntity> > Get([FromQuery] string inn, string trim)
        {
            if (string.IsNullOrEmpty(inn) && string.IsNullOrEmpty(trim))
            {
                return(NotFound(new { message = "Данные не найдены" }));
            }
            XDocument data = _loadData.GetDocument();

            string namespeces  = "{" + data.Root.Name.NamespaceName + "}";
            var    inspections = data.Root.Elements();

            var checks = inspections.Elements(namespeces + "I_SUBJECT")
                         .Where(n => (string.IsNullOrEmpty(inn) || n.Attribute("INN")?.Value == inn) &&
                                (string.IsNullOrEmpty(trim) || n.Attribute("ORG_NAME").Value.ToLower().Contains(trim.ToLower()))
                                )
                         .Select(n => new CheckEntity
            {
                StartDate                = n.Parent.Attribute("START_DATE")?.Value,
                Status                   = n.Parent.Attribute("STATUS")?.Value,
                ProsecutorsName          = n.Parent.Attribute("PROSEC_NAME")?.Value,
                OkatoName                = n.Parent.Element(namespeces + "OKATO")?.Attribute("OKATO_NAME")?.Value,
                TypeName                 = n.Parent.Attribute("ITYPE_NAME")?.Value,
                GoalOrganizationName     = n.Attribute("ORG_NAME")?.Value,
                ProviderOrganizationName = n.Parent.Element(namespeces + "I_CLASSIFICATION")?.Attribute("ISUPERVISION_NAME")?.Value,
                INN        = n.Attribute("INN")?.Value,
                OGRN       = n.Attribute("OGRN")?.Value,
                Inspectors = n.Parent
                             .Elements(namespeces + "I_INSPECTOR")
                             .Select(v => new Inspector
                {
                    FullName = v.Attribute("FULL_NAME").Value,
                    Position = v.Attribute("POSITION").Value
                }).ToList()
            });

            return(checks.ToList());
        }