public ActionResult Create(Venue venue)
        {
            if (ModelState.IsValid)
            {
                db.Venues.Add(venue);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Venue_CountryId = new SelectList(db.CountryRegions.OrderBy(c => c.CountryRegion_Name), "CountryRegion_Id", "CountryRegion_Code", venue.Venue_CountryId);
            ViewBag.Venue_StateProvinceId = new SelectList(db.StateProvinces.OrderBy(s => s.StateProvince_Name), "StateProvince_Id", "StateProvince_Code", venue.Venue_StateProvinceId);
            return View(venue);
        }
        public ActionResult EditEvent(Event Xevent, string VenueName)
        {
            if (ModelState.IsValid)
            {

                Venue venue = db.Venues.FirstOrDefault(a => a.Venue_Name == VenueName);
                if (venue != null)
                {
                    //attach the artist
                    Xevent.Event_VenueId = venue.Venue_Id;
                }
                else
                {
                    //create a new piece

                    // remove any unnecessary spaces
                    VenueName.Replace("  ", " ").Trim();

                    Venue newVenue = new Venue();
                    newVenue.Venue_Name = VenueName;
                    db.Venues.Add(newVenue);

                    Xevent.Event_VenueId = newVenue.Venue_Id;
                }

                db.Entry(Xevent).State = EntityState.Modified;
                db.SaveChanges();

                ViewBag.Venue = db.Venues.FirstOrDefault(v => v.Venue_Id == Xevent.Event_VenueId);

                // data for the genre
                ViewBag.Genre = db.Genres.FirstOrDefault(g => g.Genre_Id == Xevent.Event_GenreId);

                return PartialView("DetailsEvent", Xevent);
            }
            else
            {
                return Content("Please review your form");
            }
        }
        public ActionResult CreateEvent(Event eventX, string Event_VenueName)
        {
            if (ModelState.IsValid)
            {

                Venue venue = db.Venues.FirstOrDefault(v => v.Venue_Name.Equals(Event_VenueName));
                if (venue != null)
                {
                    //attach the venue
                    eventX.Event_VenueId = venue.Venue_Id;
                }
                else
                {
                    //create a new venue
                    Venue newVenue = new Venue();

                    // remove any unnecessary spaces
                    Event_VenueName.Replace("  ", " ").Trim();
                    newVenue.Venue_Name = Event_VenueName;

                    db.Venues.Add(newVenue);
                    eventX.Event_VenueId = newVenue.Venue_Id;

                }

                // set the creation details
                eventX.Event_CreatedBy = (int)Session["UserID"];
                eventX.Event_CreatedDate = DateTime.Now;

                db.Events.Add(eventX);
                db.SaveChanges();

                // data for the performances
                ViewBag.performances = db.Performances
                    .Where(p => p.Performance_EventId == eventX.Event_Id)
                    .OrderBy(p => p.Performance_Order)
                    .Take(PageSize+1);

                // data for the venue
                ViewBag.Venue = db.Venues.FirstOrDefault(v => v.Venue_Id == eventX.Event_VenueId);

                // data for the genre
                ViewBag.Genre = db.Genres.FirstOrDefault(g => g.Genre_Id == eventX.Event_GenreId);

                // data for the MyStatus dropdown
                if (eventX.Event_Date < DateTime.Today)
                {
                    var query = db.EventUserStatus.OrderBy(c => c.EventUserStatus_Id)
                        .Select(c => new
                        {
                            c.EventUserStatus_Id,
                            c.EventUserStatus_Past
                        });

                    ViewBag.MyStatus = new SelectList(query.AsEnumerable(), "EventUserStatus_Id", "EventUserStatus_Past", ViewBag.EventUser_StatusId);
                }
                else
                {
                    var query = db.EventUserStatus.OrderBy(c => c.EventUserStatus_Id)
                        .Select(c => new
                        {
                            c.EventUserStatus_Id,
                            c.EventUserStatus_Future
                        });

                    ViewBag.MyStatus = new SelectList(query.AsEnumerable(), "EventUserStatus_Id", "EventUserStatus_Future", ViewBag.EventUser_StatusId);
                }

                // Can the current user edit this event?
                ViewBag.UserCanEditEvent = true;

                // sort out the paging
                ViewBag.page = 0;
                ViewBag.PageSize = PageSize;

                return View("Details", eventX);
            }
            else
            {
                return Content("Please review your form");
            }
        }
        public ActionResult CopyEvent(Event xEvent, int oldEventId, string VenueName)
        {
            if (ModelState.IsValid)
            {

                // Sort out the venue
                Venue venue = db.Venues.FirstOrDefault(a => a.Venue_Name == VenueName);
                if (venue != null)
                {
                    //attach the artist
                    xEvent.Event_VenueId = venue.Venue_Id;
                }
                else
                {
                    //create a new piece

                    // remove any unnecessary spaces
                    VenueName.Replace("  ", " ").Trim();

                    Venue newVenue = new Venue();
                    newVenue.Venue_Name = VenueName;
                    db.Venues.Add(newVenue);

                    xEvent.Event_VenueId = newVenue.Venue_Id;
                }

                db.Events.Add(xEvent);
                db.Entry(xEvent).State = EntityState.Added;
                db.SaveChanges();

                // copy over all the child objects
                Event oldEvent = db.Events.Single(e => e.Event_Id == oldEventId);

                foreach (PerfV400.Models.Performance performance in oldEvent.Performances)
                {

                    Performance newPerformance = new Performance();
                    newPerformance.Performance_EventId = xEvent.Event_Id;
                    newPerformance.Performance_Order = performance.Performance_Order;
                    newPerformance.Performance_Photo = performance.Performance_Photo;
                    newPerformance.Performance_PhotoFileName = performance.Performance_PhotoFileName;
                    newPerformance.Performance_PhotoMimeType = performance.Performance_PhotoMimeType;
                    newPerformance.Performance_PieceId = performance.Performance_PieceId;
                    newPerformance.Performance_ProductionId = performance.Performance_ProductionId;

                    db.Performances.Add(newPerformance);
                    db.Entry(newPerformance).State = EntityState.Added;
                    db.SaveChanges();

                    foreach (PerfV400.Models.PerformanceArtist performanceArtist in performance.PerformanceArtists)
                    {

                        PerformanceArtist newPerformanceArtist = new PerformanceArtist();
                        newPerformanceArtist.PerformanceArtist_ArtistId = performanceArtist.PerformanceArtist_ArtistId;
                        newPerformanceArtist.PerformanceArtist_Comments = performanceArtist.PerformanceArtist_Comments;
                        newPerformanceArtist.PerformanceArtist_PerformanceId = newPerformance.Performance_Id;
                        newPerformanceArtist.PerformanceArtist_Photo = performanceArtist.PerformanceArtist_Photo;
                        newPerformanceArtist.PerformanceArtist_RoleId = performanceArtist.PerformanceArtist_RoleId;

                        db.PerformanceArtists.Add(newPerformanceArtist);
                        db.Entry(newPerformanceArtist).State = EntityState.Added;

                    }

                }

                db.SaveChanges();

            // Retrieve the data for the view

                // data for the performances
                ViewBag.performances = db.Performances
                    .Where(p => p.Performance_EventId == xEvent.Event_Id)
                    .OrderBy(p => p.Performance_Order)
                    .Take(60)
                    .Include(p => p.Piece.Genre)
                    .Include(p => p.PerformanceArtists.Select(pa => pa.Role))
                    .Include(p => p.PerformanceArtists.Select(pa => pa.Artist))
                    ;

                // data for the venue
                ViewBag.Venue = db.Venues.FirstOrDefault(v => v.Venue_Id == xEvent.Event_VenueId);

                // data for the genre
                ViewBag.Genre = db.Genres.FirstOrDefault(g => g.Genre_Id == xEvent.Event_GenreId);

                // Can the current user edit this event?
                ViewBag.UserCanEditEvent = true;

                // data for the MyStatus dropdown
                if (xEvent.Event_Date < DateTime.Today)
                {
                    var query = db.EventUserStatus.OrderBy(c => c.EventUserStatus_Id)
                        .Select(c => new
                        {
                            c.EventUserStatus_Id,
                            c.EventUserStatus_Past
                        });

                    ViewBag.MyStatus = new SelectList(query.AsEnumerable(), "EventUserStatus_Id", "EventUserStatus_Past", ViewBag.EventUser_StatusId);
                }
                else
                {
                    var query = db.EventUserStatus.OrderBy(c => c.EventUserStatus_Id)
                        .Select(c => new
                        {
                            c.EventUserStatus_Id,
                            c.EventUserStatus_Future
                        });

                    ViewBag.MyStatus = new SelectList(query.AsEnumerable(), "EventUserStatus_Id", "EventUserStatus_Future", ViewBag.EventUser_StatusId);
                }

                // sort out the paging
                ViewBag.page = 0;
                ViewBag.PageSize = PageSize;

                return PartialView("Details", xEvent);

            }
            else
            {
                return Content("Please review your form");
            }
        }
        public ActionResult EditVenue(Venue venue)
        {
            if (ModelState.IsValid)
            {
                db.Venues.Attach(venue);
                db.Entry(venue).State = EntityState.Modified;
                db.SaveChanges();

                return PartialView("DetailsVenue", venue);
            }
            else
            {
                return Content("Please review your form");
            }
        }