Exemple #1
0
        public async Task <IActionResult> Edit(int id, CreateAboutVM about)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

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

            if (!ModelState.IsValid)
            {
                return(View(about));
            }

            var currentAbout = await _context.About.FirstOrDefaultAsync(p => p.Id == id);

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

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

                string filename = await about.Photo.SaveAsync(_env.WebRootPath);

                currentAbout.PhotoURL = filename;
            }

            AboutLang azBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                      x.AboutId == currentAbout.Id);

            AboutLang ruBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                      x.AboutId == currentAbout.Id);

            AboutLang enBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                      x.AboutId == currentAbout.Id);

            azBlogLangFromDb.Description = about.DescriptionAZ;
            enBlogLangFromDb.Description = about.DescriptionEN;
            ruBlogLangFromDb.Description = about.DescriptionRU;

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "About"));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

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

            var about = await _context.About.FirstOrDefaultAsync(p => p.Id == id);

            var viewModel = new CreateAboutVM
            {
                DescriptionAZ = about.AboutLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "az").Description,
                DescriptionEN = about.AboutLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "en").Description,
                DescriptionRU = about.AboutLangs.FirstOrDefault(x => x.Lang.Code.ToLower() == "ru").Description,
            };

            return(View(viewModel));
        }