public User MapFrom(NewUserCommand command) { var user = new User(command.Name, command.Email, command.Password, DateTime.Now); command.Phones.ForEach(phone => user.Phones.Add(new Phone(user.Id, phone.Ddd, phone.Number))); return(user); }
public async Task <IActionResult> Create([FromBody] NewUserCommand request) { request.IsGuest = true; var result = await Mediator.Send(request); return(Created(string.Empty, result)); }
public async Task <IActionResult> New(NewUserCommand command) { if (!ModelState.IsValid) { ModelState.AddModelError("Inválido", "Dados para login inválidos"); return(BadRequest()); } var user = new User(command.Email, command.Password); var result = await _userService.Create(user, user.Password); if (result.Succeeded) { var userCreated = await _userService.GetByEmail(user.Email); if (userCreated == null) { return(StatusCode(StatusCodes.Status500InternalServerError)); } var signInResult = await _userService.SignIn(userCreated, command.Password, true); if (signInResult.IsLockedOut) { return(StatusCode(StatusCodes.Status423Locked)); } return(RedirectToAction("Start", "Office")); } return(Unauthorized()); }
public void CriaUserCorretamente_UserCriado() { // Arrange var newUserCommand = new NewUserCommand(NAME, EMAIL, PASSWORD); newUserCommand.Phones.Add(new NewPhoneCommand(DDD1, PHONE1)); newUserCommand.Phones.Add(new NewPhoneCommand($"({DDD2})", PHONE2)); // Act var user = new UserMapper().MapFrom(newUserCommand); // Assert Assert.IsNotNull(user); Assert.AreNotEqual(Guid.Empty, user.Id); Assert.IsNotNull(user.Phones); Assert.IsTrue(user.Phones.Any()); Assert.AreEqual(2, user.Phones.Count); Assert.AreEqual(NAME, user.Name); Assert.AreEqual(EMAIL, user.Email); Assert.IsTrue(new Encryption().ComparePasswords(PASSWORD, user.Password)); Assert.AreEqual(user.Phones.First().Ddd, DDD1); Assert.AreEqual(user.Phones.First().Number, PHONE1); Assert.AreEqual(user.Phones.Last().Ddd, DDD2.OnlyNumbers()); Assert.AreEqual(user.Phones.Last().Number, PHONE2.OnlyNumbers()); }
public Guid Create(NewUserCommand command) { try { var existUser = UserRepository.GetByEmail(command.Email); if (existUser == null) { existUser = UserRepository.GetByUserName(command.NickName); } AssertConcern.AssertArgumentTrue(existUser == null, "Usuário já cadastrado"); var user = new User(command.NickName, command.Email, AccountType.Normal, SubscriptionType.Gratuity); user.GenerateNewId(); user.PasswordHash = SecurityService.Encrypt(command.Password); UserRepository.Save(user); AssertConcern.AssertArgumentNotGuidEmpty(user.UserId, "Id do usuário de domínio criado incorretamente"); Uow.Commit(); return(user.UserId); } catch (Exception ex) { throw ex; } }
public IActionResult Register(NewUserCommand user) { bool result = _mediator.Send(user).Result; if (result) { return(RedirectToAction("Login")); } return(View()); }
public UserPageVM() { Usuarios = new ObservableCollection <User>(UserQueries.GetUsers()); Empleados = new List <IdName>(PersonaQueries.GetEmpleadosDropDown()); Roles = new ObservableCollection <Role>(UserQueries.GetRoles()); SelectedRole = new Role(); NuevoUsuarioCommand = new NewUserCommand(this); UpdateUsuarioCommand = new UpdateUserCommand(this); NewPasswordCommand = new UpdateUserPassword(this); NewUser = new User(); }
public IHttpActionResult CreateNewUser(NewUserCommand command) { if (!ModelState.IsValid) { return(BadRequest("Dados inválidos para criação da conta")); } var userId = UserAppService.Create(command); return(Ok(userId)); }
public NewUserCommandResult New([FromBody] NewUserCommand command) { command.setRequestHost(HttpContext.Request.Host.ToString()); _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method }); NewUserCommandResult result = (NewUserCommandResult)_userHandler.Handle(command); _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { User = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode }); HttpContext.Response.StatusCode = result.Code; return(result); }
public async Task <IActionResult> Post([FromBody] NewUserCommand command) { if (ModelState.IsValid) { await _createUserUseCase.Handle( new CreateUserRequest(command.Email, command.PasswordHash), _createUserPresenter ); if (_createUserPresenter.Succeeded) { return(Created($"api/user/{_createUserPresenter.Id}", _createUserPresenter.ContentResult)); } else { return(_createUserPresenter.ContentResult); } } return(BadRequest(ModelState)); }
public async Task <IActionResult> Create([FromBody] NewUserCommand request) { var result = await Mediator.Send(request); return(Created("GetUser", result)); }
public async Task <IHttpActionResult> Post([FromBody] NewUserCommand command) { var result = await _commandHandler.ExecuteAsync(command); return(ProcessResult(result)); }
public IHttpActionResult NewUser(NewUserCommand command) { var response = _mediator.Request(command); return(Created("", response.Data)); }
public IActionResult AddUser([FromBody] NewUserCommand command) { return(_commandHandler.ExecuteCommand(command, UserId)); }
public IActionResult Login(NewUserCommand user) { return(_mediator.Send(user).Result ? RedirectToAction("Index", "Home") as IActionResult : View()); }