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(a => a.ID == ViewModel.ID && a.ArtistID == UserID); Gig.Venue = ViewModel.Venue; Gig.DateTime = ViewModel.GetDateTime(); Gig.GenreID = ViewModel.Genre; _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
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 Edit(int id) { var userId = User.Identity.GetUserId(); var gig = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId); var genres = _genreRepository.GetGenres(); var viewModel = new GigFormViewModel { Id = gig.Id, Genres = genres, Venue = gig.Venue, Date = gig.Date.ToString("dd MMM yyyy"), Time = gig.Date.ToString("HH:mm"), Genre = gig.GenreId, Heading = "Edit a Gig" }; return(View("GigForm", viewModel)); }
public ActionResult Edit(int id) { var gig = unitofwork.Gigs.GetGigToEdit(id, User.Identity.GetUserId()); var genres = unitofwork.Genres.GetAllGenres(); var viewModel = new GigFormViewModel { Id = gig.Id, Heading = "Edit a Gig", Genres = genres, Date = gig.Datetime.ToString("dd/MM/yyyy"), Time = gig.Datetime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue }; return(View("GigForm", viewModel)); }
public ActionResult Create(GigFormViewModel viewModel) { //var artistId = User.Identity.GetUserId(); //var artist = _context.Users.Single(u => u.Id == artistId); //var genre = _context.Genres.Single(g => g.Id == viewModel.Genre); var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.DateTime, GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(int id) { var userId = User.Identity.GetUserId(); var gig = _context.Gigs.SingleOrDefault(x => x.Id == id && x.ArtistId == userId); var viewModel = new GigFormViewModel() { Heading = "Edit a Gig", Id = gig.Id, Genres = _context.Genres.ToList(), Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue }; return(View("GigForm", viewModel)); }
public ActionResult Edit(int id) //gets the id passed over from view as an anonymus object { var userId = User.Identity.GetUserId(); var singleGig = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId); var viewModel = new GigFormViewModel { Genres = _context.Genres.ToList(), Id = singleGig.Id, Date = singleGig.DateTime.ToString("d MMM yyyy"), Time = singleGig.DateTime.ToString("HH:mm"), Genre = singleGig.GenreId, Venue = singleGig.Venue, Heading = "Edit Gig" }; return(View("GigForm", viewModel)); }
public ActionResult Create(GigFormViewModel viewModel) { var artistId = User.Identity.GetUserId(); var artist = _context.Users.Single(u => u.Id == artistId); var genre = _context.Genres.Single(g => g.Id == viewModel.Genre); var gig = new Gig { Artist = artist, DateTime = DateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time)), Genre = genre, Venu = viewModel.Venu }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
[ValidateAntiForgeryToken] // prevent csrf attack 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(a => a.Attendances.Select(s => s.Attendee)) // eager eager loading .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Modify(viewModel.GetDatetime(), viewModel.Venue, viewModel.Genre); _context.SaveChanges(); return(RedirectToAction("Mine")); }
public ActionResult Edit(int id) { var userId = User.Identity.GetUserId(); Gig gig = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId); GigFormViewModel viewModel = new GigFormViewModel { Id = gig.Id, Genres = _context.Genres.ToList(), Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue, Heading = "Edit a Gig" }; return(View("GigsForm", viewModel)); }
public ActionResult Edit(int id) { var userId = User.Identity.GetUserId(); var gig = _context.Gigs.Where(g => g.Id == id && g.ArtistId == userId).FirstOrDefault(); var viewModel = new GigFormViewModel { Id = id, Heading = $"Edit {gig.Genre}", Genres = _context.Genres.ToList(), Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue }; return(View("GigForm", viewModel)); }
public ActionResult Create(GigFormViewModel viewModel) { //var artistId = User.Identity.GetUserId(); //Lamda expression doesn't understand the User.Identity.GetUserId() method //so we need to extract the value and store it to a separate variable artistId. //var artist = _context.Users.Single(u => u.Id == artistId); //var genre = _context.Genres.Single(g => g.Id == viewModel.Genre); if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), //This below line is not a good SoC, controller should not do the job of parsing //a variable. So there is a INFORMATION EXPERT principal which means the class or //the object has the information to do sth should be one that will carry that responsibility. // In this case, it is viewModel who knows the Date and Time so it should be ViewModel to tackle // the string format /* * //Metaphor: A Chef knows recipes so he is the one does the cook. -- Information Expert Principal. */ //DateTime = DateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time)), //Instead create a DateTime Property to transfter date time to string DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(GigFormViewModel viewModel) { /* * This used to be 2 calls to the DB to get the artist and genre for the currently logged in user. * But by changing the Domain Model (adding FK's GenreId and ArtistId) these calls are unnecessary. * --> When loading the view, everything is loaded using foreign keys. * * var artistId = User.Identity.GetUserId(); * var artist = _context.Users.Single(u => u.Id == artistId); * var genre = _context.Genres.Single(g => g.Id == viewModel.Genre); */ if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("Create", viewModel)); } var gig = new Gig { /* * Artist = artist, * Genre = genre, */ /* * Parsing is too detailed for a Controller. * A Controller is like a manager, coördination only. * * DateTime = DateTime.Parse($"{viewModel.Date} {viewModel.Time}"), */ ArtistId = User.Identity.GetUserId(), GenreId = viewModel.Genre, DateTime = viewModel.GetDateTime(), Venue = viewModel.Venue }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); //temporary send the user to the homepage. }
public ActionResult Edit(int id) { var userId = User.Identity.GetUserId(); var gig = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId); var viewModel = new GigFormViewModel { Genres = _context.Genres.ToList(), // Initialize the Id property otherwise it add a new gig instead of updating Id = gig.Id, Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:MM"), Genre = gig.GenreId, Venue = gig.Venue, Heading = "Edit a Gig!" }; return(View("GigForm", viewModel)); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _genreRepository.GetAllGenres(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue, }; _gigRepository.AddGig(gig); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Edit(GigFormViewModel gigFormViewModel) { //mapping vm to db obj and save in DB Gig gig = null; var currentlyloggedUserId = User.Identity.GetUserId(); gig = dbContext.Gigs.Where(e => e.Id == gigFormViewModel.Id && e.ArtistId == currentlyloggedUserId).SingleOrDefault(); if (gigFormViewModel != null) { gig.Modifiy(gigFormViewModel.Venue, gigFormViewModel.GetDateTime(), gigFormViewModel.Genere); //dbContext.Gigs.Attach(gig); dbContext.SaveChanges(); } List <Gig> gigsLsList = dbContext.Gigs.ToList(); return(RedirectToAction("ViewMyUpCommingGigs", "Gigs")); }
public ActionResult Create(GigFormViewModel ViewModel) { if (!ModelState.IsValid) { ViewModel.Genres = _unitOfWork.Genres.GetGenres(); return(View("GigForm", ViewModel)); } Gig gig = new Gig( _unitOfWork.ApplicationUser.GetArtist(User.Identity.GetUserId()), ViewModel.GetDatetime(), ViewModel.Venue, ViewModel.Genre ); _unitOfWork.Gigs.Add(gig); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Edit(int id) { var userId = User.Identity.GetUserId(); var gig = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId); var ViewModel = new GigFormViewModel { // get a list of genres from the Genres database table Heading = "Edit Gig", Id = gig.Id, Genres = _context.Genres.ToList(), Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue }; return(View("GigForm", ViewModel)); }
public ActionResult Update(GigFormViewModel model) { if (!ModelState.IsValid) { model.Genres = _context.Genre.ToList(); return(View("GigForm", model)); } var userId = User.Identity.GetUserId(); var gig = _context.Gig .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == model.Id && g.ArtistId == userId); gig.Update(model.GetDateTime(), model.Venue, model.Genre); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Edit(GigFormViewModel viewmodel) { // makesure of the validation of the form properties if (!ModelState.IsValid) { viewmodel.Genres = _Context.Genres.ToList(); return(View("GigForm", viewmodel)); } var userId = User.Identity.GetUserId(); var genre = _Context.Genres.Single(g => g.Id == viewmodel.Genre); // eager loading var gig = _Context.Gigs .Include(a => a.Attendances.Select(b => b.Attendee)) .Single(s => s.Id == viewmodel.Id && s.ArtistId == userId); gig.modify(viewmodel.GetDateTime(), viewmodel.Venue, viewmodel.Genre); _Context.SaveChanges(); return(RedirectToAction("mine", "Gigs")); }
public ActionResult Update(int gigid) { var Artist = User.Identity.GetUserId(); var gig = DB.Gigs.Single(g => g.id == gigid && g.ArtistID == Artist); GigFormViewModel model = new GigFormViewModel() { id = gigid, Genres = DB.Genres.ToList(), Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreID, Venue = gig.Venue, Heading = "Edit a gig " }; return(View("GigForm", model)); }
public ActionResult Create(GigFormViewModel gigViewModel) { if (!ModelState.IsValid) { gigViewModel.Genres = _unitOfWork.Genres.GetGenres(); return(View("GigForm", gigViewModel)); } _unitOfWork.Gigs.AddGig(Gig.Create(User.Identity.GetUserId(), _unitOfWork.Followings.GetFollowersByArtist(User.Identity.GetUserId()), gigViewModel.GetDateTime(), gigViewModel.Venue, gigViewModel.Genre)); _unitOfWork.Complete(); return(RedirectToAction("MyUpcomingGigs", "Gig")); }
public ActionResult Create(GigFormViewModel formViewModel) { if (ModelState.IsValid) { formViewModel.Genres = _context.Genres.ToList(); return(View("GigForm", formViewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), GigDate = formViewModel.GetDateTime(), GenreId = formViewModel.Genre, Venue = formViewModel.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("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)); } var userId = User.Identity.GetUserId(); var gigs = Context.Gigs .Include(x => x.Attendences.Select(a => a.Attendee)) .Single(x => x.Id == viewModel.Id && x.ArtistId == userId); gigs.Modify(viewModel.Vanue, viewModel.GetDateTime(), viewModel.Genre); Context.SaveChanges(); return(RedirectToAction("MyUpcomingGigs", "Gigs")); }
public ActionResult Edit(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var userId = User.Identity.GetUserId(); var gig = _context.Gigs.FirstOrDefault(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Venue = viewModel.Venue; gig.DateTime = viewModel.GetDateTime(); gig.GenreId = viewModel.Genre; _context.SaveChanges(); return(RedirectToAction(nameof(Mine))); }
public IActionResult Create(GigFormViewModel gigModel) { if (!ModelState.IsValid) { gigModel.Genres = _dbContext.Genres; return(View(gigModel)); } var artistId = _userManager.GetUserId(User); var gig = new Gig { ArtistId = artistId, GenreId = gigModel.Genre, Venue = gigModel.Venue, DateTime = DateTime.Parse(string.Format("{0} {1}", gigModel.Date, gigModel.Time)) }; _dbContext.Gigs.Add(gig); _dbContext.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenresList(); return(View("Create", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), Venue = viewModel.Venue, GenreId = viewModel.Genre }; _unitOfWork.Gigs.Add(gig); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = Context.Genres.ToList(); return(View("GigForm", viewModel)); } var gigs = new Gig() { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Vanue = viewModel.Vanue, }; Context.Gigs.Add(gigs); Context.SaveChanges(); return(RedirectToAction("MyUpcomingGigs", "Gigs")); }
public void Modify(GigFormViewModel updatedViewModel) { //CODE FOR GIG Descreption = updatedViewModel.Descreption; GigName = updatedViewModel.GigName; UserRating = updatedViewModel.UserRating; //CODE FOR BASIC PACKAGE BasicPackage.Modify(updatedViewModel); //CODE FOR ADVANCED PACKAGE AdvancedPackage.Modify(updatedViewModel); //CODE FOR PREMIUM PACKAGE PremiumPackage.Modify(updatedViewModel); //CODE FOR SPECIFIC INDUSTRY SpecificIndustryID = updatedViewModel.SpecificIndustryID; }