예제 #1
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));
        }