예제 #1
0
 private void InsertPicture(Picture _pic, CategoryViewModel model)
 {
     if (model.Picture != null && model.Picture.ContentLength > 0 && model.PictureId == 0 || model.PictureId == null)
     {
         _pic.Title     = model.Name;
         _pic.SmallPath = ImgUploadService.imgSingUpload(model.Picture, 200, 200);
         _pic.Default   = ImgUploadService.imgDefaultSingUpload(model.Picture);
         _pic.Alt       = model.Name;
         _pic.OrderNo   = 0;
         _pictureService.Insert(_pic);
     }
     if (model.Picture != null && model.Picture.ContentLength > 0 && model.PictureId > 0 && model.PictureId != null)
     {
         _pic.Id        = model.PictureId ?? 0;
         _pic.Title     = model.Name;
         _pic.SmallPath = ImgUploadService.imgSingUpload(model.Picture, 200, 200);
         _pic.Default   = ImgUploadService.imgDefaultSingUpload(model.Picture);
         _pic.Alt       = model.Name;
         _pic.OrderNo   = 0;
         _pictureService.Update(_pic);
     }
 }
예제 #2
0
        public ActionResult AsyncUpload()
        {
            HttpPostedFileBase file = Request.Files[0];

            if (file == null)
            {
                throw new Exception("No file Upload");
            }
            Picture _pic = new Picture();

            _pic.SmallPath = ImgUploadService.imgSingUpload(file, 200, 200);
            _pic.Default   = ImgUploadService.imgDefaultSingUpload(file);
            if (_pictureService.Insert(_pic) != null)
            {
                var result = new PictureViewModel();
                result.SmallPath = _pic.SmallPath;
                result.Id        = _pic.Id;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            return(Json(""));
        }