示例#1
0
 public static void AddInDataBase <T>(T[] data, LudothequeAccountContext context)
 {
     foreach (var d in data)
     {
         context.Add(d);
     }
     context.SaveChanges();
 }
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] MaterialSupport materialSupport)
        {
            if (ModelState.IsValid)
            {
                _context.Add(materialSupport);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(materialSupport));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] Illustrator illustrator)
        {
            if (ModelState.IsValid)
            {
                _context.Add(illustrator);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(illustrator));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Id,label")] Difficulty difficulty)
        {
            if (ModelState.IsValid)
            {
                _context.Add(difficulty);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(difficulty));
        }
示例#5
0
 /// <summary>
 /// Add game in database
 /// </summary>
 /// <param name="game">Game to add</param>
 /// <returns></returns>
 public async Task AddGame(Game game)
 {
     _context.Add(game);
     await _context.SaveChangesAsync();
 }
示例#6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,MinPlayer,MaxPlayer,MinimumAge,GameTime,Price,ReleaseDate,BuyLink,VideoLink,PictureLink,Validate,DifficultyId,IllustratorId,EditorId")] Game game, string[] selectedThemes, string[] selectedMs, string[] selectedMecha)
        {
            if (game.EditorId == -1)
            {
                game.EditorId = null;
            }
            if (game.DifficultyId == -1)
            {
                game.DifficultyId = null;
            }
            if (game.IllustratorId == -1)
            {
                game.IllustratorId = null;
            }
            if (selectedMecha != null)
            {
                game.MechanismsGames = new List <MechanismsGames>();
                foreach (var mecha in selectedMecha)
                {
                    var mechaToAdd = new MechanismsGames()
                    {
                        GameId = game.Id, MechanismId = int.Parse(mecha)
                    };
                    game.MechanismsGames.Add(mechaToAdd);
                }
            }
            if (selectedMs != null)
            {
                game.MaterialSupportsGames = new List <MaterialSupportsGames>();
                foreach (var ms in selectedMs)
                {
                    var msToAdd = new MaterialSupportsGames()
                    {
                        GameId = game.Id, MaterialSupportId = int.Parse(ms)
                    };
                    game.MaterialSupportsGames.Add(msToAdd);
                }
            }
            if (selectedThemes != null)
            {
                game.ThemesGames = new List <ThemesGames>();
                foreach (var t in selectedThemes)
                {
                    var themeToAdd = new ThemesGames()
                    {
                        GameId = game.Id, ThemeId = int.Parse(t)
                    };
                    game.ThemesGames.Add(themeToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                var test = errors;
            }
            ViewDataRelationOtM(game);

            ViewDataRelationMtM(game);
            return(View(game));
        }