public async Task <IActionResult> PostEstablishmentLocation([FromBody] EstablishmentLocationRequest request) { if (!ModelState.IsValid) { return(BadRequest(new Response { IsSuccess = false, Message = "Bad request", Result = ModelState })); } EstablishmentEntity establishment = await _context.Establishments.FirstOrDefaultAsync(e => e.Id == request.IdEstablishment); CityEntity city = await _context.Cities.FirstOrDefaultAsync(c => c.Id == request.IdCity); TypeEstablishmentEntity typeEstablishment = await _context.TypeEstablishments.FirstOrDefaultAsync(te => te.Id == request.IdTypeEstablishment); List <EstablishmentLocationEntity> establishmentLocationEntity = await _context.EstablishmentLocations .Include(m => m.Establishments) .Include(m => m.Foods) .ThenInclude(m => m.TypeFoods) .Include(m => m.Foods) .ThenInclude(m => m.User) .Include(m => m.Cities) .Include(m => m.TypeEstablishment) .Where(e => e.Establishments.Id == request.IdEstablishment) .ToListAsync(); var LatitudeValidation = establishmentLocationEntity.FirstOrDefault(el => el.SourceLatitude == request.SourceLatitude); var LongitudeValidation = establishmentLocationEntity.FirstOrDefault(el => el.SourceLongitude == request.SourceLongitude); if (LatitudeValidation != null & LongitudeValidation != null) { return(BadRequest(new Response { IsSuccess = false, Message = "Establishment location exist" })); } EstablishmentLocationEntity establishmentLocation = new EstablishmentLocationEntity { SourceLatitude = request.SourceLatitude, SourceLongitude = request.SourceLongitude, TargetLatitude = request.TargetLatitude, TargetLongitude = request.TargetLongitude, Remarks = request.Remarks, Establishments = establishment, Cities = city, TypeEstablishment = typeEstablishment }; _context.EstablishmentLocations.Add(establishmentLocation); await _context.SaveChangesAsync(); return(Ok(_converterHelper.ToEstablishmentLocationResponse(establishmentLocation))); }
public AddLocationPageViewModel( INavigationService navigationService, IApiService apiService, IGeolocatorService geolocatorService) : base(navigationService) { _navigationService = navigationService; _apiService = apiService; _geolocatorService = geolocatorService; Title = "Add Location"; IsEnabled = true; Location = new EstablishmentLocationRequest(); TypeEstablishments = new ObservableCollection <TypeEstablishmentResponse>(CombosHelper.GetTypeEstablishment()); Cities = new ObservableCollection <CityResponse>(CombosHelper.GetCities()); }
public async Task <IActionResult> GetEstablishmentLocations([FromBody] EstablishmentLocationRequest establishmentLocationRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <EstablishmentLocationEntity> establishmentLocationEntity = await _context.EstablishmentLocations .Include(m => m.Establishments) .Include(m => m.Foods) .ThenInclude(m => m.TypeFoods) .Include(m => m.Foods) .ThenInclude(m => m.User) .Include(m => m.Cities) .Include(m => m.TypeEstablishment) .Where(e => e.Establishments.Id == establishmentLocationRequest.IdEstablishment) .ToListAsync(); if (establishmentLocationEntity == null) { } return(Ok(_converterHelper.ToEstablishmentLocationResponse(establishmentLocationEntity))); }
public async Task <Response> NewEstablishmentLocationAsync(string urlBase, string servicePrefix, string controller, EstablishmentLocationRequest model, string tokenType, string accessToken) { try { string request = JsonConvert.SerializeObject(model); StringContent content = new StringContent(request, Encoding.UTF8, "application/json"); HttpClient client = new HttpClient { BaseAddress = new Uri(urlBase) }; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken); string url = $"{servicePrefix}{controller}"; HttpResponseMessage response = await client.PostAsync(url, content); string answer = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return(new Response { IsSuccess = false, Message = answer, }); } EstablishmentLocationResponse location = JsonConvert.DeserializeObject <EstablishmentLocationResponse>(answer); return(new Response { IsSuccess = true, Result = location, }); } catch (Exception ex) { return(new Response { IsSuccess = false, Message = ex.Message, }); } }