public ActionResult Update(MahfilFormViewModel model) { if (!ModelState.IsValid) { model.Genres = _context.Genres.ToList(); return(View("CongregrationForm", model)); } var congregration = _mahfilMepository.GetMahfilWithAttendees(model.Id); if (congregration == null) { return(HttpNotFound()); } if (congregration.SpeakerId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } congregration.Venue = model.Venue; congregration.DateTime = model.GetDateTime(); congregration.GenreId = model.Genre; _context.SaveChanges(); return(RedirectToAction("Mine", "Mahfil")); }
public ActionResult Create(MahfilFormViewModel model) { if (!ModelState.IsValid) { model.Genres = _genreRepository.GetGenres(); return(View("CongregrationForm", model)); } var speakerId = User.Identity.GetUserId(); //var speaker = _context.Users.Single(x => x.Id == speakerId); //var genre = _context.Genres.Single(x => x.Id == model.Genre); var mahfil = new Congregration() { Id = Guid.NewGuid().ToString(), SpeakerId = speakerId, //Speaker = speaker, DateTime = model.GetDateTime(), //Genre = genre, GenreId = model.Genre, Venue = model.Venue }; _mahfilMepository.Add(mahfil); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Mahfil")); }