public PlaceResponse Create(CreatePlaceRequest placeRequest) { var domain = placeRequest.To <Place>(); var createdPlace = _placeService.Create(domain); return(createdPlace.To <PlaceResponse>()); }
private async void Ajouter(object obj) { ApiClient client = new ApiClient(); CreatePlaceRequest request = new CreatePlaceRequest(); request.Title = Name; request.Description = Description; request.Latitude = Lattitude; request.Longitude = Longitude; if (image != null) { request.ImageId = image.Id; } HttpResponseMessage reponse = await client.Execute(HttpMethod.Post, "https://td-api.julienmialon.com/places", request); if (reponse.IsSuccessStatusCode) { await NavigationService.PopAsync(); } else { IDialogService dialog = DependencyService.Get <IDialogService>(); await dialog.DisplayAlertAsync("Marche pas", "Marche pas", "Triste"); } }
public Place CreatePlaceRequestToPlace(CreatePlaceRequest createPlaceRequest) { return(new Place { Name = createPlaceRequest.Name, MaximumCapacity = createPlaceRequest.MaximumCapacity }); }
public IActionResult Create([FromBody] CreatePlaceRequest createPlaceRequest) { logroñoGuide.AddPlaceOfInterest( PlaceOfInterest.Create(createPlaceRequest.Name, Address.Create(createPlaceRequest.Address))); return(Ok()); }
public async Task <Place> CreatePlace(CreatePlaceRequest createPlaceRequest) { var create = _placeConverter.CreatePlaceRequestToPlace(createPlaceRequest); await _placeRepository.CreatePlace(create); return(create); }
public async Task <IActionResult> Create([FromBody] CreatePlaceRequest createPlaceRequest) { var place = await _placeService.CreatePlace(createPlaceRequest); var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.Places.Get.Replace("{postId}", place.PlaceId.ToString()); return(Created(locationUri, place)); }
public AddItemViewModel(Map map) { LoadPin = new Command(async() => await RunPin()); Place = new CreatePlaceRequest(); image = new ImageItem(); byteimage = new byte[4]; Map = map; LoadPin.Execute(null); }
// requête pour ajouter un lieu public async Task <bool> AddPlace(string title, string description, int imageId, double latitude, double longitude) { try { httpClient = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), "https://td-api.julienmialon.com/places"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Barrel.Current.Get <LoginResult>(key: "Login").AccessToken); CreatePlaceRequest place = new CreatePlaceRequest(title, description, imageId, latitude, longitude); string data = JsonConvert.SerializeObject(place); request.Content = new StringContent(data, Encoding.UTF8, "application/json"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { if (await GetUser()) { return(true); } } else { if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { bool token = await RefreshToken(); if (token) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Barrel.Current.Get <LoginResult>(key: "Login").AccessToken); response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { if (await GetUser()) { return(true); } } } } } return(false); } catch (Exception e) { return(false); } }
public async Task<Response> SavePlaceItem(CreatePlaceRequest place) { HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url + "places"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", TOKEN); Response res = new Response(); try { var json = JsonConvert.SerializeObject(place); var u = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = u; HttpResponseMessage response = await client.SendAsync(request); var result = await response.Content.ReadAsStringAsync(); //var response = await client.PostAsync(uri, u); res = JsonConvert.DeserializeObject<Response>(result); if (response.IsSuccessStatusCode) { Debug.WriteLine(@"Commentaire enregistré"); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return await Task.FromResult(res); }
public async Task <bool> NouveauLieu(string title, string description, int imageId, double Latitude, double longitude) { try { client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Barrel.Current.Get <LoginResult>("Login").AccessToken); var uri = new Uri(string.Format("https://td-api.julienmialon.com/places", string.Empty)); CreatePlaceRequest createPlaceRequest = new CreatePlaceRequest(title, description, imageId, Latitude, longitude); string data = JsonConvert.SerializeObject(createPlaceRequest); var contentRequest = new StringContent(data, Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, contentRequest); if (response.IsSuccessStatusCode) { Console.WriteLine("Post Lieu REUSSI"); return(true); } else { if (await Refresh()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Barrel.Current.Get <LoginResult>("Login").AccessToken); response = await client.PostAsync(uri, contentRequest); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } } return(false); } } catch (Exception e) { Console.WriteLine(@" ERROR {0}", e.Message); return(false); } }
public async Task <bool> AjouterLieu(string title, string description, int imageId, double Latitude, double longitude) { try { httpClient = new HttpClient(); var uri = new Uri(string.Format(URL_RACINE + URL_CREATE_PLACE, string.Empty)); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", App.SESSION_LOGIN.AccessToken); CreatePlaceRequest temp = new CreatePlaceRequest(title, description, imageId, Latitude, longitude); string data = JsonConvert.SerializeObject(temp); var contentRequest = new StringContent(data, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync(uri, contentRequest); if (response.IsSuccessStatusCode) { return(true); } else { if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { bool actualiser = await Actualiser(); if (actualiser) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", App.SESSION_LOGIN.AccessToken); response = await httpClient.PostAsync(uri, contentRequest); if (response.IsSuccessStatusCode) { return(true); } } } } return(false); } catch (Exception e) { return(false); } }
public async Task Post(CreatePlaceRequest request) { await places.Create(request.GetDto()); }
public async Task ajouterPlace(string title, string description, string idImage, string latitude, string longitude) { if (!title.Equals("") && !description.Equals("") && !idImage.Equals("")) { if (latitude == "" || longitude == "") { try { var location = await Geolocation.GetLastKnownLocationAsync(); if (location != null) { Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}"); latitude = location.Latitude.ToString(); longitude = location.Longitude.ToString(); } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception Console.WriteLine(fnsEx.InnerException); } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception Console.WriteLine(fneEx.InnerException); } catch (PermissionException pEx) { // Handle permission exception Console.WriteLine(pEx.InnerException); } catch (Exception ex) { // Unable to get location Console.WriteLine(ex.InnerException); } } CreatePlaceRequest content = new CreatePlaceRequest { Title = title, Description = description, ImageId = int.Parse(idImage), Latitude = double.Parse(latitude), Longitude = double.Parse(longitude), }; ApiClient apiClient = new ApiClient(); HttpResponseMessage response = await apiClient.Execute(HttpMethod.Post, URL + "places", content, loginViewModel.infoLogin.AccessToken); string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine("YEEEEEEEEEEEEEEEEEEEEEEs"); await App.Current.MainPage.DisplayAlert("Alert", "Lieu ajouté !", "OK"); await Application.Current.MainPage.Navigation.PushAsync(new listeLieuxPage()); } else { Console.WriteLine("Nooooooooooooooooooooo"); await App.Current.MainPage.DisplayAlert("Alert", "Echec !", "OK"); } } else { await App.Current.MainPage.DisplayAlert("Alert", "Veuillez remplir au minimum les 3 premiers champs", "OK"); } }
public async Task <bool> SendPlaceDataAsync(String nom, String description, String lattitude, String longitude, byte[] imageData, LoginResult lr) { CheckInternetConnection(); await isConnected(); if (imageData == null) { throw new AddPlaceE("Vous n'avez pas ajouté d'image"); } if (nom == "" || description == "" || string.IsNullOrEmpty(lattitude) || string.IsNullOrEmpty(longitude)) { throw new AddPlaceE(nom, description, lattitude, longitude); } var uri = new Uri(string.Format(url + "places/", string.Empty)); double lattitudeD; double longitudeD; try { lattitudeD = double.Parse(lattitude, System.Globalization.CultureInfo.InvariantCulture); longitudeD = double.Parse(longitude, System.Globalization.CultureInfo.InvariantCulture); if (lattitudeD > 90 || lattitudeD < -90 || longitudeD > 180 || longitudeD < -180 || lattitudeD.Equals(0) || longitudeD.Equals(0)) { throw new AddPlaceE(lattitudeD, longitudeD); } } catch (System.FormatException) { throw new AddPlaceE("mauvais format de la latitude ou de la longitude(ex 5 ou 5.2)"); } CreatePlaceRequest cpr = new CreatePlaceRequest(); cpr.Title = nom; cpr.Description = description; ImageItem iItem = await UploadImage(imageData); cpr.ImageId = iItem.Id; cpr.Latitude = lattitudeD; cpr.Longitude = longitudeD; var jsonRequest = JsonConvert.SerializeObject(cpr); var content = new StringContent(jsonRequest, Encoding.UTF8, "text/json"); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", lr.AccessToken); request.Content = content; HttpResponseMessage response = await client.SendAsync(request); string result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { Response r = JsonConvert.DeserializeObject <Response>(result); return(true); } else { Debugger.Break(); } return(false); }
public async Task <int> Post([FromBody] CreatePlaceRequest value) { return(await mediator.Send(value)); }