public ActionResult Update(GigFormViewModel model) { if (ModelState.IsValid) { Gig gig = gigRepository.GetGigWithAttendees(model.Id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } gig.Modify(model, gig); gigRepository.UpdateGig(gig); return(RedirectToAction("Mine", "Gigs")); } else { model.Genres = genreRepository.GetAllGenres(); return(View("GigForm", model)); } }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = unitOfWork.Genres.GetGenres(); return(View("GigForm", viewModel)); } Gig gig = unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } gig.Modify(viewModel.Venue, viewModel.GetDateTime(), viewModel.Genre); unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public void Modify_WhenCalled_ShouldSetVenueDateTimeGenreId() { var gig = new Gig(); var newVenue = "NewVenue"; var newDate = DateTime.Now; var genreId = Byte.MinValue; gig.Modify(newVenue, newDate, genreId); gig.Venue.Should().Be(newVenue); gig.DateTime.Should().Be(newDate); gig.GenreId.Should().Be(genreId); }
public void UpdateGig(Gig gig, InputModelGig input) { try { gig.Modify(input.Venue, input.DateTime, input.Genre); _context.Attach(gig).State = EntityState.Modified; } catch (Exception) { if (!_context.Gigs.Any(e => e.Id == gig.Id)) { throw; } } }
public void Modify_WhenCalled_AllAttendeesShouldBeNotified() { // Arrange var gig = new Gig(); var user = new ApplicationUser(); gig.Attendances.Add(new Attendance() { Attendee = user }); // Act gig.Modify(DateTime.Now, "foo", 1); // Assert Assert.AreEqual(1, user.UserNotifications.Count); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = Context.Genres.ToList(); return(View("GigForm", viewModel)); } string userId = User.Identity.GetUserId(); Gig gig = Context.Gigs.Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDateAdded(), viewModel.Venue, viewModel.Genre); Context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public void Modify_WhenCalled_EachAttendeeShouldHaveNotification() { var gig = new Gig(); gig.Attendances.Add(new Attendance { Attendee = new ApplicationUser { Id = "1" } }); var newVenue = "NewVenue"; var newDate = DateTime.Now; var genreId = Byte.MinValue; gig.Modify(newVenue, newDate, genreId); var notifications = gig.GetAttendees().First().UserNotifications; notifications.Count.Should().Be(1); notifications.First().Notification.Type.Should().Be(NotificationType.GigUpdated); }
public void UpdateGig(Gig gig, DateTime newDate, byte newGenreId, String newVenue) { gig.Modify(newDate, newGenreId, newVenue); }