public async Task <IActionResult> AddAsync(Location location)
        {
            var result = await _locationService.AddAsync(location);

            if (result.Success)
            {
                return(Ok(JsonConvert.SerializeObject(result.Message)));
            }
            return(BadRequest(JsonConvert.SerializeObject(result.Message)));
        }
Ejemplo n.º 2
0
        private async Task <LocationInfo> SaveLocationAsync(LocationInfo location)
        {
            if (_view.Locations.All(x => x.Id != location.Id))
            {
                location = await _locationService.AddAsync(location);

                _view.Locations.Add(location);
            }
            else
            {
                await _locationService.UpdateAsync(location);

                location = await _locationService.GetAsync(location.Id);

                _view.Locations.AddOrReplace(x => x.Id == location.Id, location);
            }

            return(location);
        }
        public async Task <IActionResult> Post(UserLocationRequest request)
        {
            try
            {
                request.UserId = HttpContext.GetUserId();

                var result = await _locationService.AddAsync(request);

                if (!result.Success)
                {
                    return(BadRequest(result));
                }

                var response = JsonConvert.SerializeObject(request);

                await _hub.Clients.Client(request.UserId).SendAsync("newLocation", response);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }