public User Create(CreateUserCommand commandUser) { var user = new User(commandUser.IdPerson, commandUser.Email, commandUser.UserName); user.Validate(); _repository.Create(user, "C@achinP1an"); if (Commit()) return user; return null; }
public Task<HttpResponseMessage> Post([FromBody]dynamic body) { var cpf = _servicePerson.GetOneByCPF((string)body.cpf); if (cpf != null) return CreateResponse(HttpStatusCode.Ambiguous, cpf); var email = _service.GetOneByEmail((string)body.email); if (email != null) return CreateResponse(HttpStatusCode.Ambiguous, cpf); var listAddress = _serviceAddress.AddToPerson(body.address); var listPhone = _servicePhone.AddToPerson(body.phone); var commandPerson = new CreatePersonCommand( name: (string)body.name, cpf: (string)body.cpf, birthDate: (DateTime)body.birthDate, genre: (EGenre)body.genre, address: listAddress, phone: listPhone, phototgraph: (string)body.photograph ); var person = _servicePerson.Create(commandPerson); var commandUser = new CreateUserCommand( email: (string)body.email, password: (string)body.password, userName: (string)body.email, idPerson: person.Id, type: (ETypeUser)body.type ); var user = _service.Create(commandUser); if (commandUser.Type == ETypeUser.Administrator) _service.AddRole(user.Id, "Administrator"); else if (commandUser.Type == ETypeUser.SessionManager) _service.AddRole(user.Id, "SessionManager"); var token = _service.GenerateTokenRecoveryPassword(user.Email); _service.SendEmailRecoveryPassword(user.Id, token); return CreateResponse(HttpStatusCode.Created, user); }