protected void ValidateUserPlace(UserPlaceViewModel userPlace) { if (string.IsNullOrWhiteSpace(userPlace.Name)) { throw new EntityValidationException("Name is a required field."); } }
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); }
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); }
public IActionResult Update([FromBody] UserPlaceViewModel userPlace) { return(Ok(_userPlaceService.Update(userPlace).ToViewModel())); }