Esempio n. 1
0
 public static void ConvertImageToDataString(Picture pictureToSave, Stream stream)
 {
     ImageConverter IC = new ImageConverter();
     Image image = Image.FromStream(stream);
     image = PictureResizer.ScaleImage(image, 600, 400);
     pictureToSave.PictureData = Convert.ToBase64String(PictureResizer.GetByteArrayFromImage(image));
 }
        public string SaveUploadedFile(Picture picture)
        {
            Session["upload"] = picture.Answer.Module.Name;
            bool isSavedSuccessfully = true;
            string fName = "";
            var path = "";
            try
            {
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    //Save file content goes here
                    fName = file.FileName;
                    if (file != null && file.ContentLength > 0)
                    {
                        string moduleDirectory = (Path.Combine(Server.MapPath("~/Content/Images/PLM/" + Session["upload"].ToString() + "/" )));
                        if (!Directory.Exists(moduleDirectory)) 
                        {
                            Directory.CreateDirectory(moduleDirectory);
                        }
                        var originalDirectory = new DirectoryInfo(string.Format("{0}Content\\Images\\PLM\\", Server.MapPath(@"\")));

                        string pathString = System.IO.Path.Combine(originalDirectory.ToString(), moduleDirectory);

                        var fileName1 = Path.GetFileName(file.FileName);

                        bool isExists = System.IO.Directory.Exists(pathString);

                        if (!isExists)
                            System.IO.Directory.CreateDirectory(pathString);


                        path = string.Format("{0}\\{1}", pathString, file.FileName);


                        file.SaveAs(path);

                    }

                }

            }
            catch (Exception ex)
            {
                isSavedSuccessfully = false;
            }


            if (isSavedSuccessfully)
            {
                return path;
            }
            else
            {
                return "";
            }
        }
Esempio n. 3
0
 // Using to get a base game working
 public void AddPicturesToList(Picture pic)
 {
     Pictures.Add(pic);
 }
Esempio n. 4
0
 public AnsPicIndex(int ans, int pic, Picture picOBJ)
 {
     AnswerIndex = ans;
     PictureIndex = pic;
     PictureOBJ = picOBJ;
 }
Esempio n. 5
0
 public bool AddPicture(Picture picture)
 {
     var idParam = new SqlParameter
     {
         ParameterName = "Location",
         Value = picture.Location
     };
     var idParam1 = new SqlParameter
     {
         ParameterName = "AnswerID",
         Value = picture.AnswerID
     };
     var idParam2 = new SqlParameter
     {
         ParameterName = "Attribution",
         Value = picture.Attribution
     };
     var idParam3 = new SqlParameter
     {
         ParameterName = "PictureData",
         Value = picture.PictureData
     };
     try
     {
         _dc.Database.ExecuteSqlCommand(
             "INSERT INTO Pictures (Location, AnswerID, Attribution, PictureData) VALUES (@Location, @AnswerID, @Attribution, @PictureData)", idParam, idParam1, idParam2, idParam3
             );
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Esempio n. 6
0
 public bool UpdatePicture(Picture picture)
 {
     var idParam = NullChecker(new SqlParameter
     {
         ParameterName = "Location",
         Value = picture.Location
     });
     var idParam1 = new SqlParameter
     {
         ParameterName = "AnswerID",
         Value = picture.AnswerID
     };
     var idParam2 = NullChecker(new SqlParameter
     {
         ParameterName = "Attribution",
         Value = picture.Attribution
     });
     var idParam3 = new SqlParameter
     {
         ParameterName = "PictureData",
         Value = picture.PictureData
     };
     var idParam4 = new SqlParameter
     {
         ParameterName = "PictureID",
         Value = picture.PictureID
     };
     try
     {
         _dc.Database.ExecuteSqlCommand(
             "UPDATE Pictures SET Location = @Location, AnswerID = @AnswerID, Attribution = @Attribution, PictureData = @PictureData Where PictureID = @PictureID", idParam, idParam1, idParam2, idParam3, idParam4
             );
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }
Esempio n. 7
0
 public ActionResult Create(int? id)
 {
     ViewBag.AnswerID = id;
     Picture picture = new Picture();
     int ID = id ?? 0;
     using (Repos repo = new Repos())
     {
         picture.Answer = repo.GetAnswerByID(ID);
     }
     return View(picture);
 }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "Attribution,PictureID")] Picture picture, int? id)
        {
            int ID = id ?? 0;
            pictureToSave = new Picture();
            pictureToSave.AnswerID = ID;
            pictureToSave.Location = "NotYetConstructed";
            if (picture.Attribution == null)
                pictureToSave.Attribution = "";
            else
                pictureToSave.Attribution = picture.Attribution;

            ConvertImageToDataString(pictureToSave, Request.Files[0].InputStream);
            ViewBag.AnswerID = ID;

            if (ModelState.IsValid)
            {
                using (Repos repo = new Repos())
                {
                    if (!repo.AddPicture(pictureToSave))
                    {
                        //ERROR SAVING TO DATABASE
                    }
                }
                return RedirectToAction("edit", new { controller = "Answers", id = pictureToSave.AnswerID });
            }
            ViewBag.AnswerID = new SelectList(db.Answers, "AnswerID", "AnswerString", pictureToSave.AnswerID);
            return View(pictureToSave);
        }