示例#1
0
        private async Task <IActionResult> GetTechnicalAsync(EmailRequest emailRequest)
        {
            var technical = await _dataContext.Technicals
                            .Include(o => o.User)
                            .Include(o => o.Visits)
                            .ThenInclude(o => o.Company)
                            .Include(o => o.Visits)
                            .ThenInclude(o => o.Technical)
                            .Include(o => o.Visits)
                            .ThenInclude(o => o.State)
                            .Include(o => o.Visits)
                            .ThenInclude(o => o.VisitDetails)
                            .FirstOrDefaultAsync(o => o.User.UserName.ToLower().Equals(emailRequest.Email.ToLower()));

            var response = new TechnicalResponse
            {
                Document  = technical.User.Document,
                FirstName = technical.User.FirstName,
                LastName  = technical.User.LastName,
                Address   = technical.User.Address,
                FullName  = technical.User.FullName,

                Visits = technical.Visits?.Select(p => new Common.Models.VisitResponse
                {
                    Id          = p.Id,
                    Date        = p.Date,
                    CompanyName = p.Company.Name,
                    GRXX        = p.Company.GRXX,
                    GRYY        = p.Company.GRYY,
                    State       = p.State.Name,

                    VisitDetails = p.VisitDetails?.Select(pi => new VisitDetailResponse
                    {
                        Id               = pi.Id,
                        IdSubject        = pi.IdSubject,
                        ImageUrl1        = pi.ImageUrl1,
                        ImageUrl2        = pi.ImageUrl2,
                        ImageUrl3        = pi.ImageUrl3,
                        ImageUrl4        = pi.ImageUrl4,
                        Note             = pi.Note,
                        QuestionTypeId   = pi.QuestionTypeId,
                        QuestionTypeName = pi.QuestionTypeName,
                        Subject          = pi.Subject
                    }).ToList()
                }).ToList()
            };

            return(Ok(response));
        }
        private static AirQualityDescription ConvertToModelObject(TechnicalResponse response)
        {
            AirQualityDescription modelObject = null;

            try
            {
                modelObject = JsonConvert.DeserializeObject <AirQualityDescription>(response.ResponseText);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception deserializing json: {e}");
                Console.WriteLine($"Problematic Json: {response.RequestText}");
            }

            return(modelObject);
        }