public async Task <IActionResult> UpdateAsync(string id, UserUpdateCommand command) { command.UserId = id; await _mediator.Publish(command); return(NoContent()); }
public void Update(UserUpdateCommand command) { using (var transaction = new TransactionScope()) { var id = new UserId(command.Id); var user = userRepository.Find(id); if (user == null) { throw new UserNotFoundException(id); } if (command.Name != null) { var name = new UserName(command.Name); user.ChangeName(name); if (userService.Exists(user)) { throw new CanNotRegisterUserException(user, "이미 등록된 사용자임"); } } userRepository.Save(user); transaction.Complete(); } }
public async Task TruckHandler_update_invalid_error_database() { var mockContextRepository = new Mock <IContextRepository>(); var mockUserRepository = new Mock <IUserRepository>(); UserUpdateCommand userUpdateCommand = new UserUpdateCommand(); userUpdateCommand.Id = "04690063-39c2-4d86-8bf1-1ffbfb4503a2"; userUpdateCommand.Login = "******"; userUpdateCommand.Email = "*****@*****.**"; userUpdateCommand.Password = "******"; userUpdateCommand.Name = "Name"; userUpdateCommand.Role = "Role"; User _user = new User(); _user = null; mockUserRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_user); mockContextRepository.Setup(x => x.Update(It.IsAny <User>())).ReturnsAsync(true); UserHandler _handler = new UserHandler(mockContextRepository.Object, mockUserRepository.Object); var _return = await _handler.Handle(userUpdateCommand); Assert.False(_return.Success); Assert.Equal(HttpStatusCode.NotFound, _return.Code); Assert.Null(_return.Data); }
public async Task TruckHandler_update_invalid_notfound() { var mockContextRepository = new Mock <IContextRepository>(); var mockUserRepository = new Mock <IUserRepository>(); UserUpdateCommand userUpdateCommand = new UserUpdateCommand(); userUpdateCommand.Id = "04690063-39c2-4d86-8bf1-1ffbfb4503a2"; userUpdateCommand.Login = "******"; userUpdateCommand.Email = "*****@*****.**"; userUpdateCommand.Password = "******"; userUpdateCommand.Name = "Name"; userUpdateCommand.Role = "Role"; User _user = new User() { Email = "*****@*****.**", Id = "b627435c-45ed-43e0-8969-e20ae10b4f21", Login = "******", Name = "name", Password = "******", Role = "Administrator" }; mockUserRepository.Setup(x => x.GetById(It.IsAny <string>())).ReturnsAsync(_user); mockContextRepository.Setup(x => x.Update(It.IsAny <User>())).ReturnsAsync(false); UserHandler _handler = new UserHandler(mockContextRepository.Object, mockUserRepository.Object); var _return = await _handler.Handle(userUpdateCommand); Assert.False(_return.Success); Assert.Equal(HttpStatusCode.BadRequest, _return.Code); Assert.False((bool)_return.Data); }
public async Task <ActionResult <UpdateModel> > Update(int id, UserUpdateCommand command) { var currentUserId = int.Parse(User.Identity.Name); if (id != currentUserId && User.IsInRole(Role.Admin)) { return(Forbid()); } var user = new UserUpdateCommand(); user.Id = id; user.FirstName = command.FirstName; user.LastName = command.LastName; user.Username = command.Username; user.Email = command.Email; user.PhoneNumber = command.PhoneNumber; user.Password = command.Password; if (id != command.Id) { return(BadRequest()); } return(await Mediator.Send(user)); }
public async Task Deve_Verificar_Metodo_E_Retornar_Falha_De_Usuario_Duplicado_Quando_Atualizar_Username_Para_Um_Ja_Existente() { // Arrange var id = Guid.NewGuid(); var command = new UserUpdateCommand() { ID = id, Name = "Name", }; var user = new User() { ID = id, Name = command.Name, }; _moqUserRepository .Setup(p => p.RetrieveByIDAsync(command.ID, default)) .ReturnsAsync(user); _moqUserRepository .Setup(p => p.AnyAsync(x => x.Name.Equals(command.Name) && x.ID != command.ID, default)) .ReturnsAsync(true); // Act var result = await GetHandler().Handle(command, default); // Assert result.Error.Should().Be(ErrorType.Duplicating.ToString()); }
public void Update(UserUpdateCommand command) { var targetId = new UserId(command.Id); var user = userRepository.Find(targetId); if (user == null) { throw new UserNotFoundException(targetId); } var name = command.Name; if (name != null) { var newUserName = new UserName(name); user.ChangeName(newUserName); if (userService.Exists(user)) { throw new CanNotRegisterUserException(user, "이미 등록된 사용자임"); } } var mailAddress = command.MailAddress; if (mailAddress != null) { var newMailAddress = new MailAddress(mailAddress); user.ChangeMailAddress(newMailAddress); } userRepository.Save(user); }
static void Main(string[] args) { var repository = new InMemoryUserRepository(); var userService = new UserService(repository); var userApplicationService = new UserApplicationService(repository, userService); var id = "test-id"; var user = new User(new UserId(id), new UserName("test-user")); repository.Save(user); // ユーザ名変更だけを行うように var updateNameCommand = new UserUpdateCommand(id) { Name = "naruse" }; userApplicationService.Update(updateNameCommand); // メールアドレス変更だけを行うように var updateMailAddressCommand = new UserUpdateCommand(id) { MailAddress = "*****@*****.**" }; userApplicationService.Update(updateMailAddressCommand); }
public void Update(UserUpdateCommand command) { var targetId = new UserId(command.Id); var user = userRepository.Find(targetId); if (user == null) { throw new UserNotFoundException(targetId); } var name = command.Name; if (name != null) { // 重複確認を行うコード var newUserName = new UserName(name); var duplicatedUser = userRepository.Find(newUserName); if (duplicatedUser != null) { throw new CanNotRegisterUserException(user, "ユーザは既に存在しています。"); } user.ChangeName(newUserName); } var mailAddress = command.MailAddress; if (mailAddress != null) { var newMailAddress = new MailAddress(mailAddress); user.ChangeMailAddress(newMailAddress); } userRepository.Save(user); }
public async Task <ICommandResult> Handle(UserUpdateCommand command) { //FFV command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, HttpStatusCode.BadRequest, command.Notifications)); } var _verify = await _userRepository.FindById(command.Id); if (_verify == null) { return(new GenericCommandResult(false, HttpStatusCode.NotFound, "Não localizado na base")); } User _entity = new User(); _entity.Id = command.Id; _entity.Login = _verify.Login; _entity.Password = command.Password; _entity.Name = command.Name; _entity.Role = (!string.IsNullOrEmpty(command.Role)) ? command.Role : "Administrator"; var _result = await _cudRepository.Update(_entity); //retorna o resultado if (!_result) { return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result)); } return(new GenericCommandResult(true, HttpStatusCode.OK, _result)); }
public Task <Respond> HandleAsync(UserUpdateCommand c) { var ver = c.Version; c.Version = ver + 1; return(TryUpdateAsync(conn => conn.UpdateAsync(c.UserUpdate, new { c.Id, ver }, Tables.UserTable))); }
public async Task <ResponseViewModel> UpdateAsync(UserUpdateRequestViewModel request) { using (_unitOfWork) { // Inicia a transação _unitOfWork.BeginTransaction(); // Atualiza o Perfil ProfileUpdateCommand profileUpdateCommand = new ProfileUpdateCommand(Convert.ToInt32(request.IdType), request.GuidProfile, request.Avatar, request.CpfCnpj, request.Address); ResponseCommand profileUpdateResponse = await _mediator.Send(profileUpdateCommand, CancellationToken.None).ConfigureAwait(true); if (!profileUpdateResponse.Success) { return(new ResponseViewModel(false, profileUpdateResponse.Object)); } // Atualiza o Usuário UserUpdateCommand userUpdateCommand = new UserUpdateCommand(request.GuidUser, request.Name, request.Email); ResponseCommand userUpdateResponse = await _mediator.Send(userUpdateCommand, CancellationToken.None).ConfigureAwait(true); if (!userUpdateResponse.Success) { return(new ResponseViewModel(false, userUpdateResponse.Object)); } // Comita e Retorna _unitOfWork.CommitTransaction(); return(new ResponseViewModel(true, "User updated")); } }
public void Handle(UserUpdateCommand command) { var targetId = new UserId(command.Id); var user = _userRepository.Find(targetId); if (user == null) { // throw new UserNotFoundException(targetId); throw new Exception(); } var name = command.Name; if (name != null) { var newUserName = new UserName(name); user.ChangeName(newUserName); if (_userService.Exists(user)) { // // throw new CanNotRegisterUserException(user, "ユーザーは既に存在しています。"); throw new Exception(); } } var mailAddress = command.MailAddress; if (mailAddress != null) { var newMailAddress = new MailAddress(mailAddress); user.ChangeMailAddress(newMailAddress); } _userRepository.Save(user); }
public async Task <IActionResult> UpdateUser(Guid id, [FromBody] UserUpdateCommand command) { command.Id = id; await this._mediator.Send(command); return(this.Ok(new { })); }
public void Update(UserUpdateCommand command) { var targetId = new UserId(command.Id); var user = userRepository.Find(targetId); if (user == null) { throw new UserNotFoundException(targetId); } var name = command.Name; if (name != null) { // 사용자명의 중복은 허용된다 var newUserName = new UserName(name); user.ChangeName(newUserName); } var mailAddress = command.MailAddress; if (mailAddress != null) { // 대신 이메일 주소의 중복이 금지된다 var newMailAddress = new MailAddress(mailAddress); var duplicatedUser = userRepository.Find(newMailAddress); if (duplicatedUser != null) { throw new CanNotRegisterUserException(newMailAddress); } user.ChangeMailAddress(newMailAddress); } userRepository.Save(user); }
public async Task <ICommandResult> Handle(UserUpdateCommand command) { //FFV command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, HttpStatusCode.BadRequest, command.Notifications)); } var _verify = await _userRepository.GetById(command.Id); if (_verify == null) { return(new GenericCommandResult(false, HttpStatusCode.NotFound, _verify)); } User _entity = new User(); _entity.Id = command.Id; _entity.Login = command.Login; _entity.Password = command.Password; _entity.Name = command.Name; _entity.Role = command.Role.ToString(); var _result = await _contextRepository.Update(_entity); //retorna o resultado if (!_result) { return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result)); } return(new GenericCommandResult(true, HttpStatusCode.OK, _result)); }
public async Task <IActionResult> Put(int userId) { var userDeleteCommand = new UserUpdateCommand(userId); await _commandDispather.Execute(userDeleteCommand); return(NoContent()); }
public async Task <IActionResult> PutProduct(int id, UserRequestCommand userRequest) { var command = new UserUpdateCommand(userRequest, id); var result = await _mediator.Send(command); return(result != null ? (IActionResult)Ok(result) : NotFound(string.Format(ModelConstants.PropertyNotFoundFromController, "იუზერი"))); }
/// <summary> /// Constructor for UserViewModel /// </summary> public UserViewModel() { _DefaultUser = new User(); _DefaultMarket = new MarketTrade(); UpdateCommand = new UserUpdateCommand(this); AuthenticateCommand = new AuthenticateCommand(this); LimitBuyCommand = new LimitBuyCommand(this); LimitSellCommand = new LimitSellCommand(this); }
public async Task <bool> UpdateAsync(UserUpdateCommand command) { var user = Mapper.Map <User>(command); user.SetPassword(command.Password, _encrypter); var updateResult = await _userRepository.UpdateAsync(user); return(updateResult); }
public void TranslateExternalUpdateCommandToAkkaMessage(HTTPSourcedCommand cmdExternal) { UserState cs; if (ExtractStateObject(cmdExternal, out cs)) { UserUpdateCommand updateCmd = new UserUpdateCommand(cs, cmdExternal.User, cmdExternal.ConnectionId); SendTo.Tell(updateCmd, ReplyTo); } }
public void Update(UserUpdateCommand request) { const string sql = "" + " UPDATE FgjCqrsUser" + " SET Name = @Name" + " , Email = @Email" + " WHERE Guid = @Guid"; _unitOfWork.Connection.Execute(sql, request, _unitOfWork?.Transaction); }
public IHttpActionResult Update(UserUpdateCommand user) { var validator = user.Validation(); if (!validator.IsValid) { return(HandleValidationFailure(validator.Errors)); } return(HandleCallback(() => UserAppService.Update(user))); }
public ActionResult UpdateForm(User user) { Require.NotNull(user, "user"); UserUpdateCommand userUpdateCommand = new UserUpdateCommand(user); IList <string> roles = Roles.AllRoles; IList <UserGroup> financialBrokerPools = UserGroupService.GetAll(); UserUpdateViewModel userUpdateViewModel = new UserUpdateViewModel(user, roles, financialBrokerPools, userUpdateCommand); return(View("Update", userUpdateViewModel)); }
public async Task <ActionResult> Put(UserUpdateCommand command) { var result = await _appService.UpdateAsync(command); if (_notificationProvider.HasErrors()) { return(BadRequest(new FailedResult("Bad Request", _notificationProvider.GetErrors()))); } return(Ok(result)); }
public IActionResult Index(UserUpdateCommand command) { if (!ModelState.IsValid) { // OnActionExecutedでModelStateをTempDataに保存する return(RedirectToAction()); } // 仮 return(Content("保存しました!")); }
public IHttpActionResult Update(UserUpdateCommand command) { var validator = command.Validate(_service); if (!validator.IsValid) { return(HandleValidationFailure(validator.Errors)); } return(HandleCallback(_service.Update(command))); }
private void PostUpdateHandler(UserUpdateCommand c) { // Update updatable fields _ActorState.Update(c.UserStateData); AutoSaveSnapshot(false); _logger.Debug($"User's :{c.User} update command recorded for User id:{_ActorState.Id}."); // Notify interested actors on the update NotifyCommandEventSubscribers(new UserUpdateRecordedEvent(Sender, c, c.User, c.ConnectionId)); }
public void Update(UserUpdateCommand command) { this.FirstName = command.FirstName; this.LastName = command.LastName; this.DateOfBirth = command.DateOfBirth; this.UserName = command.UserName; this.Email = command.Email; this.PhoneNumber = command.PhoneNumber; this.NormalizedEmail = this.Email.ToUpper(); //this.PasswordHash = new PasswordHasher<ApplicationUser>().HashPassword(this, command.Password); //todo: set other values }
public async Task <ObjectResult> PutAsync(UserUpdateCommand command) { ValidationResult resultadoValidacao = command.Validate(); if (!resultadoValidacao.IsValid) { throw new Exception("Erro de validação!"); } await _userService.UpdateAsync(command); return(StatusCode(201, command)); }