Exemplo n.º 1
0
        public ArtistEvent UpdateArtistEvent(int id, int idEvent, ArtistEvent artistEventRequest)
        {
            var artistEventExist = _context.ArtistEvent.Where(e => e.IdEvent == idEvent && e.IdArtist == id).Any();

            if (!artistEventExist)
            {
                throw new Exception($"Nie ma eventu w ktorym wystepuje artysta z id = {id} oraz eventu z id = {idEvent}");
            }
            else
            {
                var artistEvent = _context.Event.Where(e => e.IdEvent == idEvent).Single();

                if (artistEvent.StartDate < artistEventRequest.PerformanceDate && artistEvent.EndDate > artistEventRequest.PerformanceDate)
                {
                    var e1 = new ArtistEvent
                    {
                        IdArtist        = id,
                        IdEvent         = idEvent,
                        PerformanceDate = artistEventRequest.PerformanceDate
                    };

                    _context.Attach(e1);
                    _context.Entry(e1).Property("PerformanceDate").IsModified = true;

                    _context.SaveChanges();
                }
                else
                {
                    throw new Exception($"Nieprawidlowa data, lub data nie miesci sie pomiedzy rozpoczeciem eventu a jego zakonczeniem.");
                }
            }
            return(artistEventRequest);
        }
Exemplo n.º 2
0
        public IActionResult UpdateStudent(ModelsGenerated.Student student, string id)
        {
            var db = new s17188Context();
            var s1 = new ModelsGenerated.Student
            {
                IndexNumber = id,
                FirstName   = student.FirstName
            };

            db.Attach(s1);
            db.Entry(s1).Property("FirstName").IsModified = true;

            db.SaveChanges();
            return(Ok(s1));
        }