public async Task <IActionResult> Post([FromBody] EventInsertDTO dto) { EventFindDTO createdEvent = await this.EventService.Insert( this.User.GetEstablishmentId(), dto ); return(Created( $"{this.Request.Path.ToString()}/{createdEvent.Id}", createdEvent )); }
/// <summary> /// Inserts a new Event. /// </summary> /// <param name="establishmentId"></param> /// <param name="dto"></param> /// <returns></returns> public async Task <EventFindDTO> Insert(ObjectId establishmentId, EventInsertDTO dto) { UploadImageModel uploadedImage = await this.ImageService.UploadImage( EventService.EventsContainer, dto.Image); Establishment establishment = this.MongoRepository.FindById <Establishment>(establishmentId); Event eventEntity = this.CreateEvent(establishment, uploadedImage, dto); this.MongoRepository.Insert(eventEntity); return(this.Find(eventEntity.Id)); }
/// <summary> /// Create Event from specified dto. /// </summary> /// <param name="establishment"></param> /// <param name="uploadedImage"></param> /// <param name="dto"></param> /// <returns></returns> private Event CreateEvent(Establishment establishment, UploadImageModel uploadedImage, EventInsertDTO dto) { return(new Event( establishment.Id, dto.StartDate, dto.EndDate, dto.Name, dto.Description, uploadedImage.Image, uploadedImage.Thumbnail, dto.Location != null ? new Location( dto.Location.Street, dto.Location.Number, dto.Location.State, dto.Location.Country, dto.Location.City, new GeoJson2DGeographicCoordinates( dto.Location.Longitude, dto.Location.Latitude ) ) : establishment.Location, dto.Location == null, dto.Genres )); }