Ejemplo n.º 1
0
        public async Task <IActionResult> Upload(UploadVM uploadVM)
        {
            if (ModelState.IsValid)
            {
                Image newImage = new Image()
                {
                    Title    = uploadVM.Title,
                    Created  = DateTime.Now,
                    ImageUrl = "/images/gallery/" + uploadVM.ImageUploaded.FileName
                };
                if (uploadVM.ImageUploaded != null && uploadVM.ImageUploaded.Length > 0)
                {
                    string path = Path.Combine(_webHostEnvironment.ContentRootPath, "wwwroot\\images\\gallery\\", uploadVM.ImageUploaded.FileName);

                    using (var fStream = new FileStream(path, FileMode.Create))
                    {
                        await uploadVM.ImageUploaded.CopyToAsync(fStream);
                    }
                }
                _imageService.AddImage(newImage);

                TempData["message"] = $"Image \"{uploadVM.Title}\" has benn added to gallery";
                return(RedirectToAction("Index", "Gallery"));
            }
            else
            {
                return(View(uploadVM));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Upload(UploadImageModel uploadImageModel)
        {
            if (ModelState.IsValid)
            {
                var webRoot  = _env.WebRootPath;
                var filePath = Path.Combine(webRoot.ToString() + "\\images\\" + uploadImageModel.ImageUpload.FileName);

                if (uploadImageModel.ImageUpload.FileName.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await uploadImageModel.ImageUpload.CopyToAsync(stream);
                    }
                }

                var image = new GalleryImage
                {
                    Title = uploadImageModel.Title,
                    Tags  = uploadImageModel.Tags.Split(",").Select(tag => new ImageTag
                    {
                        Description = tag
                    }).ToList(),
                    Created = DateTime.Today,
                    Url     = "/images/" + uploadImageModel.ImageUpload.FileName
                };

                _image.AddImage(image);

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

            return(View(uploadImageModel));
        }
Ejemplo n.º 3
0
 public void AddImage(Image img)
 {
     if (img != null)
     {
         img.Id = Guid.NewGuid();
         _imgRepository.AddImage(img);
     }
 }
Ejemplo n.º 4
0
 public IActionResult Post([FromBody] Image image)
 {
     imageService.AddImage(image);
     return(Ok());
 }
Ejemplo n.º 5
0
 public Image AddImage(Image image)
 {
     return(context.AddImage(image));
 }