public ActionResult AddGig(GigViewModel gigViewModel) { if (ModelState.IsValid) { //We Can compare User.Identity.GetUserId() Function in LinQ Method !! // Because this Method is Purely a C Sharp Code !!! // var artist = _context.Users.Where(u => u.Id == User.Identity.GetUserId()); var artistId = User.Identity.GetUserId(); //In the following code, we use the Single method which takes one predicate as a parameter. //Using that predicate we specify our condition which is going to return only one element from the sequence. var artist = _context.Users.Single(u => u.Id == artistId); var genre = _context.Genres.Single(g => g.Id == gigViewModel.SelectedGenreId); _gig.Venue = gigViewModel.Venue; _gig.Artist = artist; _gig.Genre = genre; _gig.DateTime = DateTime.Parse(string.Format("{0} {1}", gigViewModel.Date, gigViewModel.Time)); _context.Gigs.Add(_gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); } return(View()); }
public ActionResult ApplyForGig(int id) { //Gig gig = db.Gigs.Find(id); //Artist artist = db.Artists.Find(User.Identity.GetUserId()); //gig.Artists.Add(artist); //db.SaveChanges(); var gigs = db.Gigs.Include(g => g.Host); List <GigViewModel> gigvms = new List <GigViewModel>(); foreach (Gig g in gigs) { GigViewModel gigvm = CloudConcerts3.Models.ModelMapper.ConvertToGigViewModel(g); var foundApplication = db.ArtistGigs.Where(a => a.ArtistID.Equals(User.Identity.GetUserId())).Where(gi => gi.GigID.Equals(gigvm.GigID)).First(); if (foundApplication != null) { gigvm.hasUserApplied = true; } gigvms.Add(gigvm); } return(View("Apply", gigvms)); }
public ActionResult Edit(int gigId) { var gig = _unitofWork.Gigs.Get(gigId); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } var viewModel = new GigViewModel { Id = gigId, Date = gig.Datetime.ToString("dd MMM yyyy"), Time = gig.Datetime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue, Genres = _unitofWork.Genres.GetAll(), Heading = "Update Gig" }; return(View("GigForm", viewModel)); }
public GigsController() { _context = new ApplicationDbContext(); _gigViewModel = new GigViewModel(); _gig = new Gig(); }
public ActionResult Update(GigViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genre.GetAllGenres(); return(View("GigForm", viewModel)); } string userId = User.Identity.GetUserId(); var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != userId) { return(new HttpUnauthorizedResult()); } gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigViewModel viewModel) { //var userId = User.Identity.GetUserId(); //solve this by create forignkey //var artist = _context.Users.Single(p => p.Id ==userId ); //var genre = _context.Genres.Single(p => p.Id == viewModel.Genre); if (!ModelState.IsValid) { viewModel.Genres = _unitofWork.Genres.GetAll(); return(View("GigForm", viewModel)); } Gig gig = new Gig { ArtistId = User.Identity.GetUserId(), Datetime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue }; _unitofWork.Gigs.Add(gig); _unitofWork.Complete(); return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(int id) { var gig = _unitOfWork.Gigs.GetGigForEdit(id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } var genres = _unitOfWork.Genre.GetAllGenres(); var viewModel = new GigViewModel { Genres = genres, Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Genre = gig.GenreId, Venue = gig.Venue, Heading = "Edit a Gig", Id = gig.Id }; return(View("GigForm", viewModel)); }
public ActionResult Create(GigViewModel formModel) { try { if (!ModelState.IsValid) { formModel.Genres = _context.Genre.ToList(); return(View("Create", formModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), GenreId = formModel.Genre, Venue = formModel.Venue, DateTime = formModel.GetDateTime() }; _context.Gig.Add(gig); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { var errorMessage = ex.Message;//OR ex.ToString(); OR Free text OR an custom object return(View()); } }
public ActionResult Index(string query = null) { var upcomingGigs = _context.Gigs .Include(g => g.Artist) .Include(g => g.Genre) .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled); if (!String.IsNullOrWhiteSpace(query)) { upcomingGigs = upcomingGigs.Where(g => g.Artist.Name.Contains(query) || g.Genre.Name.Contains(query) || g.Venue.Contains(query)); } var userId = User.Identity.GetUserId(); var attendances = _context.Attendances .Where(a => a.AttendeeId == userId && a.Gig.DateTime > DateTime.Now) .ToList() .ToLookup(a => a.GigId); var viewModel = new GigViewModel { UpcomingGigs = upcomingGigs, ShowActions = User.Identity.IsAuthenticated, Heading = "Upcoming Gigs", SearchTerm = query, Attendances = attendances }; return(View("Gigs", viewModel)); }
public ActionResult Details(int id) { var gig = _context.Gigs .Include(g => g.Artist) .Include(g => g.Genre) .SingleOrDefault(g => g.Id == id); if (gig == null) { return(HttpNotFound()); } var viewModel = new GigViewModel { Gig = gig }; if (User.Identity.IsAuthenticated) { var userId = User.Identity.GetUserId(); viewModel.IsAttending = _context.Attendances .Any(a => a.GigId == gig.Id && a.AttendeeId == userId); viewModel.IsFollowing = _context.Followings .Any(f => f.FolloweeId == gig.ArtistId && f.FollowerId == userId); } return(View("Details", viewModel)); }
public ActionResult Attending() { var userId = User.Identity.GetUserId(); var gigs = _context.Attendances .Where(a => a.AttendeeId == userId) .Select(a => a.Gig) .Include(g => g.Artist) .Include(g => g.Genre) .ToList(); var attendances = _context.Attendances .Where(a => a.AttendeeId == userId && a.Gig.DateTime > DateTime.Now) .ToList() .ToLookup(a => a.GigId); var viewModel = new GigViewModel { UpcomingGigs = gigs, ShowActions = User.Identity.IsAuthenticated, Heading = "Gigs I'm Attending", Attendances = attendances }; return(View("Gigs", viewModel)); }
public ActionResult Edit(int gigId) { var gig = _unitOfWork.Gigs.GetGigById(gigId); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } var gigViewModel = new GigViewModel() { Date = gig.DateTime.ToString("d MMM yyyy"), Time = gig.DateTime.ToString("HH:mm"), Venue = gig.Venue, Id = gig.Id, Genre = gig.GenreId, Genres = _unitOfWork.Genres.GetGenres(), Heading = "Edit Gig" }; return(View("GigForm", gigViewModel)); }
public ActionResult Index(string SearchTerm = null) { var upcomingGigs = _context.Gigs .Include(g => g.Artist) .Include(g => g.Genre) .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled); if (!string.IsNullOrWhiteSpace(SearchTerm)) { upcomingGigs = upcomingGigs .Where(g => g.Artist.Name.Contains(SearchTerm) || g.Genre.Name.Contains(SearchTerm) || g.Venue.Contains(SearchTerm)); } var userid = User.Identity.GetUserId(); var attendances = _attendanceRepository.GetFutureAttendances(userid) .ToLookup(a => a.GigId); var viewmodel = new GigViewModel { Gigs = upcomingGigs, Attendances = attendances }; return(View(viewmodel)); }
public ActionResult index(string query = null) { var upComingGig = _unitOfWork.Gigs.GetFutureGig(); if (!string.IsNullOrWhiteSpace(query)) { upComingGig = upComingGig.Where(g => g.Genre.Name.Contains(query) || g.Artist.Name.Contains(query) || g.Venue.Contains(query)).ToList(); } string userId = User.Identity.GetUserId(); GigViewModel model = new GigViewModel() { UpComingGigs = upComingGig, ShowActions = User.Identity.IsAuthenticated, Heading = "Upcoming Gig ", SearchTerm = query, Attendances = _unitOfWork.Attendaces.GetFutureAttandance(userId). ToLookup(g => g.GigId) /*_attendaceRepository.GetFutureAttandance(userId). * ToLookup(g => g.GigId)*/ }; return(View("Gigs", model)); }
public ActionResult Update(GigViewModel 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); //update gig.Update(viewModel.DateTime, viewModel.Genre, viewModel.Venue); gig.Venue = viewModel.Venue; gig.GenreId = viewModel.Genre; gig.DateTime = viewModel.DateTime; _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public async Task <bool> CreateGigAsync(GigViewModel model, bool isArtist) { var entity = new Gig() { OwnerId = _userId, Date = model.Date, PostalCode = model.PostalCode }; if (isArtist) { entity.IsRequest = false; } else { entity.IsRequest = true; } using (var context = new ApplicationDbContext()) { context.Gigs.Add(entity); return(await context.SaveChangesAsync() == 1); } }
public ActionResult Create() { var viewModel = new GigViewModel(); viewModel.Genres = _context.Genres.ToList(); return(View(viewModel)); }
public IActionResult Create() { var gigsViewModel = new GigViewModel() { Genres = GetGenres().GetAwaiter().GetResult() }; return(View(gigsViewModel)); }
public ActionResult Create() { GigViewModel model = new GigViewModel { Genres = _context.Genre.ToList() }; return(View(model)); }
public IActionResult Create() { var gigViewModel = new GigViewModel() { Genres = _context.Genres.ToList() }; return(View(gigViewModel)); }
public ActionResult Create() { var viewModel = new GigViewModel { Genres = _context.Genres.ToList(), Heading = "Add a Gig" }; return(View("GigForm", viewModel)); }
public ActionResult Create() { var gigVM = new GigViewModel() { Genres = _unitOfWork.Genres.GetGenres(), Heading = "Add a Gig" }; return(View("GigForm", gigVM)); }
public ActionResult Create() { var ViewModel = new GigViewModel { Genres = _unitofWork.Genres.GetAll(), Heading = "Create Gig" }; return(View("GigForm", ViewModel)); }
public ActionResult Create() { var viewModel = new GigViewModel { Genres = _unitOfWork.Genre.GetAllGenres(), Heading = "Add a Gig" }; return(View("GigForm", viewModel)); }
public ActionResult Index() { var viewModel = new GigViewModel { Gig = _context.Gigs.ToList(), Genre = _context.Genres.ToList() }; return(View(viewModel)); }
private List<GigViewModel> MakeViewModels(IEnumerable<Gig> gigs) { List<GigViewModel> models = new List<GigViewModel>(); foreach (Gig gig in gigs) { GigViewModel model = new GigViewModel { Date = gig.Date, Id = gig.Id, Name = gig.Name }; models.Add(model); } return models; }
public ActionResult Attending() { var userid = User.Identity.GetUserId(); var viewmodel = new GigViewModel { Gigs = _unitOfWork.Gigs.GetGigsUserAttending(userid), Attendances = _unitOfWork.Attendances.GetFutureAttendances(userid) .ToLookup(a => a.GigId) }; return(View(viewmodel)); }
public ActionResult Index() { var upcomingGigs = _context.Gigs .Include(g => g.Artist) .Include(g => g.Genre) .Where(g => g.DateTime > DateTime.Now); GigViewModel homeModel = new GigViewModel { UpComingGigs = upcomingGigs, ShowAction = User.Identity.IsAuthenticated }; return(View("Gigs", homeModel)); }
public ActionResult Attending() { string userId = User.Identity.GetUserId(); var viewModel = new GigViewModel { UpcomingGigs = _unitOfWork.Gigs.GetGigUserAttending(userId), ShowActions = User.Identity.IsAuthenticated, Heading = "Gigs I'm attending", Attendaces = _unitOfWork.Attendance.GetFutureAttendance(userId).ToLookup(a => a.GigId) }; return(View("Gigs", viewModel)); }
public ActionResult Attending() { var userId = User.Identity.GetUserId(); var gigs = _context.Attendances. Where(a => a.AttendeeId == userId).Select(a => a.Gig) .Include(g => g.Artist) .Include(g => g.Genre); var gigAttendingView = new GigViewModel { UpComingGigs = gigs, ShowAction = User.Identity.IsAuthenticated }; return(View("Gigs", gigAttendingView)); }
public IHttpActionResult Post(GigViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateGigService(); if (!service.CreateGig(model)) { return(InternalServerError()); } return(Ok()); }
private List<GigViewModel> makeViewModels(IEnumerable<Gig> gigs) { List<GigViewModel> gigViewModels = new List<GigViewModel>(); foreach (Gig gig in gigs) { GigViewModel model = new GigViewModel {Id = gig.Id, Date = gig.Date}; if (gig.Private) { model.Name = "Private Booking"; model.ShowDetailsLink = false; } else { model.Name = gig.Name; model.ShowDetailsLink = true; } gigViewModels.Add(model); } return gigViewModels; }