public ActionResult Create([Bind(Include = "RowID,Title,Description")] GalleryVM mod) { if (ModelState.IsValid) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetExtension(file.FileName); tblGallery tbl = new tblGallery { Description = mod.Description, Title = mod.Title, Status = true, Transdate = DateTime.Now.AddHours(12), UserID = bl.GetUserID(System.Web.HttpContext.Current), ImagePath = fileName }; db.tblGalleries.Add(tbl); db.SaveChanges(); var path = Path.Combine(Server.MapPath("~/Images/"), "gal" + tbl.RowID + fileName); file.SaveAs(path); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "No Image Found"); } } return(View(mod)); }
public async Task <ActionResult> DeleteGallery(int GalleryID) { if (Session["user"] != null) { List <tblPhoto> tblPhotos = db.tblPhotos.Where(gallery => gallery.GalleryID.Equals(GalleryID)).ToList(); foreach (var file in tblPhotos) { string fullPath = Request.MapPath(fileLocation + file.Url); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); tblPhoto tblPhoto = db.tblPhotos.Find(file.PhotoID); db.tblPhotos.Remove(tblPhoto); } } tblGallery tblGallery = await db.tblGalleries.FindAsync(GalleryID); db.tblGalleries.Remove(tblGallery); await db.SaveChangesAsync(); return(RedirectToAction("Portfolio", "Home")); } else { return(RedirectToAction("Portfolio", "Home")); } }
public ActionResult DeletePost(int id) { tblGallery tb = db.tblGalleries.Where(g => g.GalleryId == id).FirstOrDefault(); db.tblGalleries.Remove(tb); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ChangeImageUnSelected(int id) { tblGallery objGallery = new tblGallery(); objGallery = db.tblGalleries.SingleOrDefault(g => g.GalleryID == id); objGallery.IsSelected = false; db.Entry(objGallery).State = EntityState.Modified; db.SaveChanges(); }
public int Insert(Models.Gallery gallery) { tblGallery newGallery = new tblGallery { GalleryName = gallery.GalleryName, GalleryDescription = gallery.GalleryDescription, UserId = gallery.UserId, DateCreated = gallery.DateCreated }; db.Galleries.Add(newGallery); db.SaveChanges(); return(newGallery.Id); }
public IHttpActionResult GettblGallery(int id) { tblGallery tblGallery = db.tblGalleries.Find(id); if (tblGallery == null) { return(NotFound()); } return(Ok(tblGallery)); }
public void DeleteImageByID(int id) { tblGallery tblGallery = db.tblGalleries.Find(id); db.tblGalleries.Remove(tblGallery); string path = Server.MapPath("~/GalleryImages/" + tblGallery.Image); FileInfo delfile = new FileInfo(path); delfile.Delete(); db.SaveChanges(); }
public ActionResult Edit(int id) { GalleryViewModel gvm = new GalleryViewModel(); tblGallery tb = db.tblGalleries.Where(g => g.GalleryId == id).FirstOrDefault(); gvm.GalleryId = tb.GalleryId; gvm.Title = tb.Title; gvm.Description = tb.Description; gvm.Photo = tb.Photo; return(View(gvm)); }
public String POST() { int counter = 0; //collection files System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; string url = HttpContext.Current.Request.Url.AbsoluteUri; tblGallery gal = new tblGallery(); String Status = ""; for (int i = 0; i < files.Count; i++) { //get the posted file System.Web.HttpPostedFile file = files[i]; string fileName = new FileInfo(file.FileName).Name; //String Id = url.Split('=')[1]; if (file.ContentLength > 0) { Guid id = Guid.NewGuid(); string modifiedFileName = id.ToString() + "_" + fileName; byte[] imageb = new byte[file.ContentLength]; file.InputStream.Read(imageb, 0, file.ContentLength); gal.Images = imageb; //gal.ID = new Random().Next(); db.tblGalleries.Add(gal); db.SaveChanges(); counter++; } } if (counter > 0) { return(Status); } return("Upload Failed"); }
public bool SaveGallery(GalleryViewModel objGallery) { bool status = false; tblGallery tblgallery = new tblGallery(); Mapper.Map(objGallery, tblgallery); tblgallery.IsActive = true; tblgallery.CreatedDate = DateTime.Now; tblgallery.ModifiedDate = DateTime.Now; tblgallery.CreatedBy = "101"; tblgallery.ModifiedBy = "101"; _Context.tblGalleries.Add(tblgallery); _Context.Configuration.ValidateOnSaveEnabled = true; _Context.SaveChanges(); status = true; return(status); }
public async Task <ActionResult> editGalleryDetails(int?GalleryID) { if (Session["user"] != null) { if (GalleryID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblGallery tblGallery = await db.tblGalleries.FindAsync(GalleryID); if (tblGallery == null) { return(HttpNotFound()); } return(View(tblGallery)); } else { return(RedirectToAction("Portfolio", "Home")); } }
public ActionResult DeleteImage(long id) { if (Session["StudioID"] == null && Session["StudioName"] == null && Session["StudioPhoneNo"] == null) { return(RedirectToAction("Login", "Login")); } try { tblGallery tblGallery = db.tblGalleries.Find(id); db.tblGalleries.Remove(tblGallery); db.SaveChanges(); string path = Server.MapPath("~/Gallery/" + tblGallery.Image); FileInfo delfile = new FileInfo(path); delfile.Delete(); return(Json(new { success = true, message = "Image is deleted." }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = "Image is not deleted." }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit([Bind(Include = "RowID,Title,Description,Status")] GalleryVM mod) { if (ModelState.IsValid) { tblGallery tbl = db.tblGalleries.Find(mod.RowID); tbl.Description = mod.Description; tbl.Title = mod.Title; tbl.Status = true; var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetExtension(file.FileName); tbl.ImagePath = fileName; var path = Path.Combine(Server.MapPath("~/Images/"), "gal" + tbl.RowID + fileName); file.SaveAs(path); } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mod)); }
public IHttpActionResult upload(tblGallery tblg) { int countUpload = 0; string sPath = System.Web.Hosting.HostingEnvironment.MapPath("/Galleries/"); System.Web.HttpFileCollection file = System.Web.HttpContext.Current.Request.Files; for (int g = 0; g < file.Count; g++) { System.Web.HttpPostedFile files = file[g]; string Filename = new FileInfo(files.FileName).Name; if (files.ContentLength > 0) { Guid id = Guid.NewGuid(); string modifiedFilename = id.ToString() + " " + Filename; if (!File.Exists(sPath + Path.GetFileName(modifiedFilename))) { files.SaveAs(sPath + Path.GetFileName(modifiedFilename)); countUpload++; //tblg.Image_id = new Random().Next(); db.tblGalleries.Add(new tblGallery() { ImageUrl = id, FileName = "/Galleries/" + modifiedFilename, Title = Filename }); } } } if (countUpload > 0) { db.SaveChanges(); return(Ok("Uploaded Successfully")); } return(InternalServerError()); }
// GET: Galleries/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblGallery tblGallery = db.tblGalleries.Find(id); if (tblGallery == null) { return(HttpNotFound()); } GalleryVM mod = new GalleryVM { Description = tblGallery.Description, Title = tblGallery.Title, ImagePath = tblGallery.ImagePath, RowID = tblGallery.RowID, Status = tblGallery.Status }; return(View(mod)); }
public ActionResult Add(GalleryViewModel model) { if (ModelState.IsValid) { tblGallery tb = new tblGallery(); tb.Title = model.Title; tb.Description = model.Description; HttpPostedFileBase fup = Request.Files["Photo"]; if (fup != null) { tb.Photo = fup.FileName; fup.SaveAs(Server.MapPath("~/Gallery/" + fup.FileName)); } db.tblGalleries.Add(tb); db.SaveChanges(); ViewBag.Message = "Photo Saved"; } return(View()); }
public ActionResult Edit(GalleryViewModel model) { if (ModelState.IsValid) { tblGallery tb = db.tblGalleries.Where(g => g.GalleryId == model.GalleryId).FirstOrDefault(); tb.GalleryId = model.GalleryId; tb.Title = model.Title; tb.Description = model.Description; HttpPostedFileBase fup = Request.Files["Photo"]; if (fup != null && fup.FileName != "") { tb.Photo = fup.FileName; fup.SaveAs(Server.MapPath("~/Gallery/" + fup.FileName)); } else { tb.Photo = model.Photo; } db.SaveChanges(); ViewBag.Message = "Gallery Updated"; } return(View(model)); }
public ActionResult InsertImage() { if (Session["UserID"] == null && Session["UserName"] == null) { return(RedirectToAction("Login", "Login")); } try { if (ModelState.IsValid) { if (Request.Files.Count > 0) { int fileSize = 0; string fileName = string.Empty; string mimeType = string.Empty; System.IO.Stream fileContent; for (int i = 0; i < Request.Files.Count; i++) { tblGallery NewGallery = new tblGallery(); int CustomerID = Convert.ToInt32(Request.Form["CustomerID"]); int CategoryID = Convert.ToInt32(Request.Form["CategoryID"]); bool ApplyWatermark = Request.Form["chkApplyWaterMark"] == "true" ? true : false; NewGallery.CustomerID = CustomerID; NewGallery.CategoryID = CategoryID; HttpPostedFileBase file = Request.Files[i]; fileSize = file.ContentLength; fileName = file.FileName; mimeType = file.ContentType; fileContent = file.InputStream; if (mimeType.ToLower() != "image/jpeg" && mimeType.ToLower() != "image/jpg" && mimeType.ToLower() != "image/png") { return(Json(new { Formatwarning = true, message = "Profile pic format must be JPEG or JPG or PNG." }, JsonRequestBehavior.AllowGet)); } //WebImage img = new WebImage(file.InputStream); #region Save And compress file //To save file, use SaveAs method file.SaveAs(Server.MapPath("~/GalleryImages/") + fileName); if (ApplyWatermark) { if (!ImageProcessing.InsertImages(Server.MapPath("~/GalleryImages/") + fileName, true)) { return(Json(new { success = false, message = "Error occur while uploading image." }, JsonRequestBehavior.AllowGet)); } } else { if (!ImageProcessing.InsertImages(Server.MapPath("~/GalleryImages/") + fileName)) { return(Json(new { success = false, message = "Error occur while uploading image." }, JsonRequestBehavior.AllowGet)); } } #endregion NewGallery.Image = fileName; NewGallery.CreatedDate = DateTime.Now; NewGallery.IsSelected = false; db.tblGalleries.Add(NewGallery); db.SaveChanges(); } } return(Json(new { success = true, message = "Record inserted successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Record not inserted" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { success = false, message = "Error!" + ex.Message }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> SaveGallery(int?GalleryID, string GalleryName, string GalleryImg, [Bind(Include = "GalleryID, GalleryName,GalleryImg, GalleryDiscription")] tblGallery tblGallery) { if (Session["user"] != null) { GalleryImg = null; if (ModelState.IsValid) { bool saveData = db.tblGalleries.Any(record => record.GalleryID == GalleryID); if (saveData) { db.Entry(tblGallery).State = EntityState.Modified; } else { db.tblGalleries.Add(tblGallery); } await db.SaveChangesAsync(); return(RedirectToAction("Portfolio", "Home")); } return(View(tblGallery)); } else { RedirectToAction("Portfolio", "Home"); } return(View()); }