public IActionResult Edit(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (id == null)
            {
                return(View("Error"));
            }
            Testimonials category  = _context.Testimonials.Find(id);
            var          viewModel = new CreateTestimonialsVM
            {
                FullNameAZ    = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "az").FullName,
                FullNameEN    = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "en").FullName,
                FullNameRU    = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "ru").FullName,
                DescriptionAZ = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "az").Description,
                DescriptionEN = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "en").Description,
                DescriptionRU = category.TestimonialLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "ru").Description,
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> EditPost(int id, CreateTestimonialsVM category)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Xaiş olunur düzgün doldurun.");
                return(View(category));
            }
            Testimonials newCategory = await _context.Testimonials.FindAsync(id);

            if (newCategory == null)
            {
                return(View("Error"));
            }

            if (category.Photo != null)
            {
                string computerPhoto = Path.Combine(_env.WebRootPath, "images", newCategory.PhotoURL);

                if (System.IO.File.Exists(computerPhoto))
                {
                    System.IO.File.Delete(computerPhoto);
                }

                string fileName = await category.Photo.SaveAsync(_env.WebRootPath);

                newCategory.PhotoURL = fileName;
            }
            TestimonialsLang azBlogLangFromDb = await _context.TestimonialsLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                                     x.TestimonialsId == newCategory.Id);

            TestimonialsLang ruBlogLangFromDb = await _context.TestimonialsLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                                     x.TestimonialsId == newCategory.Id);

            TestimonialsLang enBlogLangFromDb = await _context.TestimonialsLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                                     x.TestimonialsId == newCategory.Id);

            azBlogLangFromDb.FullName    = category.FullNameAZ;
            enBlogLangFromDb.FullName    = category.FullNameEN;
            ruBlogLangFromDb.FullName    = category.FullNameRU;
            azBlogLangFromDb.Description = category.DescriptionAZ;
            enBlogLangFromDb.Description = category.DescriptionEN;
            ruBlogLangFromDb.Description = category.DescriptionRU;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(CreateTestimonialsVM category)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                return(View(category));
            }

            if (category.Photo == null)
            {
                return(View(category));
            }

            string fileName = await category.Photo.SaveAsync(_env.WebRootPath);

            Lang azLang = await _context.Langs.FirstOrDefaultAsync(x => x.Code.ToLower() == "az");

            Lang ruLang = await _context.Langs.FirstOrDefaultAsync(x => x.Code.ToLower() == "ru");

            Lang enLang = await _context.Langs.FirstOrDefaultAsync(x => x.Code.ToLower() == "en");

            Testimonials newCategory = new Testimonials()
            {
                PhotoURL = fileName,
            };

            await _context.Testimonials.AddAsync(newCategory);

            await _context.SaveChangesAsync();

            TestimonialsLang historyAZ = new TestimonialsLang
            {
                FullName       = category.FullNameAZ,
                Description    = category.DescriptionAZ,
                LangId         = azLang.Id,
                TestimonialsId = newCategory.Id
            };
            TestimonialsLang historyEN = new TestimonialsLang
            {
                FullName       = category.FullNameEN,
                Description    = category.DescriptionEN,
                LangId         = enLang.Id,
                TestimonialsId = newCategory.Id
            };
            TestimonialsLang historyRU = new TestimonialsLang
            {
                FullName       = category.FullNameRU,
                Description    = category.DescriptionRU,
                LangId         = ruLang.Id,
                TestimonialsId = newCategory.Id
            };

            _context.TestimonialsLangs.AddRange(historyAZ, historyEN, historyRU);
            await _context.SaveChangesAsync();

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