public AddFoto GetPhotoById(string photo) { var query = (from ph in adb.Fotos where ph.Nombre == photo + ".jpg" select ph).Single(); // var det = query.FirstOrDefault(); var model = new AddFoto() { photo = query.Nombre, name = query.Fotografo, airline = query.Aerolinea, airplane = query.Avion, date = query.Fecha, place = query.Lugar, notes = query.Notas }; return model; }
public ActionResult MasInfo(AddFoto af) { bool foto = (from ph in adb.Fotos where ph.Nombre == (string)Session["foto"] select true).SingleOrDefault(); var nombre = (from usu in adb.Usuarios where usu.Alias == (string)Session["usuario"] select usu.Nombre).Single(); if (foto == false) { if (ModelState.IsValid) { Foto nuevo = new Foto(); af.name = (string)nombre; af.photo = (string)Session["foto"]; nuevo.Aerolinea = af.airline; nuevo.Avion = af.airplane; nuevo.Fecha = af.date; nuevo.Fotografo = af.name; nuevo.Lugar = af.place; nuevo.Notas = af.notes; nuevo.Nombre = af.photo; adb.Fotos.InsertOnSubmit(nuevo); adb.SubmitChanges(); return RedirectToAction("Index", "Home"); } else { var err = ModelState.SelectMany(x => x.Value.Errors.Select(y => y.Exception)); return View("MasInfo"); } } else { return RedirectToAction("AñadirFoto"); } }
public ActionResult EditarFoto(AddFoto ph) { try { if (ModelState.IsValid) { Foto photoData = (from p in adb.Fotos where p.Nombre == ph.photo + ".jpg" select p).Single(); photoData.Aerolinea = ph.airline; photoData.Avion = ph.airplane; photoData.Fecha = ph.date; photoData.Lugar = ph.place; photoData.Notas = ph.notes; adb.SubmitChanges(); return RedirectToAction("TusFotos"); } else { var err = ModelState.SelectMany(x => x.Value.Errors.Select(y => y.Exception)); return View("EditarFoto"); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes."); } return View(ph); }