コード例 #1
0
 public ActionResult Edit(PhotoEditModel photo)
 {
     if (ModelState.IsValid)
     {
         var originalPhoto = _rep.PhotoById(photo.PhotoID);
         Mapper.Map<PhotoEditModel, Photo>(photo, originalPhoto);
         _rep.AddOrUpdatePhoto(originalPhoto);
         _rep.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(photo);
 }   
コード例 #2
0
        public ActionResult Create(PhotoEditModel photo, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var photo2 = Mapper.Map<Photo>(photo);

                photo2.CreatedDate = DateTime.Now;
                photo2.UserName = User.Identity.Name;

                if (image != null)
                {
                    photo2.ImageMimeType = image.ContentType;
                    photo2.PhotoFile = new byte[image.ContentLength];
                    image.InputStream.Read(photo2.PhotoFile, 0, image.ContentLength);
                }

                _rep.AddOrUpdatePhoto(photo2);
                _rep.SaveChanges();

                return RedirectToAction("Index");
            }

            return View(photo);
        }