Beispiel #1
0
 public ActionResult Create([Bind(Include = "Id,DiveSite,Location,DateTime,Duration,Depth,Description")] Dive dive, int? id, IEnumerable<HttpPostedFileBase> files, float lat, float lng)
 {
     if (ModelState.IsValid)
     {
         Diver diver = db.Divers.Find(id);
         dive.Diver = diver;
         if (files != null)
         {
             foreach(var p in files)
             {
                 Photo photo = new Photo();
                 photo.DiveId = dive.Id;
                 photo.PhotoBytes = new ImageProcessor().ImageToByteArray(p);
                 db.Photos.Add(photo);
             }
         }
         dive.Latitude = lat;
         dive.Longitude = lng;
         db.Dives.Add(dive);
         db.SaveChanges();
         return RedirectToAction("Feed");
     }
     return View(dive);
 }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "Id,DiveSite,Location,DateTime,Duration,Depth,Description")] Dive dive, IEnumerable<HttpPostedFileBase> files)
 {
     if (ModelState.IsValid)
     {
         if (files != null)
         {
             foreach (var p in files)
             {
                 Photo photo = new Photo();
                 photo.DiveId = dive.Id;
                 photo.PhotoBytes = new ImageProcessor().ImageToByteArray(p);
                 db.Photos.Add(photo);
             }
         }
         db.Entry(dive).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Feed");
     }
     return View(dive);
 }