public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
        {
            if (ModelState.IsValid)
            {
                // process album cover upload if any
                if (Request != null)
                {
                    if (Request.Files.Count > 0)
                    {
                        var file = Request.Files[0];

                        if (file.FileName != "" && file.ContentLength > 0)
                        {
                            string path = Server.MapPath("/Content/Images/") + file.FileName;
                            file.SaveAs(path);

                            album.AlbumArtUrl = "/Content/Images/" + file.FileName;
                        }
                    }
                }

                // scaffold code for inserting
                //db.Albums.Add(album);
                //db.SaveChanges();

                // new repository code for inserting
                db.Save(album);

                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
            ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
            return(View("Create", album));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
        {
            if (ModelState.IsValid)
            {
                if (album == null)
                {
                    return(View("Error"));
                }
                //bool redirect = true;

                //if (album.AlbumId > 0)
                //{
                //    redirect = false;
                //}
                smRepo.Save(album);
                //db.SaveChanges();

                //if (redirect)
                //{
                return(RedirectToAction("Index"));
                //}
                //else
                //{
                //return View(album);
                //}
            }

            ViewBag.ArtistId = new SelectList(smRepo.Artists, "ArtistId", "Name", album.ArtistId);
            ViewBag.GenreId  = new SelectList(smRepo.Genres, "GenreId", "Name", album.GenreId);
            return(View("Create", album));
        }
        public ActionResult Create([Bind(Include = "PartyId,Message_,Party_Type_,Address_,LocationID")] Party party)
        {
            if (ModelState.IsValid)
            {
                db.Save(party);
                return(RedirectToAction("Index"));
            }

            ViewBag.LocationID = new SelectList(db.Plocation, "LocationID", "City", party.LocationID);
            return(View("Create", party));
        }