public Sighting AddSighting(CreateSightingRequest newSighting) { var sightingRepo = new SightingRepository(); using (var db = new SqlConnection(ConnectionString)) { var insertQuery = @" INSERT INTO [dbo].[Sightings] ([Description] ,[DateOfEvent] ,[Duration] ,[Shape] ,[CityLatitude] ,[CityLongitude] ,[Image] ) output inserted.* VALUES (@description, @dateOfEvent, @duration, @shape, @cityLatitude, @cityLongitude, @image )"; var parameters = new { Description = newSighting.Description, DateOfEvent = newSighting.DateOfEvent, Duration = newSighting.Duration, Shape = newSighting.Shape, CityLatitude = newSighting.CityLatitude, CityLongitude = newSighting.CityLongitude, Image = newSighting.Image }; var newSightings = db.QueryFirstOrDefault <Sighting>(insertQuery, parameters); if (newSightings != null) { return(newSightings); } throw new Exception("Could not create sighting"); } }
public ActionResult AddSighting(CreateSightingRequest newSighting) { var newSightings = _sightingRepository.AddSighting(newSighting); return(Ok(newSightings)); }