public JsonResult DeleteOption(int?id)
        {
            object result;

            try
            {
                var option  = db.Product_Options.Find(id);
                var product = option.Product;
                foreach (var file in option.Files)
                {
                    option.Files.Remove(file);
                    db.Files.Remove(file);
                    Uploader.DeleteFile(file, this);
                }

                if (option.PreviewImage != null)
                {
                    db.Files.Remove(option.PreviewImage);
                    Uploader.DeleteFile(option.PreviewImage, this);
                }

                product.Product_Options.Remove(option);
                db.Product_Options.Remove(option);
                result = db.SaveChanges() > 0 ? "Success" : "Fail";
            }
            catch (Exception ex)
            {
                result = ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult Delete(int id)
        {
            var    model = db.Product_Variants.Find(id);
            object result;

            if (model != null)
            {
                try
                {
                    if (model.PreviewImage != null)
                    {
                        Uploader.DeleteFile(model.PreviewImage, this);
                        db.Files.Remove(model.PreviewImage);
                    }

                    db.Product_Variants.Remove(model);
                    result = db.SaveChanges() > 0 ? "Success" : "Fail";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            else
            {
                result = HttpStatusCode.NotFound;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult Delete(int slideId)
        {
            var    slide  = db.Slides.Find(slideId);
            object result = -1;

            if (slide != null)
            {
                if (slide.ImageFile != null)
                {
                    Uploader.DeleteFile(slide.ImageFile, this);
                    db.Files.Remove(slide.ImageFile);
                }
                db.Slides.Remove(slide);
                result = db.SaveChanges();
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }