/************************************
         *           VENUE PROFILE
         * *********************************/
        // GET: Venues/Details/5
        public ActionResult Details(int?id)
        {
            // If no user is passed through
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Venue venue = db.Venues.Find(id);

            // If user doesn't exisit
            if (venue == null)
            {
                return(HttpNotFound());
            }

            var identityID = User.Identity.GetUserId();

            VenueOwnerDetailViewModel viewModel = new VenueOwnerDetailViewModel(venue);

            viewModel.UpcomingShows = db.User_Show.Where(u => u.VenueOwnerID == venue.UserID).Select(s => s.Show).Where(s => s.StartDateTime > DateTime.Now && s.Status == "Accepted").OrderByDescending(s => s.EndDateTime).ToList();
            viewModel.VenueList     = new SelectList(db.Venues.Where(v => v.User.ID == venue.ID), "ID", "VenueName");

            User user = db.Users.Find(id);

            string profilePath = "";

            if (user.ProfilePictureID == 1)
            {
                profilePath = "/Profiles/male.jpg";
            }
            else if (user.ProfilePictureID == 2)
            {
                profilePath = "/Profiles/female.jpg";
            }
            else if (user.ProfilePictureID == 3)
            {
                profilePath = "/Profiles/nonbinary.jpg";
            }
            ViewBag.ProfilePath = profilePath;

            return(View(viewModel));
        }
        public async Task <ActionResult> PerformanceRequest(int?id, VenueOwnerDetailViewModel viewModel)
        {
            // No user id passed through
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Venue venue = db.Venues.Find(id);

            // If users doesn't exisit
            if (venue == null)
            {
                return(HttpNotFound());
            }

            // Viewmodel for VenueOwner
            VenueOwnerDetailViewModel model = new VenueOwnerDetailViewModel(venue);

            var IdentityID = User.Identity.GetUserId();

            viewModel.VenueList = new SelectList(db.Venues.Where(v => v.User.ID == venue.ID), "ID", "VenueName");

            if (ModelState.IsValid)
            {
                // Get user's calendar credentials
                UserCredential credential = await GetCredentialForApiAsync();

                // Create Google Calendar API service.
                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = "Harmony",
                });

                // Fetch the list of calendars.
                var calendars = await service.CalendarList.List().ExecuteAsync();

                // create a new event to google calendar
                if (calendars != null)
                {
                    Event newEvent = new Event()
                    {
                        Id          = Guid.NewGuid().ToString().Replace('-', '0'),
                        Summary     = viewModel.Title,
                        Description = viewModel.ShowDescription,
                        Location    = model.VenueName,
                        Start       = new EventDateTime()
                        {
                            DateTime = viewModel.StartDateTime.AddHours(7.0),
                            TimeZone = "America/Los_Angeles"
                        },
                        End = new EventDateTime()
                        {
                            DateTime = viewModel.EndDateTime.AddHours(7.0),
                            TimeZone = "America/Los_Angeles"
                        },
                        Attendees = new List <EventAttendee>()
                        {
                            new EventAttendee()
                            {
                                Email = model.OwnerEmail
                            }
                        },
                        GuestsCanModify = true
                    };
                    var newEventRequest = service.Events.Insert(newEvent, "primary");
                    // This allows attendees to get email notification
                    newEventRequest.SendNotifications = true;
                    var eventResult = newEventRequest.Execute();

                    // add the new show to db
                    Show newShow = new Show
                    {
                        Title         = viewModel.Title,
                        StartDateTime = viewModel.StartDateTime,
                        EndDateTime   = viewModel.EndDateTime,
                        Description   = viewModel.ShowDescription,
                        DateBooked    = newEvent.Created ?? DateTime.Now,
                        VenueID       = model.ID,
                        Status        = "Pending",
                        GoogleEventID = newEvent.Id,
                        ShowOwnerID   = db.Users.Where(u => u.ASPNetIdentityID == IdentityID).First().ID
                    };
                    db.Shows.Add(newShow);
                    User_Show user_Show = new User_Show
                    {
                        MusicianID    = db.Users.Where(u => u.ASPNetIdentityID == IdentityID).First().ID,
                        VenueOwnerID  = model.UserID,
                        ShowID        = newShow.ID,
                        MusicianRated = false,
                        VenueRated    = false
                    };
                    db.User_Show.Add(user_Show);
                    db.SaveChanges();
                }

                return(RedirectToAction("Details", new { id = model.ID }));
            }

            return(View(model));
        }