コード例 #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 }
         });
     }
 }
コード例 #2
0
        public Intray()
        {
            Get["/Intray"] = _ => View["Intray/index.cshtml"];

            Get["/Intray/GetFiles"] = _ =>
            {
                List <IntrayItem> files = DMS.Session.GetIntrayFiles();
                return(files);
            };

            Post["/Intray/InsertIntoArchive"] = _ =>
            {
                IntrayItem file = this.Bind <IntrayItem>();
                string     id   = DMS.Session.InsertIntoArchive(file, true);
                return(id);
            };

            Post["/Intray/UploadFile"] = _ =>
            {
                Nancy.HttpFile file = Request.Files.FirstOrDefault();
                string         page = Request.Form["page"];

                var uploader = new FileUploader();
                uploader.SaveFile(file, page);

                return(true);
            };
        }
コード例 #3
0
        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 }
                });
            }
        }
コード例 #4
0
        public ActionResult Create(HttpPostedFileBase file, string productId, string title)

        {
            if (file != null)
            {
                try
                {
                    var name = FileUploader.SaveFile(file, "/uploadFiles/ProductImages/", title, true);

                    db.ProductImages.Add(new ProductImage {
                        Name      = name,
                        ProductId = productId,
                        Title     = title
                    });
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = productId }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                    ViewData["Product"] = db.Products.Find(productId);
                    return(View());
                }
            }

            ModelState.AddModelError("", "باید تصویر انتخاب شود");
            ViewData["Product"] = db.Products.Find(productId);
            return(View());
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public ActionResult Create(HttpPostedFileBase file, [Bind(Include = "URLPage,SliderId,Title")] SliderImage model)

        {
            if (file != null)
            {
                try
                {
                    var name = FileUploader.SaveFile(file, "/uploadFiles/SliderImages/", model.Title, true);
                    if (name == null)
                    {
                        throw new ArgumentException("فایل مورد نظر ذخیره نگردید دوباره امتحان نمایید");
                    }
                    var position = db.SliderImages.Where(m => m.SliderId == model.SliderId).OrderBy(m => m.InsertTime).Select(m => m.Position).ToList().Count();
                    db.SliderImages.Add(new SliderImage
                    {
                        URLPage  = model.URLPage,
                        Name     = name,
                        SliderId = model.SliderId,
                        Title    = model.Title,
                        Position = position
                    });
                    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());
                }
            }

            ModelState.AddModelError("", "باید تصویر انتخاب شود");
            ViewData["Slider"] = db.Sliders.Find(model.SliderId);
            return(View());
        }