Exemplo n.º 1
0
        public IHttpActionResult PostLocation(UserLocationViewModel location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            try
            {
                _userLocationRepository.Add(location.ToModel());
            }
            catch (DbUpdateException)
            {
                if (LocationExist(location.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = location.Id }, location));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PutLocation(Guid id, UserLocationViewModel location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != location.Id)
            {
                return(BadRequest());
            }

            location.Id = id;

            try
            {
                await _userLocationRepository.EditAsync(location.ToModel());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LocationExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public ActionResult <IEnumerable <ShopViewModel> > Sorted([FromBody] UserLocationViewModel userLocation)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpRequestException(string.Format(
                                                   _errorHandler.GetMessage(ErrorMessagesEnum.ModelValidation),
                                                   ModelState.Values.First().Errors.First().ErrorMessage));
            }

            var allShops = _shopRepository.GetSortedShops(userLocation.longitude, userLocation.latitude);

            if (allShops == null || allShops.Count() == 0)
            {
                return(NoContent());
            }

            var viewModels = allShops.Select(shop => new ShopViewModel
            {
                Id        = shop.Id,
                Name      = shop.Name,
                latitude  = shop.Location.Y,
                longitude = shop.Location.X
            });

            return(Ok(viewModels));
        }
Exemplo n.º 4
0
        public IHttpActionResult GetLocation(Guid id)
        {
            UserLocationViewModel location = new UserLocationViewModel(_userLocationRepository.GetSingle(e => e.Id == id));

            if (location == null)
            {
                return(NotFound());
            }

            return(Ok(location));
        }
        public async Task <ActionResult <UserLocationViewModel> > UploadFileAsync([FromForm] IFormFile file)
        {
            var userId   = Guid.NewGuid().ToString();
            var response = new UserLocationViewModel
            {
                Id = userId
            };

            if (file == null)
            {
                return(BadRequest("No file has been uploaded."));
            }

            if (!IsFileLengthValid(file))
            {
                return(BadRequest("File size exceeded configured limit."));
            }

            try
            {
                using (Stream stream = new MemoryStream())
                {
                    await file.CopyToAsync(stream);

                    stream.Position = 0;
                    await azureBlobService.UploadFile(userId, stream);

                    await locationCreatedSender.SendMessageAsync(new LocationsCreatedMessage
                    {
                        UserId = userId
                    });
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Processing of uploaded file failed.", ex);
            }


            return(response);
        }
        public async Task <IActionResult> PostLocation([FromBody] UserLocationViewModel location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var loc = await _locationService.Do(location);

            if (loc)
            {
                return(Ok(new
                {
                    status = "success"
                }));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 7
0
        public async Task <bool> Do(UserLocationViewModel userLocation)
        {
            try
            {
                var state = _context.States.Where(stateSr => stateSr.Name == "Active").FirstOrDefault();

                var location = new UserLocation()
                {
                    UserId    = userLocation.UserId,
                    Latitude  = userLocation.Latitude,
                    Longitude = userLocation.Longitude,
                    StateId   = state.Id
                };
                _context.UserLocations.Add(location);
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }