Beispiel #1
0
        public ActionResult UpdateGaleryImage(GalleryMaster item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    HttpPostedFileBase file = Request.Files[0];
                    if (file.ContentLength > 0)
                    {
                        var path = Server.MapPath("~/Images/Gallery/Master/" + item.Id + ".jpg");
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        file.SaveAs(path);
                    }

                    var obj = db.GalleryMaster.Find(item.Id);
                    db.Entry(obj).CurrentValues.SetValues(item);
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult DeleteGalery(GalleryMaster item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    db.GalleryMaster.Remove(db.GalleryMaster.Find(item.Id));
                    var pathMaster = Server.MapPath("~/Images/Gallery/Master/" + item.Id + ".jpg");
                    if (System.IO.File.Exists(pathMaster))
                    {
                        System.IO.File.Delete(pathMaster);
                    }
                    foreach (var i in db.GalleryDetails.Where(x => x.GalleryMasterId == item.Id))
                    {
                        var pathDetails = Server.MapPath("~/Images/Gallery/Details/" + i.Id + ".jpg");
                        if (System.IO.File.Exists(pathDetails))
                        {
                            System.IO.File.Delete(pathDetails);
                        }
                        db.GalleryDetails.Remove(db.GalleryDetails.Find(i.Id));
                    }
                    db.SaveChanges();
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult SaveGaleryImage(GalleryMaster item)
        {
            bool res = true;

            try
            {
                using (AbcUEMDbEntities db = new AbcUEMDbEntities())
                {
                    if (!Directory.Exists(Server.MapPath("~/Images/Gallery/Master")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Images/Gallery/Master"));
                    }

                    HttpPostedFileBase file = Request.Files[0];

                    var i = db.GalleryMaster.Add(item);
                    db.SaveChanges();
                    string extension = Path.GetExtension(file.FileName);

                    var path = Path.Combine(Server.MapPath("~/Images/Gallery/Master/"), i.Id + ".jpg");

                    file.SaveAs(path);
                }
            }
            catch
            {
                res = false;
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }