Пример #1
0
        public async Task <List <ReservationModel> > GetPitchesMultiplesBusyCustomerAsync(int id, DateTime date)
        {
            var uri = new Uri(string.Format("{0}api/reservations/customer/busy/multiple", _uriBase));

            AddAuth();

            var json    = JsonConvert.SerializeObject(new { id_place = id, date = date.ToString("yyyy-MM-dd") });
            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> placeModels = JArray.Parse(result).Select(x => new ReservationModel
                {
                    Pitch = new PitchModel {
                        Id = (int)x["id_pitch"]
                    },
                    Date          = FunctionsService.GetHour((string)x["hour"]),
                    Status        = FunctionsService.GetStatus((int)x["status"]),
                    IdReservation = (int)x["id_reservation"],
                    Source        = (int)x["source"]
                }).ToList();

                return(placeModels);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        List <HourModel> GetHours(JToken json)
        {
            List <HourModel> model = JArray.Parse(json.ToString()).Select(x => new HourModel
            {
                NumberDay = (int)x["id_day"],
                HourStart = FunctionsService.GetHour((string)x["hour_start"]),
                HourEnd   = FunctionsService.GetHour((string)x["hour_end"])
            }).ToList();

            return(model);
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
            }
        }