public void UpdateArtistPerformanceTime(int idArtist, int idEvent, UpdateArtistPerformanceTimeRequest request) { var anEvent = _context.Events.Include(e => e.ArtistEvents) .SingleOrDefault(e => e.IdEvent == idEvent); if (anEvent == null) { throw new EventDoesNotExistsException($"Event with an id {idEvent} does not exists"); } var artistEvent = anEvent.ArtistEvents.SingleOrDefault(e => e.IdArtist == idArtist); if (artistEvent == null) { throw new ArtistDoesNotParticipateInAnEventException($"Artist with an id {idArtist} does not participate in an event with an id {idEvent}"); } if (DateTime.Compare(anEvent.StartDate, DateTime.Now) > 0) { throw new EventAlreadyBegunException("An event has already begun"); } if (!(DateTime.Compare(anEvent.StartDate, request.PerformanceDate) < 0 && DateTime.Compare(request.PerformanceDate, anEvent.EndDate) < 0)) { throw new IncorrectTimeException($"Performance date has to be between {anEvent.StartDate} and {anEvent.EndDate}"); } artistEvent.PerformanceDate = request.PerformanceDate; _context.SaveChanges(); }
public IActionResult UpdateArtistPerformanceTime(int idArtist, int idEvent, UpdateArtistPerformanceTimeRequest request) { try { _service.UpdateArtistPerformanceTime(idArtist, idEvent, request); return(NoContent()); } catch (EventDoesNotExistsException exception) { return(NotFound(exception.Message)); } catch (ArtistDoesNotParticipateInAnEventException exception) { return(BadRequest(exception.Message)); } catch (EventAlreadyBegunException exception) { return(BadRequest(exception.Message)); } catch (IncorrectTimeException exception) { return(BadRequest(exception.Message)); } }