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)); }
public IActionResult Create([FromBody] PersonDTO personDTO) { try { _personApplicationService.Create(PersonAssembler.ToDO(personDTO)); return(Ok()); } catch (Exception e) { Console.WriteLine(e.Message); return(new NotFoundResult()); } }
public async Task <IActionResult> Create(PersonDTO personDTO) { var personDO = Mapper.Map <Person>(personDTO); try { await _personApplicationService.Create(personDO); return(Ok(new { message = "Create Person Success!" })); } catch (Exception ex) { _logger.LogError(ex, "Create Person Error!"); return(BadRequest(new { message = ErrorMessage })); } }
public async Task <IActionResult> Create([FromBody] PersonViewModel personViewModel) { var createdPerson = await _personAppService.Create(personViewModel); return(Created("/{id}", createdPerson)); }