示例#1
0
        public ActionResult Upload(Photo photo, HttpPostedFileBase file)
        {
            if (ModelState.IsValid) {
                if (file != null && file.ContentLength > 0) {
                    photo.Href = SaveFile(file);
                    photo.ContentLength = file.ContentLength;
                    photo.ContentType = file.ContentType;
                    photo.User = this.User.Identity.Name;
                    photo.DateAdded = DateTime.UtcNow;
                    photo.FileName = file.FileName;
                    _repository.Add(photo);

                }
            }
            else {
                return View(photo);
            }
            return RedirectToAction("Index");
        }
示例#2
0
 public Photo Update(Photo p)
 {
     _db.Entry(p).State = System.Data.EntityState.Modified;
     _db.SaveChanges();
     return p;
 }
示例#3
0
 public Photo Add(Photo p)
 {
     this._db.Photos.Add(p);
     this._db.SaveChanges();
     return p;
 }