public async Task <IActionResult> Add(List <string> Names)
        {
            List <Language> languages = await db.Languages.ToListAsync();

            if (Checker.CheckList(Names))
            {
                Color color = new Color();
                db.Colors.Add(color);
                for (int i = 0; i < languages.Count; i++)
                {
                    ColorLanguage colorLanguage = new ColorLanguage();
                    colorLanguage.Name       = Names[i];
                    colorLanguage.LanguageId = languages[i].Id;
                    colorLanguage.ColorId    = color.Id;
                    db.ColorLanguage.Add(colorLanguage);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError("", "Fill all Blanks");
                return(View());
            }
        }
示例#2
0
        public IActionResult Delete(int?id)
        {
            ColorLanguage colorLanguage = _baselDb.Colors
                                          .SelectMany(x => x.ColorLanguages)
                                          .Where(x => x.LanguageId == 1)
                                          .Include(x => x.Color)
                                          .Where(x => x.ColorId == id)
                                          .SingleOrDefault();

            return(View(colorLanguage));
        }