Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Dinary dinary = db.Dinary.Find(id);

            db.Dinary.Remove(dinary);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "DinaryId,mood,weather,write,UserId,picture,picturetype,FbName")] Dinary dinary, HttpPostedFileBase imgFile)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    /* var extension = Path.GetExtension(imgFile.FileName);
                     * var allowedExtensions = new[] { ".png", ".gif", ".jpg", ".jpeg" };
                     * List<Dinary> results = new List<Dinary>();
                     *
                     * if(imgFile.ContentLength > 1024*1024)
                     * {
                     *   results.Add(new Dinary()
                     *   {
                     *       IsValid = false,
                     *       length = imgFile.ContentLength,
                     *       Message = "圖片尺寸不能超過1024KB",
                     *       picturetype = imgFile.ContentType
                     *   });
                     * }
                     *
                     * else if(!allowedExtensions.Contains(extension))//如果文件的后缀名不包含在规定的后缀数组中
                     *   {
                     *   results.Add(new Dinary()
                     *   {
                     *
                     *       IsValid = false,
                     *       length = imgFile.ContentLength,
                     *       Message = "圖片格式必须是png、gif、jpg或jpeg",
                     *       picturetype = imgFile.ContentType
                     *   });
                     * }
                     *
                     * else { */



                    int    length = imgFile.ContentLength;
                    byte[] buffer = new byte[length];
                    imgFile.InputStream.Read(buffer, 0, length);


                    dinary.picture     = ImageHelper.ReImage(buffer, 300, 300);
                    dinary.picturetype = imgFile.ContentType;

                    // }
                }


                db.Dinary.Add(dinary);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.User, "UserId", "Name", dinary.UserId);
            return(View(dinary));
        }
Beispiel #3
0
        // GET: Dinaries/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dinary dinary = db.Dinary.Find(id);

            if (dinary == null)
            {
                return(HttpNotFound());
            }
            return(View(dinary));
        }
Beispiel #4
0
        // GET: Dinaries/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dinary dinary = db.Dinary.Find(id);

            if (dinary == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.User, "UserId", "Name", dinary.UserId);
            return(View(dinary));
        }
Beispiel #5
0
        public ActionResult Edit([Bind(Include = "DinaryId,mood,weather,write,UserId,picturetype,FbName,picture")] Dinary dinary, HttpPostedFileBase imgFile)
        {
            if (ModelState.IsValid)
            {
                if (imgFile != null)
                {
                    int    length = imgFile.ContentLength;
                    byte[] buffer = new byte[length];
                    imgFile.InputStream.Read(buffer, 0, length);


                    dinary.picture     = ImageHelper.ReImage(buffer, 300, 300);
                    dinary.picturetype = imgFile.ContentType;
                }
                db.Entry(dinary).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.UserId = new SelectList(db.User, "UserId", "Name", dinary.UserId);
            return(View(dinary));
        }