예제 #1
0
        private async Task <AnimeCharacter> InsertCharacterAsync(long malId)
        {
            var existingCharacter = await _characterRepository.GetAsync(malId);

            if (existingCharacter != null)
            {
                return(existingCharacter);
            }

            var parsedData = await _malApiService.GetCharacterDataAsync(malId);

            if (parsedData is null)
            {
                return(null);
            }

            var newCharacter = new AnimeCharacter
            {
                Id         = Guid.NewGuid(),
                MalId      = malId,
                ImageUrl   = parsedData.ImageUrl,
                Name       = parsedData.Name,
                Popularity = parsedData.Popularity,
                About      = parsedData.About,
                KanjiName  = parsedData.JapaneseName,
                Nicknames  = parsedData.Nicknames
            };

            await _characterRepository.AddAsync(newCharacter);

            Console.WriteLine($"Inserted character with malId {malId} ({parsedData.Name})");

            return(newCharacter);
        }
예제 #2
0
        public async Task AddCharacterAsync(CharacterForCreationDto dto)
        {
            var character = new Character(dto.Name, dto.Planet, dto.Episodes);

            await _characterRepository.AddAsync(character);

            await _characterRepository.SaveChangesAsync();
        }
        public async Task <CharacterDto> Handle(CreateCharacterCommand request, CancellationToken cancellationToken)
        {
            var character = Domain.Characters.Character.Create(request.UserId, request.FirstName, request.LastName, request.Sex, _singleCharacterPerUserChecker);

            await _characterRepository.AddAsync(character, cancellationToken);

            await _unitOfWork.CommitAsync(cancellationToken);

            return(CharacterDto.FromCharacter(character));
        }
        public async Task <IActionResult> Post([FromBody, Bind("Name")] ApiCharacter apiCharacter)
        {
            // there was some "overposting" vulnerability here... i do not want client to be able
            // to set the ID. either i can make sure to ignore that value if he sends it
            // or i can explicitly not bind it.

            Character character    = _mapper.Map(apiCharacter);
            Character newCharacter = await _characterRepository.AddAsync(character);

            ApiCharacter newApiCharacter = _mapper.Map(newCharacter);

            return(CreatedAtAction(nameof(GetById), new { id = newApiCharacter.Id },
                                   newApiCharacter));
        }
예제 #5
0
        public async Task AddAsync(Guid userId, string name, int server)
        {
            var account = await _accountRepository.GetAsync(userId);

            if (account != null)
            {
                var character = await _characterRepository.GetAsync(name, server);

                if (character == null)
                {
                    character = new Character(account, name, server);
                    await _characterRepository.AddAsync(character);
                }
                else
                {
                    throw new Exception("Character alredy exists");
                }
            }
            else
            {
                throw new Exception("Account doesnt exists");
            }
        }
예제 #6
0
        public async Task CreateCharacterAsync(Guid id, string name)
        {
            var newCharacter = await _characterFactory.CreateAsync(id, name);

            await _characterRepository.AddAsync(newCharacter);
        }