Exemple #1
0
        public ActionResult uploadImage(HttpPostedFileBase imgOne)
        {
            var userID   = Convert.ToInt32(Session["userID"]);
            var userName = Session["userName"].ToString();
            var sign     = db.Signs.FirstOrDefault(o => o.ID == userID);
            //因為Linq不支援Last語法,所以需要先轉成物件(使用toList())之後,才能使用Last()
            var nextText = (from o in db.Texts
                            select o.txtID).ToList().Last();//因為還沒新增文章,所以找到文章列表的最後一份文章ID,然後加一

            AddEditTextModel mix = new AddEditTextModel()
            {
                sign = sign
            };

            if (imgOne != null && imgOne.ContentLength > 0)
            {
                var fileName = userName + "-" + nextText + ".png";//Ex:Milktea123-11.png
                var path     = Path.Combine(Server.MapPath("~/Pictures"), fileName);
                imgOne.SaveAs(path);
                Picture picture = new Picture();
                picture.picUrl         = "/Pictures/" + fileName;
                picture.txtID          = nextText;
                picture.location       = 0;
                picture.picDescription = "";
                db.Pictures.Add(picture);
                db.SaveChanges();
            }

            return(Redirect("/signs/BrowseText"));
        }
Exemple #2
0
        // GET: add/addTest
        public ActionResult addTest()
        {
            var userID           = Convert.ToInt32(Session["userID"]);
            var sign             = db.Signs.FirstOrDefault(o => o.ID == userID);
            AddEditTextModel mix = new AddEditTextModel()
            {
                sign = sign
            };

            return(View(mix));
        }