Пример #1
0
        public ActionResult Create(FormCollection collection, List<HttpPostedFileBase> mainImage, List<HttpPostedFileBase> previewImage)
        {
            try
            {
                using (var context = new SiteContext())
                {
                    int imagesCount = previewImage.Count(file => file != null);


                    for (int i = 0; i < imagesCount; i++)
                    {
                        SecretImage si = new SecretImage();

                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", previewImage[i].FileName);
                        string filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        previewImage[i].SaveAs(filePath);
                        si.PreviewImageSource = fileName;

                        fileName = IOHelper.GetUniqueFileName("~/Content/Images", mainImage[i].FileName);
                        filePath = Server.MapPath("~/Content/Images");
                        filePath = Path.Combine(filePath, fileName);
                        mainImage[i].SaveAs(filePath);
                        si.ImageSource = fileName;

                        context.AddToSecretImage(si);
                        context.SaveChanges();
                    }
                    return RedirectToAction("SiteContent", "Home", new { id = "secretlink", area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
Пример #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SecretImage EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSecretImage(SecretImage secretImage)
 {
     base.AddObject("SecretImage", secretImage);
 }
Пример #3
0
 /// <summary>
 /// Create a new SecretImage object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="previewImageSource">Initial value of the PreviewImageSource property.</param>
 public static SecretImage CreateSecretImage(global::System.Int32 id, global::System.String imageSource, global::System.String previewImageSource)
 {
     SecretImage secretImage = new SecretImage();
     secretImage.Id = id;
     secretImage.ImageSource = imageSource;
     secretImage.PreviewImageSource = previewImageSource;
     return secretImage;
 }