コード例 #1
0
ファイル: DbSeed.cs プロジェクト: BaronAdam/Star-Wars
        private IEnumerable <CharacterToEpisodeXref> BuildCharacterToEpisodeXrefsList()
        {
            var characterToEpisodeList = new List <CharacterToEpisodeXref>();

            for (int i = 1; i <= 7; i++)
            {
                if (i == 5)
                {
                    var characterToEpisode = new CharacterToEpisodeXref
                    {
                        CharacterId = i,
                        EpisodeId   = 1
                    };

                    characterToEpisodeList.Add(characterToEpisode);
                }
                else
                {
                    for (int j = 1; j <= 3; j++)
                    {
                        var characterToEpisode = new CharacterToEpisodeXref
                        {
                            CharacterId = i,
                            EpisodeId   = j
                        };

                        characterToEpisodeList.Add(characterToEpisode);
                    }
                }
            }

            return(characterToEpisodeList);
        }
コード例 #2
0
        public async Task <IActionResult> CreateCharacterToEpisodeXref([FromBody] CreateCharacterToEpisodeXref data)
        {
            var characterToEpisodeXref = new CharacterToEpisodeXref
            {
                CharacterId = data.CharacterId,
                EpisodeId   = data.EpisodeId
            };

            await _context.AddAsync(characterToEpisodeXref);

            await _context.SaveChangesAsync();

            return(Created(characterToEpisodeXref.Id.ToString(), new FriendViewModel
            {
                Id = characterToEpisodeXref.Id,
                CharacterId = characterToEpisodeXref.CharacterId,
                FriendId = characterToEpisodeXref.EpisodeId
            }));
        }