Пример #1
0
        public void PutEvents(int artistId, int eventId, PutArtistRequest request)
        {
            var artistExists = _context.Artists.Any(x => x.IdArtist.Equals(artistId));
            var eventExists  = _context.Events.Any(x => x.IdEvent.Equals(eventId));

            if (!artistExists || !eventExists)
            {
                throw new ArtistOrEventNotExistingException($"Artist {artistId} or {eventId} doesnt exist");
            }

            var eventToUpdate = _context.Events.Single(x => x.IdEvent.Equals(eventId));

            var eventHasStarted = eventToUpdate.StartDate <= DateTime.Now;

            if (eventHasStarted)
            {
                throw new EventHasStartedException($"The event {eventId} has started");
            }

            var newDateInRange = request.PerfomanceDate >= eventToUpdate.StartDate &&
                                 request.PerfomanceDate <= eventToUpdate.EndDate;

            if (!newDateInRange)
            {
                throw new DateNotInRangeException("The passed date is not in range");
            }

            eventToUpdate.StartDate = request.PerfomanceDate;
            _context.SaveChanges();
        }
Пример #2
0
 public IActionResult PutEvents(int artistId, int eventId, PutArtistRequest request)
 {
     try
     {
         _dbService.PutEvents(artistId, eventId, request);
         return(Ok());
     }
     catch (ArtistOrEventNotExistingException exc)
     {
         return(NotFound(exc.Message));
     }
     catch (EventHasStartedException exc)
     {
         return(Conflict(exc.Message));
     }
     catch (DateNotInRangeException exc)
     {
         return(BadRequest(exc.Message));
     }
     catch (Exception exc)
     {
         return(NotFound(exc.Message));
     }
 }