コード例 #1
0
        public ActionResult Create(Artist artist, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                int i = 1;
                foreach (var file in files)
                {
                    // Verify that the user selected a file
                    if (file != null && file.ContentLength > 0)
                    {
                        // extract only the fielname
                        var fileName = Path.GetFileName(file.FileName);
                        // store the file inside ~/App_Data/uploads folder
                        string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName;
                        var    path        = Path.Combine(Server.MapPath("~/Content/uploads"), "artist_" + newFileName);
                        file.SaveAs(path);
                        if (i == 1)
                        {
                            artist.BioImage = "/Content/uploads/artist_" + newFileName;
                        }
                        else
                        {
                            artist.HomePageImage = "/Content/uploads/artist_" + newFileName;
                        }
                    }
                    i++;
                }
                artist.CreatedDate = DateTime.Now;
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
コード例 #2
0
        public ActionResult Create(MenuItem menuitem)
        {
            if (ModelState.IsValid)
            {
                db.MenuItems.Add(menuitem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(menuitem));
        }
コード例 #3
0
        public ActionResult Create(SiteText sitetext)
        {
            if (ModelState.IsValid)
            {
                db.SiteText.Add(sitetext);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sitetext));
        }
コード例 #4
0
        public ActionResult Create(EnterPage page, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                // Verify that the user selected a file
                if (file != null && file.ContentLength > 0)
                {
                    // extract only the fielname
                    var fileName = Path.GetFileName(file.FileName);
                    // store the file inside ~/App_Data/uploads folder
                    string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName;
                    var    path        = Path.Combine(Server.MapPath("~/Content/uploads"), newFileName);
                    file.SaveAs(path);
                    page.Image = "/Content/uploads/" + newFileName;
                }

                db.EnterPage.Add(page);
                db.SaveChanges();
                return(RedirectToAction("Index", "Admin"));
            }

            return(View(page));
        }
コード例 #5
0
ファイル: ImagesController.cs プロジェクト: urbs44/WhiteGloss
        public ActionResult Create(Image image, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                int i = 1;
                foreach (var file in files)
                {
                    // Verify that the user selected a file
                    if (file != null && file.ContentLength > 0)
                    {
                        // extract only the fielname
                        var fileName = Path.GetFileName(file.FileName);
                        // store the file inside ~/App_Data/uploads folder
                        string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName;
                        var    path        = Path.Combine(Server.MapPath("~/Content/uploads"), newFileName);
                        file.SaveAs(path);
                        if (i == 1)
                        {
                            image.Thumb = "/Content/uploads/" + newFileName;
                        }
                        else
                        {
                            image.Normal = "/Content/uploads/" + newFileName;
                        }
                    }
                    i++;
                }

                image.CreatedDate = DateTime.Now;
                db.Images.Add(image);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", image.ArtistId);
            return(View(image));
        }