Exemplo n.º 1
0
 public ActionResult ChangePicture(HttpPostedFileBase file, string id)
 {
     if (file == null)
     {
         return(new JsonResult {
             Data = new { type = "error", result = "تصویری را انتخاب نکرده اید" }
         });
     }
     try
     {
         var user = UserManager.Users.FirstOrDefault(m => m.Id == id);
         FileUploader.DeleteFile("/uploadFiles/Users/" + user.ImageFile);
         user.ImageFile = FileUploader.SaveFile(file, "/uploadFiles/Users/", user.UserName);
         if (user.ImageFile == null)
         {
             return(new JsonResult {
                 Data = new { type = "error", result = "به دلیل خطایی نا مشخص فایل تغییر نکرد" }
             });
         }
         UserManager.Update(user);
         return(new JsonResult {
             Data = new { type = "success", result = "تصویر با موفقیت تغییر کرد." }
         });
     }
     catch (Exception e)
     {
         return(new JsonResult {
             Data = new { type = "error", result = e.Message }
         });
     }
 }
 public JsonResult Delete(string id)
 {
     try
     {
         // TODO: Add delete logic here
         Product product = db.Products.Find(id);
         if (product.ImageFile != null)
         {
             FileUploader.DeleteFile("/uploadFiles/Products/" + product.ImageFile);
         }
         if (product.ProductImages.Count > 0)
         {
             foreach (var item in product.ProductImages)
             {
                 FileUploader.DeleteFile("/uploadFiles/ProductImages/" + item.Name);
             }
         }
         db.ProductImages.RemoveRange(product.ProductImages);
         db.Products.Remove(product);
         db.SaveChanges();
         return(new JsonResult {
             Data = new { type = "success", title = "صحیح انجام شد!", message = "آیتم مورد نظر حذف شد.", id }
         });
     }
     catch (Exception e)
     {
         return(new JsonResult {
             Data = new { type = "error", title = "خطا!", message = e.Message, id }
         });
     }
 }
        public ActionResult ChangePicture(HttpPostedFileBase file, string id)
        {
            if (file == null)
            {
                return(new JsonResult {
                    Data = new { type = "error", result = "تصویری را انتخاب نکرده اید" }
                });
            }
            try
            {
                var img = db.SliderImages.Find(id);
                FileUploader.DeleteFile("/uploadFiles/SliderImages/" + img.Name);
                img.Name = FileUploader.SaveFile(file, "/uploadFiles/SliderImages/", img.Title);
                if (img.Name == null)
                {
                    return(new JsonResult {
                        Data = new { type = "error", result = "به دلیل خطایی نا مشخص فایل تغییر نکرد" }
                    });
                }
                db.Entry(img).State = EntityState.Modified;
                db.SaveChanges();

                return(new JsonResult {
                    Data = new { type = "success", result = "تصویر با موفقیت تغییر کرد." }
                });
            }
            catch (Exception e)
            {
                return(new JsonResult {
                    Data = new { type = "error", result = e.Message }
                });
            }
        }
Exemplo n.º 4
0
 public JsonResult Delete(string id)
 {
     try
     {
         // TODO: Add delete logic here
         ProductCategory category = db.ProductCategories.Find(id);
         FileUploader.DeleteFile("/uploadFiles/ProductCategories/" + category.ImageFile);
         db.ProductCategories.Remove(category);
         db.SaveChanges();
         return(new JsonResult {
             Data = new { type = "success", title = "صحیح انجام شد!", message = "آیتم مورد نظر حذف شد.", id }
         });
     }
     catch (Exception e)
     {
         return(new JsonResult {
             Data = new { type = "error", title = "خطا!", message = e.Message, id }
         });
     }
 }
 public ActionResult Delete_Confirms(int id)
 {
     if (Session["user"] != null)
     {
         var Citem = db.Classifieds_Items.Find(id);
         foreach (var item in Citem.Classifieds_Item_Image.ToList())
         {
             FileUploader.DeleteFile(this.ControllerContext, item.Classifieds_Item_Image_Name);
             db.Classifieds_Item_Image.Remove(item);
         }
         db.Classifieds_Items.Remove(Citem);
         db.SaveChanges();
         return(RedirectToAction("ClassifiedsItemData"));
     }
     else
     {
         Session.Clear();
         return(RedirectToAction("Login", "Admin"));
     }
 }
 public JsonResult Delete(string id)
 {
     try
     {
         // TODO: Add delete logic here
         var img = db.SliderImages.Find(id);
         FileUploader.DeleteFile("/uploadFiles/SliderImages/" + img.Name);
         db.SliderImages.Remove(img);
         db.SaveChanges();
         return(new JsonResult {
             Data = new { type = "success", title = "صحیح انجام شد!", message = "آیتم مورد نظر حذف شد.", id }
         });
     }
     catch (Exception e)
     {
         return(new JsonResult {
             Data = new { type = "error", title = "خطا!", message = e.Message, id }
         });
     }
 }
Exemplo n.º 7
0
 public JsonResult Delete(string id)
 {
     try
     {
         // TODO: Add delete logic here
         var user = UserManager.Users.FirstOrDefault(m => m.Id == id);
         if (user.ImageFile != null)
         {
             FileUploader.DeleteFile("/uploadFiles/Users/" + user.ImageFile);
         }
         UserManager.Delete(user);
         return(new JsonResult {
             Data = new { type = "success", title = "صحیح انجام شد!", message = "آیتم مورد نظر حذف شد.", id }
         });
     }
     catch (Exception e)
     {
         return(new JsonResult {
             Data = new { type = "error", title = "خطا!", message = e.Message, id }
         });
     }
 }
        public ActionResult Edit(HttpPostedFileBase file, [Bind(Include = "Id,URLPage,SliderId,Title")] SliderImage model)
        {
            if (file == null)
            {
                ViewData["Slider"] = db.Sliders.Find(model.SliderId);
                ModelState.AddModelError("", "تصویر انتخاب نگردیده است");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var imge = db.SliderImages.Find(model.Id);
                    FileUploader.DeleteFile("/uploadFiles/SliderImages/" + imge.Name);
                    var name = FileUploader.SaveFile(file, "/uploadFiles/ProductImages/", model.Title, true);
                    if (name == null)
                    {
                        throw new ArgumentException("تصویر به دلیل نا معلومی ذخیره نشد");
                    }
                    imge.Title           = model.Title;
                    imge.URLPage         = model.URLPage;
                    imge.SliderId        = model.SliderId;
                    imge.Name            = name;
                    imge.UpdateTime      = DateTime.Now;
                    db.Entry(imge).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = model.SliderId }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                    ViewData["Slider"] = db.Sliders.Find(model.SliderId);
                    return(View(model));
                }
            }
            ViewData["Slider"] = db.Sliders.Find(model.SliderId);
            return(View(model));
        }