public async Task <IActionResult> Edit(int id, [Bind("Id,Image")] TopicGalleryViewModel topicGallery)
        {
            if (ModelState.IsValid)
            {
                var row = _context.TopicGalleries.Where(x => x.Id == id).FirstOrDefault();

                foreach (var img in topicGallery.Image)
                {
                    if (img != null)
                    {
                        string filename = Guid.NewGuid().ToString().Substring(4) + img.FileName;
                        UploadFile(img, filename);
                        row.Image = filename;
                    }
                    else
                    {
                        row.Image = row.Image;
                    }
                }

                row.Id = topicGallery.Id;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(topicGallery));
        }
        public async Task <IActionResult> Create([Bind("Id,Image")] TopicGalleryViewModel topicGallery)
        {
            if (ModelState.IsValid)
            {
                foreach (var img in topicGallery.Image)
                {
                    string filename = "";
                    if (img != null)
                    {
                        filename = Guid.NewGuid().ToString().Substring(4) + img.FileName;
                        UploadFile(img, filename);
                    }
                    TopicGallery TopicGallery = new TopicGallery {
                        Id = topicGallery.Id, Image = filename
                    };
                    _context.TopicGalleries.Add(TopicGallery);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));
            }
            var gallery = _context.Blogs.ToList();

            ViewBag.gallery = new SelectList(gallery, "Id", "Image");
            return(View(topicGallery));
        }
        // GET: TopicGalleries/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var topicGallery = await _context.TopicGalleries.FindAsync(id);

            TopicGalleryViewModel model = new TopicGalleryViewModel {
                Id = topicGallery.Id
            };

            if (topicGallery == null)
            {
                return(NotFound());
            }
            var gallery = _context.Blogs.ToList();

            ViewBag.gallery = new SelectList(gallery, "Id", "Image");
            return(View(topicGallery));
        }