public ActionResult Create([Bind(Include = "ID,GlideNo,FirstSeen,LastSeen,DaysLast,DisasterType,Province,Borough,Village,Neighborhood,BeldeMevki,ReasonofDisaster,Latitude,Longitude,ReasonDetails,EffectedAreas,Source,Status")] Afet afet, HttpPostedFileBase[] upload) { if (ModelState.IsValid) { afet.Files = new List <File>(); foreach (HttpPostedFileBase file in upload) { if (file != null && file.ContentLength > 0) { var Uploadedfile = new File { FileName = System.IO.Path.GetFileName(file.FileName), FileType = FileType.Image, ContentType = file.ContentType }; using (var reader = new System.IO.BinaryReader(file.InputStream)) { Uploadedfile.Content = reader.ReadBytes(file.ContentLength); } afet.Files.Add(Uploadedfile); } } db.Afets.Add(afet); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(afet)); }
// GET: Afet/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Afet afet = db.Afets.Find(id); if (afet == null) { return(HttpNotFound()); } return(View(afet)); }
// GET: Afet/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bindProvince(); Afet afet = db.Afets.Find(id); if (afet == null) { return(HttpNotFound()); } return(View(afet)); }
public ActionResult Edit(string id, HttpPostedFileBase[] upload) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var afetToUpdate = db.Afets.Find(id); if (TryUpdateModel(afetToUpdate, "", new string[] { "FirstSeen", "LastSeen", "DaysLast", "DisasterType", "Province", "Borough", "Village", "Neigborhood", "BeldeMevki", "ReasonofDisaster", "Latitude", "Longitude", "ReasonDetails", "EffectedAreas", "Source" })) { try { Afet afet = db.Afets.Find(id); afet.Files = new List <File>(); foreach (HttpPostedFileBase file in upload) { if (file != null && file.ContentLength > 0) { var Uploadedfile = new File { FileName = System.IO.Path.GetFileName(file.FileName), FileType = FileType.Image, ContentType = file.ContentType }; using (var reader = new System.IO.BinaryReader(file.InputStream)) { Uploadedfile.Content = reader.ReadBytes(file.ContentLength); } afet.Files.Add(Uploadedfile); } } db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException dex) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } return(View(afetToUpdate)); }
// GET: Afet/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Afet afet = db.Afets.Include(s => s.Files).SingleOrDefault(s => s.ID == id); il pro = db.iller.Find(Int32.Parse(afet.Province)); ViewBag.AfetName = pro.IL_ADI; if (afet == null) { return(HttpNotFound()); } return(View(afet)); }
public ActionResult DeleteConfirmed(string id) { Afet afet = db.Afets.Find(id); var files = from file in db.Files where file.Afet.ID == afet.ID select file; foreach (var f in files) { System.Diagnostics.Debug.WriteLine(" 123 " + f); db.Files.Remove(f); } db.Afets.Remove(afet); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Afet/Create public ActionResult Create() { bindProvince(); //TODO //DATABASE ID'LERİ SORGULA VE BU ID'LERDEN FARKLI BİR ID OLUŞTURUP VIEW'E YOLLA Afet test = new Afet(); string demoID; var result = true; do { demoID = IDGenerator(); result = db.Afets.Any(a => a.ID == demoID); } while (result); test.ID = demoID; test.GlideNo = demoID; return(View(test)); }