示例#1
0
        public ActionResult CreatePiece(Piece piece)
        {
            if (ModelState.IsValid)
            {
                db.Pieces.Add(piece);
                db.SaveChanges();

                int id = piece.Piece_Id;

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

                // data for the Venue dropdown
                IEnumerable<SelectListItem> Venues = db.Venues
                .Where(v => db.Performances.Where(p => p.Performance_PieceId == id).Select(p => p.Event.Event_VenueId).Contains(v.Venue_Id))
                .OrderBy(g => g.Venue_Name)
                .Select(g => new SelectListItem
                {
                    Value = SqlFunctions.StringConvert((double)g.Venue_Id),
                    Text = g.Venue_Name
                })
                ;
                ViewBag.Venues = Venues;

                // data for the City dropdown
                IEnumerable<SelectListItem> cities = db.Venues
                .Where(v => db.Performances.Where(p => p.Performance_PieceId == id).Select(p => p.Event.Event_VenueId).Contains(v.Venue_Id))
                .OrderBy(v => v.Venue_City)
                .Select(v => new SelectListItem
                {
                    Value = v.Venue_City,
                    Text = v.Venue_City
                })
                .Distinct();
                ViewBag.Cities = cities;

                // data for the Country dropdown
                IEnumerable<SelectListItem> countries = db.CountryRegions
                .Where(c => db.Performances.Where(p => p.Performance_PieceId == id).Select(p => p.Event.Venue.Venue_CountryId).Contains(c.CountryRegion_Id))
                .OrderBy(c => c.CountryRegion_Name)
                .Select(c => new SelectListItem
                {
                    Value = SqlFunctions.StringConvert((double)c.CountryRegion_Id),
                    Text = c.CountryRegion_Name
                });
                ViewBag.Countries = countries;

                // set up the filters
                DateTime datetimefilter_from_Event_Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                ViewData["filter_from_Event_Date"] = DateTime.Now.ToLongDateString();

                // data for the pieceArtists
                ViewBag.pieceArtists = db.PieceArtists
                .Where(p => p.PieceArtist_PieceId == id)
                .Take(PageSize+1);

                // data for the roles
                ViewBag.roles = db.Roles
                .Where(p => p.Role_PieceId == id)
                .Take(PageSize+1);

                // data for the performances
                ViewBag.performances = db.Performances
                .Where(p => p.Performance_PieceId == id)
                .Take(PageSize+1);

                return View("Details", piece);
            }
            else
            {
                return Content("Please review your form");
            }
        }
示例#2
0
        public ActionResult EditPerformance(Performance performance, string PieceName)
        {
            if (ModelState.IsValid)
            {
                Piece piece = db.Pieces.FirstOrDefault(a => a.Piece_Name == PieceName);
                if (piece != null)
                {
                    //attach the artist
                    performance.Performance_PieceId = piece.Piece_Id;
                }
                else
                {
                    //create a new piece

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

                    Piece newPiece = new Piece();
                    newPiece.Piece_Name = PieceName;
                    db.Pieces.Add(newPiece);

                    performance.Performance_PieceId = newPiece.Piece_Id;
                }

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

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

                return PartialView("DetailsPerformance", performance);
            }
            else
            {
                return Content("Please review your form");
            }
        }
示例#3
0
        public ActionResult EditPiece(Piece piece)
        {
            if (ModelState.IsValid)
            {
                db.Entry(piece).State = EntityState.Modified;
                db.SaveChanges();

                ViewBag.Genre = db.Venues.FirstOrDefault(v => v.Venue_Id == piece.Piece_GenreId);

                return PartialView("DetailsPiece", piece);
            }
            else
            {
                return Content("Please review your form");
            }
        }