public async Task <ActorDetailedDTO> CreateAsync(ActorCreateUpdateDTO actor)
        {
            var entity = new Actor
            {
                Name = actor.Name
            };

            _context.Actors.Add(entity);
            await _context.SaveChangesAsync();

            return(await FindAsync(entity.Id));
        }
示例#2
0
        public async Task <CharacterDTO> CreateAsync(CharacterCreateUpdateDTO character)
        {
            var entity = new Character
            {
                ActorId = character.ActorId,
                Name    = character.Name,
                Species = character.Species,
                Planet  = character.Planet,
            };

            _context.Characters.Add(entity);
            await _context.SaveChangesAsync();

            return(await FindAsync(entity.Id));
        }
示例#3
0
        public async Task <EpisodeDetailedDTO> CreateAsync(EpisodeCreateUpdateDTO episode)
        {
            var entity = new Episode
            {
                Title             = episode.Title,
                FirstAired        = episode.FirstAired,
                EpisodeCharacters = episode.CharacterIds.Select(c => new EpisodeCharacter {
                    CharacterId = c
                }).ToList()
            };

            _context.Episodes.Add(entity);
            await _context.SaveChangesAsync();

            return(await FindAsync(entity.Id));
        }
示例#4
0
        public async Task <int> CreateAsync(CharacterCreateDTO character)
        {
            var entity = new Character
            {
                ActorId = character.ActorId,
                Name    = character.Name,
                Species = character.Species,
                Planet  = character.Planet,
                Image   = character.Image
            };

            _context.Characters.Add(entity);

            await _context.SaveChangesAsync();

            return(entity.Id);
        }
示例#5
0
        public async Task <bool> DeleteAsync(int characterId)
        {
            var character = await _context.Characters.FindAsync(characterId);

            if (character == null)
            {
                return(false);
            }

            _context.Characters.Remove(character);

            await _context.SaveChangesAsync();

            return(true);
        }