public async Task <ActionResult> Put(int id, [FromForm] EventCreationDTO eventCreationDTO) { var currentEvent = await context.Events.FirstOrDefaultAsync(e => e.Id == id); if (currentEvent == null) { return(NotFound()); } if (eventCreationDTO.IsTimer) { await HideOldEvent(); } mapper.Map(eventCreationDTO, currentEvent); if (eventCreationDTO.EventPicture != null) { if (string.IsNullOrEmpty(currentEvent.EventPicture)) { await fileStorage.RemoveFile(currentEvent.EventPicture, ApplicationConstants.ImageContainerNames.EventImagesContainer); } currentEvent.EventPicture = await SaveImage(eventCreationDTO.EventPicture); } context.Entry(currentEvent); await context.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Post([FromForm] EventCreationDTO eventCreationDTO) { if (eventCreationDTO.IsTimer) { await HideOldEvent(); } var entity = mapper.Map <Event>(eventCreationDTO); if (eventCreationDTO.EventPicture != null) { entity.EventPicture = await SaveImage(eventCreationDTO.EventPicture); } context.Add(entity); await context.SaveChangesAsync(); var dto = mapper.Map <EventDTO>(entity); return(new CreatedAtRouteResult("GetEvent", new { id = entity.Id }, dto)); }
public void CreateEvent([FromBody] EventCreationDTO item) { BusinesLogic.EventService.CreateEvent(item); }