Esempio n. 1
0
        private async Task <IActionResult> GetAdopterAsync(EmailRequest emailRequest)
        {
            var adopter = await _dataContext.Adopters
                          .Include(o => o.User)
                          .Include(o => o.Requests)
                          .ThenInclude(p => p.Pet)
                          .FirstOrDefaultAsync(o => o.User.UserName.ToLower() == emailRequest.Email.ToLower());

            var pets = await _dataContext.Pets
                       .Include(pt => pt.PetType)
                       .Include(pt => pt.Requests)
                       .ThenInclude(o => o.HouseType)
                       .Where(p => p.IsAvailable)
                       .ToListAsync();

            var response = new TemporaryOwnerResponse
            {
                Id          = adopter.Id,
                IsAdopter   = true,
                IsOwner     = false,
                FirstName   = adopter.User.FirstName,
                LastName    = adopter.User.LastName,
                Address     = adopter.User.Address,
                Document    = adopter.User.Document,
                Email       = adopter.User.Email,
                PhoneNumber = adopter.User.PhoneNumber,
                Pets        = pets.Select(p => new PetResponse
                {
                    Age             = p.Age,
                    Id              = p.Id,
                    ImageUrl        = p.ImageFullPath,
                    Name            = p.Name,
                    Race            = p.Race,
                    Description     = p.Description,
                    PetType         = p.PetType.Name,
                    IsAvailable     = p.IsAvailable,
                    HistoryRequests = p.Requests
                                      .Where(where => where.Adopter != null && where.Adopter.User.UserName.ToLower() == emailRequest.Email.ToLower())
                                      .Select(h => new HistoryRequestResponse
                    {
                        Active      = h.Active,
                        Adopter     = adopter.User.FullName,
                        Date        = h.Date,
                        Denied      = h.Denied,
                        HasKids     = h.HasKids,
                        HasPets     = h.HasOthePets,
                        HouseType   = h.HouseType.Name,
                        Observation = h.Observation,
                        Pet         = p.Name,
                        RequestId   = h.Id,
                        Telephone   = adopter.User.CellPhone,
                    }).ToList()
                }).ToList()
            };

            return(Ok(response));
        }
Esempio n. 2
0
 public RequestHistoriesPageViewModel(
     INavigationService navigationService,
     IApiService apiService) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     Pet    = JsonConvert.DeserializeObject <PetResponse>(Settings.Pet);
     _owner = JsonConvert.DeserializeObject <TemporaryOwnerResponse>(Settings.Owner);
     Title  = Languages.Requests;
     LoadHistories();
 }