Last active
February 12, 2020 20:44
-
-
Save ahmetkucukoglu/eb12a93840331ca4281fae376762be93 to your computer and use it in GitHub Desktop.
ASP.NET Core ile Couchbase GeoSearch - EventsController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Couchbase.GeoSearchApp.Controllers | |
| { | |
| using Couchbase.Core; | |
| using Couchbase.Extensions.DependencyInjection; | |
| using Microsoft.AspNetCore.Mvc; | |
| using System; | |
| using System.Threading.Tasks; | |
| [Route("api/[controller]")] | |
| [ApiController] | |
| public class EventsController : ControllerBase | |
| { | |
| private readonly IBucket _bucket; | |
| public EventsController(IBucketProvider bucketProvider) | |
| { | |
| _bucket = bucketProvider.GetBucket("events"); | |
| } | |
| [HttpPost] | |
| public async Task<IActionResult> CreateEvent([FromBody] CreateEventRequest request) | |
| { | |
| var document = new Document<EventDocument> | |
| { | |
| Id = Guid.NewGuid().ToString(), | |
| Content = new EventDocument | |
| { | |
| Subject = request.Subject, | |
| Description = request.Description, | |
| Date = request.Date, | |
| Address = request.Address, | |
| Location = new EventLocationDocument | |
| { | |
| Lat = request.Latitude, | |
| Lon = request.Longitude | |
| } | |
| } | |
| }; | |
| await _bucket.InsertAsync(document); | |
| return Ok(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment