示例#1
0
 public IActionResult SetPerfomanceDate(int idArtist, int idEvent, AktualizationDateRequest request)
 {
     try
     {
         dbService.SetPerfomanceDate(idArtist, idEvent, request);
         return(Ok("Data była zmienniona!"));
     }
     catch (IncorrectDateException incexcp)
     {
         return(BadRequest(incexcp.Message));
     }
     catch (ArtistEventNotFoundException artExc)
     {
         return(NotFound(artExc.Message));
     }
 }
示例#2
0
        public void SetPerfomanceDate(int idArtist, int idEvent, AktualizationDateRequest aktualizationDateRequest)
        {
            // Найти Артист_Евен
            // Проверить границы времени
            var artistEventList = dbContext.ArtistEvent.Where(e => (e.IdArtist == idArtist) && (e.IdEvent == idEvent))
                                  .Select(e => new ArtistEvent {
                IdArtist           = e.IdArtist,
                IdEvent            = e.IdEvent,
                IdEventNavigation  = e.IdEventNavigation,
                IdArtistNavigation = e.IdArtistNavigation
            }
                                          ).ToList();

            if (artistEventList == null || artistEventList.Count() == 0)
            {
                throw new ArtistEventNotFoundException("Nie znalieziono ArtistEvent z idArtista " + idArtist + " i idEvent " + idEvent);
            }

            foreach (var artistEvent in artistEventList)
            {
                if (DateTime.Now > artistEvent.IdEventNavigation.StartDate
                    ||
                    aktualizationDateRequest.PerfomanceDate < artistEvent.IdEventNavigation.StartDate
                    ||
                    aktualizationDateRequest.PerfomanceDate > artistEvent.IdEventNavigation.EndDate)
                {
                    throw new IncorrectDateException("Niepoprawna data ");
                }
            }

            dbContext.ArtistEvent.RemoveRange(artistEventList);

            foreach (var artistEvent in artistEventList)
            {
                artistEvent.PerfomanceDate = aktualizationDateRequest.PerfomanceDate;
            }
            dbContext.ArtistEvent.AddRange(artistEventList);
            dbContext.SaveChanges();
        }