public UpdateResponse Update(UpdateRequest request) { if (request == null) { AddNotification("UpdateRequest", Message.X0_E_OBRIGATORIO.ToFormat("UpdateRequest")); } var player = _playerRepository.GetById(request.Id); if (player == null) { AddNotification("Id", Message.DADOS_NAO_ENCONTRADOS); } var name = new NamePerson(request.FirstName, request.LastName); var email = new Email(request.Email); player.UpdatePlayer(name, email, player.Status); AddNotifications(player); if (player.IsInvalid()) { return(null); } _playerRepository.ToEdit(player); return((UpdateResponse)player); }
public CreateResponse Create(CreateRequest request) { if (request == null) { AddNotification("Adicionar", Message.OBJETO_X0_E_OBRIGATORIO.ToFormat("CreateRequest")); } var namePerson = new NamePerson(request.FirstName, request.LastName); var email = new Email(request.Email); var password = request.PassWord; var player = new Player(namePerson, email, password); AddNotifications(namePerson, email); var playerExist = _playerRepository.Exists(x => x.Email.Adress == request.Email); if (playerExist) { AddNotification("E-mail", Message.JA_EXISTE_UM_X0_CHAMADO_X1.ToFormat("e-mail", request.Email)); } if (IsInvalid()) { return(null); } player = _playerRepository.Create(player); return((CreateResponse)player); }
public void UpdatePlayer(NamePerson name, Email email, StatusPlayerEnum status) { NamePerson = name; Email = email; new AddNotifications <Player>(this).IfFalse(status == StatusPlayerEnum.Active, "Só é possível alterar jogador se estiver ativo"); AddNotifications(name, email); }
public Player(NamePerson namePerson, Email email, string password) { NamePerson = namePerson; Email = email; Password = password; Status = StatusPlayerEnum.InProgress; new AddNotifications <Player>(this).IfNullOrInvalidLength(x => x.Password, 6, 32, Message.X0_OBRIGATORIA_E_DEVE_CONTER_ENTRE_X1_E_X2_CARACTERES.ToFormat("Senha", "3", "50")); if (IsValid()) { Password = Password.ConvertToMD5(); } AddNotifications(namePerson, email); }