Beispiel #1
0
        public PlaceViewModel AddPlaceItem(PlaceFormViewModel model)
        {
            var hasStart = _context.Places
                           .Any(p => p.JourneyId == model.JourneyId && p.Start);

            var place = new Place
            {
                JourneyId = model.JourneyId,
                Location  = model.Location,
                Address   = model.Address,
                Latitude  = model.Latitude,
                Longitude = model.Longitude,
                Start     = !hasStart
            };

            _context.Places.Add(place);
            _context.SaveChanges();
            return(new PlaceViewModel
            {
                Id = place.Id,
                Location = place.Location,
                Address = place.Address,
                Latitude = place.Latitude,
                Longitude = place.Longitude,
                Rank = place.Rank,
                Start = place.Start
            });
        }
        public void TestAddPlaceItem()
        {
            var model = new PlaceFormViewModel {
                Location = "Place"
            };
            var item = _repository.AddPlaceItem(model);

            Assert.NotNull(item);
            Assert.AreEqual("Place", item.Location);
        }
Beispiel #3
0
        public ActionResult <PlaceViewModel> AddPlace([FromBody] PlaceFormViewModel model)
        {
            var userId = GetUserId(User);

            if (!_journeyRepository.IsUsersJourney(userId, model.JourneyId))
            {
                return(StatusCode(403, "Journey doesn't belong to the user"));
            }

            if (model.Latitude < -90 || model.Latitude > 90)
            {
                return(StatusCode(422, "Latitude must be between -90 and 90"));
            }

            if (model.Longitude < -180 || model.Longitude > 180)
            {
                return(StatusCode(422, "Longitude must be between -180 and 180"));
            }

            return(Ok(_journeyRepository.AddPlaceItem(model)));
        }