Ejemplo n.º 1
0
        public async Task <IActionResult> EditPost(int id, CreateTeamVM 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));
            }
            OurTeam newCategory = await _context.OurTeam.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;
            }
            OurTeamLang azBlogLangFromDb = await _context.OurTeamLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                           x.OurTeamId == newCategory.Id);

            OurTeamLang ruBlogLangFromDb = await _context.OurTeamLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                           x.OurTeamId == newCategory.Id);

            OurTeamLang enBlogLangFromDb = await _context.OurTeamLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                           x.OurTeamId == newCategory.Id);

            azBlogLangFromDb.FullName   = category.FullNameAZ;
            enBlogLangFromDb.FullName   = category.FullNameEN;
            ruBlogLangFromDb.FullName   = category.FullNameRU;
            azBlogLangFromDb.Profession = category.ProfessionAZ;
            enBlogLangFromDb.Profession = category.ProfessionEN;
            ruBlogLangFromDb.Profession = category.ProfessionRU;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo 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"));
            }

            OurTeamLang category = await _context.OurTeamLangs.FirstOrDefaultAsync(p => p.OurTeam.Id == id && p.Lang.Code.ToLower() == "az");

            if (category == null)
            {
                return(View("Error"));
            }
            return(View(category));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreateTeamVM 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");

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

            await _context.OurTeam.AddAsync(newCategory);

            await _context.SaveChangesAsync();

            OurTeamLang historyAZ = new OurTeamLang
            {
                FullName   = category.FullNameAZ,
                Profession = category.ProfessionAZ,
                LangId     = azLang.Id,
                OurTeamId  = newCategory.Id
            };
            OurTeamLang historyEN = new OurTeamLang
            {
                FullName   = category.FullNameEN,
                Profession = category.ProfessionEN,
                LangId     = enLang.Id,
                OurTeamId  = newCategory.Id
            };
            OurTeamLang historyRU = new OurTeamLang
            {
                FullName   = category.FullNameRU,
                Profession = category.ProfessionRU,
                LangId     = ruLang.Id,
                OurTeamId  = newCategory.Id
            };

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

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