public ActionResult Create(GigFormViewModel viewModel) { /*Check if it is valid*/ if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); /* this is needed to pre-build the gig */ return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(GigFormViewModel viewModel) { //if something went wrong, return the same view with the typed data and the error messages if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) // we need to convert viewModel into gig model and save it { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); viewModel.Heading = "Edit a gig"; return(View("GigForm", viewModel)); } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public async Task <ActionResult> Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _dbContext.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig() { Venue = viewModel.Venue, ArtistId = User.FindFirstValue(ClaimTypes.NameIdentifier), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre }; _dbContext.Add(gig); await _dbContext.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenres(); return View("GigForm", viewModel); } var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id); if (gig == null) return HttpNotFound(); if (gig.ArtistId != User.Identity.GetUserId()) return new HttpUnauthorizedResult(); gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); _unitOfWork.Complete(); return RedirectToAction("Mine", "Gigs"); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenres(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _unitOfWork.Gigs.Add(gig); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel viewModel) { if (this.ModelState.IsValid) { var userId = User.Identity.GetUserId(); var gig = this.context.Gigs .Include(g => g.Attendances.Select(att => att.Attendee)) .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Venue = viewModel.Venue; gig.DateTime = viewModel.GetDateTime(); gig.GenreId = viewModel.Genre; gig.Update(); this.context.SaveChanges(); return(this.RedirectToAction("Mine", "Gigs")); } viewModel.Genres = this.context.Genres.ToList(); return(this.View("GigForm", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); // This is necessary to populate the Genres dropdown when we re-show them the form return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); //if not valid, the page will be displayed with valid messages } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) // In order to remove getting list of attendees .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { //used cntr shift R to refactor and inline variable //therfore combining it where it is used below //var artistId = User.Identity.GetUserId(); //var genreId = viewModel.Genre; //below are no longer used changed were made to model and migration made to //simplify this replacing Artist and Genre //var artist = _context.Users.Single(u => u.Id == artistId); //var genre = _context.Genres.Single(g => g.Id == genreId); //if below is not valid returns create view and used viewmodel passed to this method so all existing values are present along with validation methods. if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenres();//this was done to prevent returning null in view when rending dropdown list GENRES IS NOt POPULATED return(View("GigForm", viewModel)); } var gig = new Gig { //Artist = artist, ArtistId = User.Identity.GetUserId(), //GetDateTime = GetDateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time)), DateTime = viewModel.GetDateTime(), //Genre = genre, GenreId = viewModel.Genre, Venue = viewModel.Venue }; _unitOfWork.Gigs.Add(gig); _unitOfWork.Complete(); // _context.Gigs.Add(gig); //_context.SaveChanges(); //instead of redirecting to home we will redirct to myy upcoming gigs // return RedirectToAction("Index", "Home"); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; try { _context.Gigs.Add(gig); _context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage); } } throw; } return(RedirectToAction("Index", "Home")); }
[ValidateAntiForgeryToken]//Anti Cross Site Request Forgeryf public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) //invalid model { viewModel.Generes = dbContext.Generes.ToList(); //bug fix : while post back ,viewModel is a new object ,Geners not intialized return(View("GigForm", viewModel)); } var gig = new Gig() { ArtistId = User.Identity.GetUserId(), //Get Currently logged User. DateTime = viewModel.GetDateTime(), //combine two fields to one filed: {data,time}=>datetime GenereId = viewModel.Genere, // type of music selected by user Venue = viewModel.Venue //the place selected by user }; dbContext.Gigs.Add(gig); dbContext.SaveChanges(); return(RedirectToAction("ViewMyUpCommingGigs", "Gigs")); //return View(); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Gigform", viewModel)); } var UserId = User.Identity.GetUserId(); var gig = _context.Gigs.Single(g => g.Id == viewModel.id && g.ArtistId == UserId); gig.Venue = viewModel.Venue; gig.DateTime = viewModel.GetDateTime(); gig.GenreId = viewModel.Genre; _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel ViewModel) { if (!ModelState.IsValid) { ViewModel.Genres = new ApplicationDbContext().Genres.ToList(); return(View("GigForm", ViewModel)); } var gig = _unitOfWork.Gigs.GetGigWithAttendees(ViewModel.id); if (IsArtistAUser(gig, out ActionResult actionResult)) { return(actionResult); } gig.Modify(ViewModel.GetDateTime(), ViewModel.Venue, ViewModel.Genre); _unitOfWork.Complate(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Edit(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenres(); return(View("GigForm", viewModel)); } // we make that beacuse it translated into sql query and sql didn't know what identity and getuserId() var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } gig.Modify(viewModel.GetDateTime(), viewModel.Genre, viewModel.Venue); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel model) { if (!ModelState.IsValid) { model.Genres = _context.Genres.ToList(); return(View("Create", model)); } //var artist = _context.Users.Single(u => u.Id == User.Identity.GetUserId()); // var genre = _context.Genres.Single(g => g.Id == model.Genre); var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = model.GetDateTime(), GenreId = model.Genre, Venue = model.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(GigFormViewModel viewModel) { //Si se tiene errores, que se cargue nuevamente pero con los datos que había completado en el formulario if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Create(GigFormViewModel viewModel) { if (ModelState.IsValid == false) { viewModel.Genres = await _unitOfWork.Genres.GetAll(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _unitOfWork.Gigs.Add(gig); await _unitOfWork.Complete(); return(RedirectToAction("Mine")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } //covert view model to gig object, add to context and save changes var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); //temporary redirect user to homepage }
public ActionResult Create(GigFormViewModel viewmodel) { // makesure of the validation of the form properties if (!ModelState.IsValid) { viewmodel.Genres = _Context.Genres.ToList(); return(View("GigForm", viewmodel)); } var genre = _Context.Genres.Single(g => g.Id == viewmodel.Genre); var gig = new GIg { ArtistId = User.Identity.GetUserId(), DateTime = viewmodel.GetDateTime(), GenreId = viewmodel.Genre, Venue = viewmodel.Venue }; _Context.Gigs.Add(gig); _Context.SaveChanges(); return(RedirectToAction("mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), //The user here enters DATE and TIME uniquely from GigFormViewModel GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); //Before the user was directed to ("index", "Home") index in HomeController //but we need to redirect them to mine after they Create a Gig }
public ActionResult Create(GigFormViewModel model) { if (!ModelState.IsValid) { model.Genres = _context.Genres.ToList(); model.Heading = "Add a Gig"; return(View("GigForm", model)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = model.GetDateTime(), GenreId = model.Genre, Venue = model.Venue }; var notification = Notification.GigCreated(gig); _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (ModelState.IsValid) { var gig = new Gig() { GenreId = viewModel.Genre, ArtistId = User.Identity.GetUserId(), Venue = viewModel.Venue, DateTime = viewModel.GetDateTime() }; _unitOfWork.Gigs.Add(gig); _unitOfWork.Commit(); } else { viewModel.Genres = _unitOfWork.Genres.GetAllGenres(); return(View("GigForm", viewModel)); } return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel ViewModel) { if (!ModelState.IsValid) { // get a list of genres from the Genres database table ViewModel.Genres = _context.Genres.ToList(); return(View("GigForm", ViewModel)); // the returned view (GigFormView needs Genres to be populated again } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == ViewModel.Id && g.ArtistId == userId); gig.Modify(ViewModel.GetDateTime(), ViewModel.Venue, ViewModel.Genre); _context.SaveChanges(); //Then redirect the user back to the home page return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel Model) { if (!ModelState.IsValid) { Model.Genres = DB.Genres.ToList(); return(View("GigForm", Model)); } var gig = new Gig() { ArtistID = User.Identity.GetUserId(), GenreID = Model.Genre, DateTime = Model.GetDateTime(), Venue = Model.Venue }; DB.Gigs.Add(gig); DB.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); //gig.Venue = viewModel.Venue; //gig.DateTime = viewModel.GetDateTime(); //this combines date and time and reutnrs them as an object //gig.GenreId = viewModel.Genre; _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Heading = "Add a Gig"; viewModel.Genres = _unitOfWork.Genres.GetGenres(); return(View("GigForm", viewModel)); } var artistId = User.Identity.GetUserId(); var gig = new Gig(artistId, viewModel.Location, viewModel.GetDateTime(), viewModel.GenreId); _unitOfWork.Gigs.Add(gig); var followers = _unitOfWork.Followings.GetFollowersByArtist(artistId); gig.NotifyGigCreation(followers); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); // The input fields will be displayed with validation messages. } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); //gig.Venue = viewModel.Venue; //gig.DateTime = viewModel.GetDateTime(); //gig.GenreId = viewModel.Genre; _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }