コード例 #1
0
        public IActionResult Upload([FromServices] IHostingEnvironment environment)
        {
            var temp = Request.Form["categoryId"];

            IFormFile file = Request.Form.Files["upload_name"];

            if (file == null)
            {
                return(Content("请选择上传图片"));
            }

            string extension = Path.GetExtension(file.FileName),
                   fileName  = $"{DateTime.Now.ToString("yyyyMMddHHmmsss")}{extension}",
                   filePath  = Path.Combine(environment.WebRootPath, "uploads"),
                   fullPath  = Path.Combine(filePath, fileName),
                   vPath     = Path.Combine("\\uploads", fileName);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            using (var stream = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                file.CopyTo(stream);
            }

            int categoryId = Convert.ToInt32(temp.Single());

            _service.Add(new ImageEntity
            {
                CategoryId = categoryId,
                FilePath   = vPath
            });
            return(Redirect("/admin/image/list"));
        }
コード例 #2
0
        //[Route("Upload")]
        public async Task <IActionResult> PostImage([FromForm] IFormFile file)
        {
            string userId;

            try
            {
                userId = User.Claims.First(c => c.Type == "UserID").Value;
            }
            catch
            {
                return(Unauthorized());
            }
            var imageName = await _imageFileService.UploadImage(file);

            if (!"failed".Equals(imageName))
            {
                Photo photo = new Photo()
                {
                    Name              = imageName,
                    Location          = _baseUrlHelper.GetBaseUrl() + "/Images/" + imageName,
                    CreateDate        = DateTime.Now,
                    ApplicationUserId = userId
                };
                _imageService.Add(photo);
                _imageService.SaveChanges();
                return(Ok(photo));
            }
            else
            {
                return(BadRequest(new { message = "Invalid image type!" }));
            }
        }
コード例 #3
0
 public IActionResult Add([FromBody] ImportImageData data)
 {
     try
     {
         string fileName = data.ImageFileName;
         if (string.IsNullOrWhiteSpace(GetContentType(data.ImageFileName)))
         {
             throw new Exception("Invalid file type. Only JPEG and PNG files are supported.");
         }
         var jBuffer = data.Buffer as Newtonsoft.Json.Linq.JObject;
         if (null == jBuffer)
         {
             throw new Exception("Inbound data is not in the correct format!");
         }
         List <byte> buffer = new List <byte>();
         foreach (var item in jBuffer.Children())
         {
             var jProp = item as Newtonsoft.Json.Linq.JProperty;
             if (null == jProp)
             {
                 throw new Exception("Inbound data is not in the correct format!");
             }
             buffer.Add((byte)jProp.Value);
         }
         imageService.Add(fileName, buffer.ToArray());
         return(Json(string.Format("Successfully added {0}", fileName)));
     }
     catch (Exception x)
     {
         return(Json(new ErrorReport {
             Error = x.Message
         }));
     }
 }
コード例 #4
0
 private async Task <string> TryUpdateImage()
 {
     if (goal?.Image != null)
     {
         imageService.Remove(goal.Image);
     }
     return(await imageService.Add(selectedImageUri, cropView.VisibleRectangleBitmap));
 }
コード例 #5
0
        public ActionResult CreateImage(int prodId)
        {
            ImageViewModel img = new ImageViewModel();

            _imageService.Add(img);
            _productService.SetImage(prodId, img.ImageID);
            return(View("Images/Create", img));
        }
コード例 #6
0
        public ActionResult CreateImage(int subcatId)
        {
            ImageViewModel img = new ImageViewModel();

            _imageService.Add(img);
            _subcategoryService.SetImage(subcatId, img.ImageID);
            return(View("Images/Create", img));
        }
コード例 #7
0
        public IActionResult PostAdd([FromForm] CarImages carImages, [FromForm] IFormFile file)
        {
            var result = _ımageService.Add(carImages, file);

            if (result.Success)
            {
                return(Ok());
            }
            return(BadRequest(result));
        }
コード例 #8
0
        public IActionResult Add([FromForm(Name = "Image")] IFormFile file, [FromForm] Image image)
        {
            var result = _imageService.Add(file, image);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
コード例 #9
0
        public IActionResult Add(Image image)
        {
            var result = _imageService.Add(image);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #10
0
        public IActionResult InsertImage([FromForm] CarImage carImage, [FromForm(Name = "image")] IFormFile formFile)
        {
            var result = _imageService.Add(carImage, formFile);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #11
0
        public IActionResult Add([FromForm] Image image, [FromForm] IFormFile file)
        {
            var result = _imageService.Add(image, file);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #12
0
        public ActionResult AddItem(ItemViewModel itemViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                itemViewModel.ImageViewModels = _itemService.GetCollectionImages(itemViewModel.Id).MapToCollectionViewModels();

                if (ModelState.IsValid)
                {
                    var itemDto = itemViewModel.MapToDtoModel();
                    _itemService.Add(itemDto, out int id);
                    _itemCache.Add(itemDto, id);

                    if (uploadImage != null)
                    {
                        itemViewModel.Screen       = ImageConvert.ImageToByteArray(uploadImage);
                        itemViewModel.ScreenFormat = ImageConvert.GetImageExtension(uploadImage);

                        var imageVM = new ImageViewModel()
                        {
                            Screen       = itemViewModel.Screen,
                            ScreenFormat = itemViewModel.ScreenFormat,
                            ItemId       = id
                        };

                        var imageDto = imageVM.MapToDtoModel();
                        _imageService.Add(imageDto, out int imageId);
                    }

                    return(RedirectToAction("Index", "User"));
                }

                itemViewModel.Statuses   = DictionaryOfStatuses();
                itemViewModel.Categories = DictionaryOfCategories();

                return(View(itemViewModel));
            }
            catch (NotFoundException exception)
            {
                ViewBag.ErrorMessage = exception.Message;
                return(View("NotFound"));
            }
        }
コード例 #13
0
        public IActionResult Add([FromForm(Name = ("Image"))] IFormFile file, [FromForm] CarImage carImage)
        {
            var result = _ImageService.Add(file, carImage);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
コード例 #14
0
        public IActionResult Add([FromForm] IFormFile file, [FromForm] Image carimage)
        {
            var result = _imageService.Add(carimage, file);

            if (result.succces)
            {
                return(Ok(result.succces));
            }

            return(BadRequest(result.message));
        }
コード例 #15
0
ファイル: StorageController.cs プロジェクト: fpetrov/KnOwl
        public async Task <IActionResult> CreateImage(List <IFormFile> files)
        {
            var response = await _imageService.Add(files);

            if (response == null)
            {
                return(BadRequest(new { message = "File with this name already exists!" }));
            }

            return(Ok(new { message = "New image was saved successfuly!" }));
        }
コード例 #16
0
        public async ValueTask <ActionResult <ImageResult> > Upload(IFormFile image)
        {
            using (var memoryStream = new MemoryStream())
            {
                await image.CopyToAsync(memoryStream);

                var imageBytes = memoryStream.ToArray();

                var hash = _imageService.Add(imageBytes);
                return(new ImageResult {
                    Hash = hash
                });
            }
        }
コード例 #17
0
        public Task PrepareAsync(SessionRecording recording)
        {
            var images = ExtractImagePaths(recording.Definition.PostSessionSteps)
                         .Concat(ExtractImagePaths(recording.Definition.SessionSteps))
                         .Concat(ExtractImagePaths(recording.Definition.PostSessionSteps))
                         .Select(s => s.Trim())
                         .Distinct();

            foreach (var image in images)
            {
                _images.Add(image);
            }

            return(Task.FromResult(true));
        }
コード例 #18
0
        private int?AddUserImage(IFormFile imagefile, ApplicationUser user)
        {
            var image = _imageService.CreateUserImage(imagefile, user.UserName);

            if (TryValidateModel(image))
            {
                _imageService.Add(image);
                var oldimage = _imageService.Find(user.ImageId);
                if (oldimage != null)
                {
                    _imageService.Delete(oldimage);
                }
                return(image.Id);
            }
            return(null);
        }
コード例 #19
0
        public IActionResult Add([FromForm(Name = ("carId"))] int carId)
        {
            var checkCount = CheckImageCount(Request.Form.Files);

            if (checkCount.Success)
            {
                var result = _imageService.Add(new ImageDto {
                    CarId = carId, Files = Request.Form.Files
                });
                if (result.Success)
                {
                    return(Ok(result));
                }

                return(BadRequest(result));
            }
            return(BadRequest(checkCount));
        }
コード例 #20
0
        public IResult Add(CarImage carImage, IFormFile formFile)
        {
            var result = BusinessRules.Run(CheckIfCarImageLimitExceded(carImage.CarId));

            if (result != null)
            {
                return(new ErrorResult(result.Message));
            }
            var imagePathResult = _imageService.Add(formFile);

            if (!imagePathResult.Success)
            {
                return(new ErrorResult(imagePathResult.Message));
            }
            carImage.ImagePath = imagePathResult.Data;
            carImage.Date      = DateTime.Now;
            _carImageDal.Add(carImage);
            return(new SuccessResult(Messages.Success));
        }
コード例 #21
0
        public async Task <ProfileDto> ChangeImageAsync(string image, User user)
        {
            user = await GetAsync(user.Id);

            string remPhotoId = "";

            if (image != null)
            {
                remPhotoId   = user.PhotoId;
                user.PhotoId = await _imageService.Add(image);
            }
            await _userGR.UpdateAsync(user);

            if (remPhotoId != null)
            {
                await _imageService.Remove(remPhotoId);
            }
            return(await GetProfileInfoAsync(user));
        }
コード例 #22
0
        public ActionResult Add(Image image, string returnUrl = null)
        {
            ViewBag.returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var errors = _imageService.ValidateImage(image);
                if (!errors.Any())
                {
                    _imageService.Add(image);
                    if (returnUrl != null)
                    {
                        return(Redirect(returnUrl));
                    }
                    return(RedirectToAction("Manage"));
                }
                ModelState.Merge(errors);
            }
            ViewBag.ImageTypes = _imageTypeService.GetAll();

            return(View(image));
        }
コード例 #23
0
ファイル: FullVapeController.cs プロジェクト: Tarahtelka/Vape
        public ActionResult Upload(HttpPostedFileBase uploadImage, int id)
        {
            FullVapeDTO fullVapeDto = imageService.GetFullVape(id);//?

            if (ModelState.IsValid && fullVapeDto != null)
            {
                ImageDTO image = new ImageDTO
                {
                    FullVapeId = id,
                    MimeType   = uploadImage.ContentType,
                };
                image.Data = new byte[uploadImage.ContentLength];
                uploadImage.InputStream.Read(image.Data, 0, uploadImage.ContentLength);
                imageService.Add(image);

                return(View("View"));
            }
            else
            {
                return(View("View1"));
            }
        }
コード例 #24
0
        public void Search(ClientEntities.Directory dir)
        {
            FileInfo[]      files   = null;
            DirectoryInfo[] subDirs = null;
            DirectoryInfo   root    = new DirectoryInfo(dir.Path);

            files = root.GetFiles();

            if (files != null)
            {
                foreach (FileInfo fi in files)
                {
                    /// Add to specific list(Casted)
                    String extension = Path.GetExtension(fi.FullName);
                    if (MusicExtensions.Contains(extension))
                    {
                        musicService.Add(new Music(fi.FullName, fi.Name), dirId);
                    }
                    else if (VideoExtensions.Contains(extension))
                    {
                        videoService.Add(new Video(fi.FullName, fi.Name), dirId);
                    }
                    else if (PictureExtensions.Contains(extension))
                    {
                        imageService.Add(new Image(fi.FullName, fi.Name), dirId);
                    }
                }


                subDirs = root.GetDirectories();

                foreach (DirectoryInfo dirInfo in subDirs)
                {
                    Search(new ClientEntities.Directory(dirInfo.Name, dirInfo.FullName));
                }
            }
        }
コード例 #25
0
ファイル: ImageHelper.cs プロジェクト: ppotapenko/Gallery
 public static void ImageUpload(IImageService imageService)
 {
     var resorce = HostingEnvironment.ApplicationPhysicalPath + GetDefaultImageRootFolder() + "\\data";
     var files = Directory.GetFiles(resorce);
     foreach (var file in files)
     {
         var hash = (Guid.NewGuid()).ToString();
         var regDate = DateTime.Now;
         var images = new Image
         {
             Name = new FileInfo(file).Name,
             Hash = hash,
             CreateDate = regDate
         };
         imageService.Add(images);
         File.Copy(file, GetImageFilePath(hash, regDate));
     }
 }
コード例 #26
0
 public ActionResult CreateImage(ImageViewModel vm)
 {
     if (ModelState.IsValid)
     {
         using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
         {
             var image = vm.ToEntity();
             if (vm.Files != null)
             {
                 var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath,
                                                                                 "Image"));
                 if (!Directory.Exists(uploadFolderPath))
                 {
                     Directory.CreateDirectory(uploadFolderPath);
                 }
                 foreach (var imageUpload in vm.Files)
                 {
                     if (imageUpload != null)
                     {
                         // If successful then upload image
                         var uploadResult = AppHelpers.UploadFile(imageUpload, uploadFolderPath,
                                                                  LocalizationService);
                         if (!uploadResult.UploadSuccessful)
                         {
                             TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                             {
                                 Message     = uploadResult.ErrorMessage,
                                 MessageType = GenericMessages.danger
                             };
                             unitOfWork.Rollback();
                             return(Json(new
                             {
                                 Result = false,
                                 Message = "Vui lòng kiểm tra lại thông tin hình ảnh",
                             }, JsonRequestBehavior.AllowGet));
                         }
                         image.ImageUrl = uploadResult.UploadedFileName;
                     }
                 }
             }
             _imageService.Add(image);
             try
             {
                 unitOfWork.Commit();
                 return(Json(new
                 {
                     Result = true,
                     Message = "Thành công",
                 }, JsonRequestBehavior.AllowGet));
             }
             catch (Exception ex)
             {
                 unitOfWork.Rollback();
                 LoggingService.Error(ex);
                 return(Json(new
                 {
                     Result = false,
                     Message = "Vui lòng kiểm tra lại thông tin hình ảnh",
                 }, JsonRequestBehavior.AllowGet));
             }
         }
     }
     else
     {
         return(Json(new
         {
             Result = false,
             Message = "Vui lòng kiểm tra lại thông tin hình ảnh",
         }, JsonRequestBehavior.AllowGet));
     }
     return(View(vm));
 }