public ActionResult <Event> Put([FromBody] UpdateEventDTO request) { var command = new EditEventCommand(_mapper.Map <Event>(request)); var handler = _commandHandler.Build(command); return(Ok(handler.Execute())); }
public async Task <IActionResult> UpdateEvent(UpdateEventDTO e) { ServiceResponse <GetEventDTO> response = await _eventService.UpdateEvent(e); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public async Task <ServiceResponse <GetEventDTO> > UpdateEvent(UpdateEventDTO updatedEvent) { ServiceResponse <GetEventDTO> serviceResponse = new ServiceResponse <GetEventDTO>(); try { Event e = await _context.Events.Where(e => e.IsDeleted == false). Include(ev => ev.User).FirstOrDefaultAsync(ev => ev.Id == updatedEvent.Id); if (e.User.Id == GetUserId()) { e.Name = updatedEvent.Name; e.Location = updatedEvent.Location; if (updatedEvent.EventDate != null) { e.EventDate = updatedEvent.EventDate; } if (updatedEvent.NumberOfAttendees != 0) { e.NumberOfAttendees = updatedEvent.NumberOfAttendees; } if (updatedEvent.User != null) { e.User = updatedEvent.User; } _context.Events.Update(e); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetEventDTO>(e); } else { serviceResponse.Success = false; serviceResponse.Message = "You do not have the permissions to edit this event. Only the creator of the event can update it."; } } catch (Exception exc) { serviceResponse.Success = false; serviceResponse.Message = exc.Message; } return(serviceResponse); }