Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Details(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (id == null)
            {
                return(View("Error"));
            }

            TestimonialsLang category = await _context.TestimonialsLangs.FirstOrDefaultAsync(p => p.Testimonials.Id == id && p.Lang.Code.ToLower() == "az");

            if (category == null)
            {
                return(View("Error"));
            }
            return(View(category));
        }
Exemplo n.º 3
0
        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)));
        }