// GET: Image/Create
        public IActionResult Create()
        {
            List <Plant> plants = context.Plants.ToList();
            AddProgressPhotoViewModel addProgressPhotoViewModel = new AddProgressPhotoViewModel(plants);

            return(View(addProgressPhotoViewModel));
        }
        public async Task <IActionResult> Create([Bind("ImageID,Name,ImageFile")] ProgressPhotos imageModel, AddProgressPhotoViewModel addProgressPhotoViewModel)
        {
            if (ModelState.IsValid)
            {
                //save image to wwwroot folder
                string wwwrootPath = hostEnvironment.WebRootPath;
                string FileName    = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
                string extension   = Path.GetExtension(imageModel.ImageFile.FileName);
                imageModel.Name = FileName = FileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwrootPath + "/Images/" + FileName);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await imageModel.ImageFile.CopyToAsync(fileStream);
                }

                Plant          thePlant         = context.Plants.Find(addProgressPhotoViewModel.PlantId);
                ProgressPhotos newProgressPhoto = new ProgressPhotos
                {
                    Name      = addProgressPhotoViewModel.Name,
                    Plant     = thePlant,
                    PhotoName = addProgressPhotoViewModel.PhotoName
                };


                //insert record
                context.Add(imageModel);
                context.ProgressPhotos.Add(newProgressPhoto);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModel));
        }