Beispiel #1
0
        public ActionResult Create([Bind(Include = "id,title,filePath,created,state,createdByUser_id,album_id")] Images images, HttpPostedFileBase file)
        {
            foreach (string upload in Request.Files)
            {
                file = Request.Files[upload];
                if (file != null)
                {
                    List <Albums> alb = albumHandler.All().ToList();
                    Albums        a   = alb.Where(x => x.id == images.album_id).FirstOrDefault();
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/ImagesUpload") + "/" + a.title);
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/ImagesUpload" + "/" + a.title), fileName);
                    file.SaveAs(path);
                    string tempUrl = a.title + "/" + fileName;
                    images.filePath = tempUrl;
                }
            }

            if (ModelState.IsValid && images.filePath != null)
            {
                images.created = DateTime.Now;
                imageHandler.Add(images);
                return(RedirectToAction("Index"));
            }

            ViewBag.album_id         = new SelectList(albumHandler.All(), "id", "title", images.album_id);
            ViewBag.createdByUser_id = new SelectList(userHandler.All(), "id", "name", images.createdByUser_Id);
            return(View(images));
        }
Beispiel #2
0
 /// <summary>
 /// Add插入一条图像记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(IModel model)
 {
     return(dal.Add(model));
 }