Exemplo n.º 1
0
        public static Viajes getNTravel(int id)
        {
            Viajes aux = new Viajes();

            for (int i = 0; i < travels.Count(); i++)
            {
                aux = travels.ElementAt(i);
                if (aux.id == id)
                {
                    return(aux);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public async Task <string> endTravel(startTravel start)
        {
            webClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", client.token);
            uri = new Uri(baseAddress, "travels/" + start.id);

            //endTravel
            end = new endTravel();
            var content = new StringContent("", Encoding.UTF8, "application/json");

            try
            {
                var response = await webClient.PutAsync(uri, content);

                var rString = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    end = JsonConvert.DeserializeObject <endTravel>(rString);
                    Viajes travel = new Viajes
                    {
                        id         = start.id,
                        started_at = end.started_at,
                        ended_at   = end.ended_at.date,
                        client_id  = start.client_id,
                        vehicle_id = start.vehicle_id,
                        created_at = start.created_at,
                    };
                    travels.Add(travel);
                    return(rString);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(null);
        }