public ActionResult Create(SiteBackground model)
        {
            using (var context = new SiteContainer())
            {
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];
                    if (file == null) continue;

                    var pi = new SiteBackground();
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");
                    filePath = Path.Combine(filePath, fileName);
                    file.SaveAs(filePath);
                    pi.ImageSource = fileName;
                    context.AddToSiteBackground(pi);
                    context.SaveChanges();
                }
                return RedirectToAction("Index");
            }
        }
示例#2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SiteBackground EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSiteBackground(SiteBackground siteBackground)
 {
     base.AddObject("SiteBackground", siteBackground);
 }
示例#3
0
 /// <summary>
 /// Create a new SiteBackground object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 public static SiteBackground CreateSiteBackground(global::System.Int32 id, global::System.String imageSource)
 {
     SiteBackground siteBackground = new SiteBackground();
     siteBackground.Id = id;
     siteBackground.ImageSource = imageSource;
     return siteBackground;
 }