public async Task <IActionResult> UploadNewImage(UploadImageModel uploadImage)
        {
            if (ModelState.IsValid)
            {
                // uploading path
                var path = Path.Combine(_environment.WebRootPath, @"images");

                var fileName = uploadImage.ImageUpload.FileName;
                using (var fileStream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                {
                    await uploadImage.ImageUpload.CopyToAsync(fileStream);
                }

                var tags = uploadImage.Tags.Split(',');

                var model = new GalleryImage
                {
                    Title   = uploadImage.Title,
                    Url     = "/images/" + fileName,
                    Created = new DateTime(),
                };


                _context.GalleryImages.Add(model);
                _context.SaveChanges();
            }
            ;
            return(RedirectToAction("Index", "Gallery"));
        }
        public async Task <IActionResult> UploadNewImage(UploadImageViewModel image)
        {
            if (image.ImageUpload != null)
            {
                string path = "/images/" + image.ImageUpload.FileName;
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await image.ImageUpload.CopyToAsync(fileStream);
                }

                ImageModel galleryImage = new ImageModel()
                {
                    Url = path
                };

                _context.Images.Add(galleryImage);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index", "Gallery"));
        }
 public void CreateImage(GalleryImage galleryImage)
 {
     _ctx.Add(galleryImage);
     _ctx.SaveChanges();
 }