Beispiel #1
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new ContentStorage())
            {
                if (fileUpload != null)
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Banners", fileUpload.FileName);
                    string filePath = Server.MapPath("~/Content/Banners");
                    filePath = Path.Combine(filePath, fileName);
                    fileUpload.SaveAs(filePath);

                    var banner = new Banner();
                    TryUpdateModel(banner, new[] { "Price", "Title", "Title2", "ContentName" });
                    banner.BannerType = Convert.ToInt32(form["BannerType"]);
                    banner.ImageSource = fileName;
                    context.AddToBanner(banner);
                    context.SaveChanges();
                }

            }
            return RedirectToAction("Index", "Banner", new { Area = "Admin" });
        }