Exemple #1
0
 protected void ValidateUserPlace(UserPlaceViewModel userPlace)
 {
     if (string.IsNullOrWhiteSpace(userPlace.Name))
     {
         throw new EntityValidationException("Name is a required field.");
     }
 }
Exemple #2
0
        public UserPlace Update(UserPlaceViewModel toUpdate)
        {
            var userPlace = Get(toUpdate.UserPlaceId);

            if (null == userPlace)
            {
                throw new EntityValidationException("User Place doesn't exist");
            }
            ValidateUserPlace(toUpdate);

            userPlace.Place.Name      = toUpdate.Name;
            userPlace.Place.Longitude = toUpdate.Longitude;
            userPlace.Place.Latitude  = toUpdate.Latitude;

            _db.SaveChanges();

            return(userPlace);
        }
Exemple #3
0
        public UserPlace Create(UserPlaceViewModel toCreate)
        {
            ValidateUserPlace(toCreate);
            var userPlace = new UserPlace()
            {
                Place = new Place()
                {
                    Name      = toCreate.Name,
                    Latitude  = toCreate.Latitude,
                    Longitude = toCreate.Longitude,
                },
                OwnerId = _requestInformation.UserId,
                Active  = true
            };

            _db.UserPlaces.Add(userPlace);
            _db.SaveChanges();
            return(userPlace);
        }
Exemple #4
0
 public IActionResult Update([FromBody] UserPlaceViewModel userPlace)
 {
     return(Ok(_userPlaceService.Update(userPlace).ToViewModel()));
 }