Beispiel #1
0
        public async Task <List <ReservationModel> > FindReservationByPlaceAsync(DateTime date, int idPlace)
        {
            var uri = new Uri(string.Format("{0}api/reservations/findfreepitchbyplace", _uriBase));

            AddAuth();

            var json = JsonConvert.SerializeObject
                           (new
            {
                id_place = idPlace,
                date     = date.ToString("yyyy-MM-dd"),
                hour     = date.ToString("HH:mm"),
            });
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage response = null;

            response = await _client.PostAsync(uri, content);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                List <ReservationModel> reservationModels = JArray.Parse(result).Select(x => new ReservationModel
                {
                    Place = new PlaceModel
                    {
                        Id            = (int)x["id_place"],
                        Name          = (string)x["name"],
                        Address       = (string)x["address"],
                        ProfileImgUrl = (string)x["profile_img"]
                    },
                    Pitch = new PitchModel
                    {
                        Id          = (int)x["id_pitch"],
                        Description = (string)x["description"],
                        PitchType   = FunctionsService.GetPitchType((int)x["id_pitch_type"])
                    },
                    Price = (decimal)x["value"],
                    Date  = FunctionsService.GetDateTime((string)x["date"], (string)x["hour"])
                }).ToList();

                return(reservationModels);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public async Task <ReservationModel> GetReservationDetailAsync(int idReservation)
        {
            var uri = new Uri(string.Format("{0}api/reservations/detail/{1}", _uriBase, idReservation));

            AddAuth();

            HttpResponseMessage response = null;

            response = await _client.GetAsync(uri);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                JObject responseModel = JsonConvert.DeserializeObject <JObject>(result.Trim('[', ']'));

                ReservationModel reservation = new ReservationModel
                {
                    IdReservation = (int)responseModel["id_reservation"],
                    Date          = FunctionsService.GetDateTime((string)responseModel["date"], (string)responseModel["hour"]),
                    Price         = (decimal)responseModel["value"],
                    Description   = (string)responseModel["reservation_description"],
                    Status        = FunctionsService.GetStatus((int)responseModel["status"]),
                    User          = new UserModel
                    {
                        Name  = (string)responseModel["name"],
                        Phone = (string)responseModel["phone"]
                    },
                    Pitch = new PitchModel
                    {
                        Description = (string)responseModel["description"]
                    }
                };

                return(reservation);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public async Task <List <ReservationModel> > GetMyReservationsAsync()
        {
            var uri = new Uri(string.Format("{0}api/reservations/myreservations/{1}", _uriBase, SessionService.Account.IdUser));

            AddAuth();

            HttpResponseMessage response = null;

            response = await _client.GetAsync(uri);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                List <ReservationModel> reservationModels = JArray.Parse(result).Select(x => new ReservationModel
                {
                    IdReservation = (int)x["id_reservation"],
                    Place         = new PlaceModel
                    {
                        Id            = (int)x["id_place"],
                        Name          = (string)x["name_place"],
                        Address       = (string)x["address"],
                        ProfileImgUrl = (string)x["profile_img"]
                    },
                    Price  = (decimal)x["value"],
                    Status = FunctionsService.GetStatus((int)x["status"]),
                    Date   = FunctionsService.GetDateTime((string)x["date"], (string)x["hour"]),
                    Pitch  = new PitchModel
                    {
                        Description = (string)x["pitch_description"]
                    }
                }).ToList();

                return(reservationModels);
            }
            else
            {
                return(null);
            }
        }