public ActionResult Create([Bind(Include = "id,logo,facebook,linkedin,twitter,google,instagram,phone,location")] SameDate sameDate, HttpPostedFileBase logo) { if (ModelState.IsValid) { if (logo == null) { Session["uploadError"] = "Your must select your file"; return(RedirectToAction("create")); } if (logo.ContentType != "image/png" && logo.ContentType != "image/jpeg" && logo.ContentType != "image/gif") { Session["uploadError"] = "Your file must be jpg,png or gif"; return(RedirectToAction("create")); } if ((logo.ContentLength / 1024) > 1024) { Session["uploadError"] = "Your file size must be max 1mb"; return(RedirectToAction("create")); } string filename = DateTime.Now.ToString("ddMMyyyyHHmmssffff") + logo.FileName; string path = Path.Combine(Server.MapPath("~/Uploads"), filename); logo.SaveAs(path); sameDate.logo = filename; db.SameDate.Add(sameDate); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sameDate)); }
public ActionResult DeleteConfirmed(int id) { SameDate sameDate = db.SameDate.Find(id); db.SameDate.Remove(sameDate); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Back/SameDates/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SameDate sameDate = db.SameDate.Find(id); if (sameDate == null) { return(HttpNotFound()); } return(View(sameDate)); }
public ActionResult Edit([Bind(Include = "id,logo,facebook,linkedin,twitter,google,instagram,phone,location")] SameDate sameDate, HttpPostedFileBase logo) { if (ModelState.IsValid) { if (logo != null) { if (logo.ContentType != "image/png" && logo.ContentType != "image/jpg" && logo.ContentType != "image/gif" && logo.ContentType != "image/jpeg") { Session["uploadError"] = "your file must be jpg, png, gif, jpeg"; return(RedirectToAction("update", "post_galery", new { id = sameDate.id })); } if ((logo.ContentLength / 1024) > 1024) { Session["uploadError"] = "your file size must be max 1mb"; return(RedirectToAction("update", "post_galery", new { id = sameDate.id })); } string FileDate = DateTime.Now.ToString("ddMMyyyHHmmssffff") + logo.FileName; string path = Path.Combine(Server.MapPath("~/Uploads"), FileDate); //string oldpath = Path.Combine(Server.MapPath("~/Uploads"), OldPhoto); // if (System.IO.File.Exists(oldpath)) // { // System.IO.File.Delete(oldpath); // } logo.SaveAs(path); sameDate.logo = FileDate; } //else //{ // post_galery.photo = OldPhoto; //} db.Entry(sameDate).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sameDate)); }