Пример #1
0
        public async Task Create(Character character)
        {
            List <Error> errors = new List <Error>();

            if (string.IsNullOrWhiteSpace(character.Name))
            {
                base.AddError("Nome", "O nome do personagem deve ser informado");
            }
            else if (character.Name.Length > 50)
            {
                base.AddError("Nome", "O nome do personagem deve conter até 50 caracteres");
            }
            if (character.Age <= 0)
            {
                base.AddError("Idade", "A idade do personagem deve ser informada");
            }
            if (character.Height <= 0)
            {
                base.AddError("Altura", "A altura do personagem deve ser informada");
            }

            base.CheckErrors();
            try
            {
                await _CharacterRepository.Create(character);
            }
            catch (Exception ex)
            {
                File.WriteAllText("log.txt", ex.Message + " - " + ex.StackTrace);
                throw new Exception("Erro no banco de dados, contate o admnistrador.");
            }
        }
Пример #2
0
        public JsonResult Add([FromBody] CharactersModelView character)
        {
            if (CheckColors(character.Color, HttpContext.Response, out var result))
            {
                return(result);
            }

            var check = _repository.Exists(character.Id);

            if (check)
            {
                HttpContext.Response.StatusCode = StatusCodes.Status409Conflict;
                return(Json(new ErrorMessage("already exists")));
            }
            var res = _repository.Create(new Character(
                                             character.Id,
                                             character.Name,
                                             character.Color[0],
                                             character.Color[1],
                                             character.Color[2],
                                             character.Color[3]
                                             ));

            return(Json(new CharactersModelView(res)));
        }
 // ADD CRUD Functionality for service
 public Character CreateCharacter(Character character)
 {
     // RULES:
     // 1.) Must have a name
     // 2.) Character can not start with more than 100 health
     return(_characterRepository.Create(character));
 }
        private void CreateCharacter()
        {
            Character newCharacter = io.PromptUserForNewCharacter();

            newCharacter = repo.Create(newCharacter);

            io.DisplayCharacter(repo.ReadById(newCharacter.Id));
        }
        public void CreateCharacter(CharacterModel model)
        {
            var entity = new DungeonMap_Entities.Character()
            {
                CharacterName = model.CharacterName,
                GameId        = model.GameId,
                RoleType      = model.RoleType,
                UserId        = model.UserId
            };

            _characterRepo.Create(entity);
        }
        public async Task <IActionResult> Create(string userId, CharacterViewModel model)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value || User.FindFirst(ClaimTypes.Role).Value == EnumRoles.ORGANIZER)
            {
                return(Unauthorized());
            }

            var newCharacter = _mapper.Map <CharacterDto>(model);

            var result = await _characterRepository.Create(userId, newCharacter);

            return(CreatedAtRoute("GetById", new { userId = userId, characterKey = result.CharacterKey }, result));
        }
Пример #7
0
        public async Task <IResponse> Handle(CreateCharacterCommand command)
        {
            command.Validate();

            if (command.Invalid)
            {
                return(new GenericCommandResponse(false, "Comando Inválido", command.Notifications));
            }

            var houseIsValid = await _potterService.ValidateHouse(command.House);

            if (!houseIsValid)
            {
                return(new GenericCommandResponse(false, "Comando Inválido", new Notification("House", "Casa não encontrada")));
            }

            var character = new Character(command.Name, command.Role, command.School, command.House, command.Patronus);
            await _characterRepository.Create(character);

            return(new GenericCommandResponse(true, "OK", character));
        }
Пример #8
0
 public void CreateCharacter(SwCharacter newCharacter)
 {
     _repository.Create(newCharacter);
 }
Пример #9
0
        public bool Create(CharacterCreateRequest request)
        {
            CharacterDataModel character = _converter.RequestToDataModel(request);

            return(_repository.Create(character));
        }