Exemple #1
0
        public async Task <IActionResult> GetAgendaForOwner(EmailRequest emailRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var agendas = await _dataContext.Agendas
                          .Include(a => a.Owner)
                          .ThenInclude(o => o.User)
                          .Include(a => a.Owner)
                          .ThenInclude(o => o.Pets)
                          .ThenInclude(p => p.PetType)
                          .Include(a => a.Pet)
                          .ThenInclude(p => p.PetType)
                          .Where(a => a.Date >= DateTime.Today.ToUniversalTime())
                          .OrderBy(a => a.Date)
                          .ToListAsync();

            var response = new List <AgendaResponse>();

            foreach (var agenda in agendas)
            {
                var agendaRespose = new AgendaResponse
                {
                    Date        = agenda.Date,
                    Id          = agenda.Id,
                    IsAvailable = agenda.IsAvailable
                };

                if (agenda.Owner != null)
                {
                    if (agenda.Owner.User.Email.ToLower().Equals(emailRequest.Email.ToLower()))
                    {
                        agendaRespose.Owner   = ToOwnerResposne(agenda.Owner);
                        agendaRespose.Pet     = ToPetResponse(agenda.Pet);
                        agendaRespose.Remarks = agenda.Remarks;
                    }
                    else
                    {
                        agendaRespose.Owner = new OwnerResponse {
                            FirstName = "Reserved"
                        };
                    }
                }

                response.Add(agendaRespose);
            }

            return(Ok(response));
        }
Exemple #2
0
        public async Task <AgendaResponse> GetAgendaAsync(bool roamResult)
        {
            string startingDate = DateTimeExtensions.StartingSchoolDate.ToString("yyyyMMdd");
            string endingDate   = DateTimeExtensions.EndingSchoolDate.ToString("yyyyMMdd");

            string requestUri = string.Format(AGENDA_URL, authResponse.UserID, startingDate, endingDate);

            HttpContent httpContent = await SendRequestAsync(HttpMethod.Get, requestUri, null);

            AgendaResponse response = JsonConvert.DeserializeObject <AgendaResponse>(await httpContent.ReadAsStringAsync());

            AccountDetails.AgendaEvents.Clear();
            AccountDetails.AgendaEvents.AddRange(response.Appointments);

            if (roamResult)
            {
                ResourceExtensions.StoreRoamingObject(BackgroundTaskExtensions.APPOINTMENTS, response.Appointments.Count);
            }

            return(response);
        }