public void UpdateProfile(UpdateProfileCommand command) { EnsureIsValid(command); EnsureIsSecure(command, new UserCommandValidator(Identity)); try { var user = _deps.Users.Find(command.UserId); if (user == null || user.Deleted) { throw NotFound.ExceptionFor <User>(command.UserId); } if (user.Profile == null) { throw NotFound.ExceptionFor <UserProfile>(command.UserId); } Mapper.Map(command, user.Profile); //TODO: When phone number is changing should validate sms code if (!string.IsNullOrEmpty(command.PhoneNumber)) { user.Profile.PhoneNumberConfirmed = true; } _deps.UserProfiles.Update(user.Profile); Commit(); Publish(new UserProfileUpdated(Operation.Id, user.Profile.ToModel <UserProfile, UserProfileModel>())); } catch (ServiceException) { throw; } catch (Exception ex) { throw new ServiceException("Can't update profile.", ex); } }
public async Task <bool> UpdateProfileAsync(UpdateProfileCommand command) { var user = await _userManager.FindByIdAsync(command.Id.ToString()); user.Name = command.Name; user.Bio = command.Bio; user.Company = command.Company; user.JobTitle = command.JobTitle; user.Url = command.Url; user.PhoneNumber = command.PhoneNumber; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { var claims = await _userManager.GetClaimsAsync(user); if (!user.Name.Equals(command.Name)) { await AddOrUpdateClaimAsync(user, claims, "name", user.Name); } return(true); } foreach (var error in result.Errors) { await _bus.RaiseEvent(new DomainNotification(result.ToString(), error.Description)); } return(false); }
public void Constructor_GiveValidArguments_PropertiesAreSet() { var updateProfileCommand = new UpdateProfileCommand("first-name", "last-name"); Assert.Equal("first-name", updateProfileCommand.FirstName); Assert.Equal("last-name", updateProfileCommand.LastName); }
public override async Task <UpdateProfileResponse> UpdateProfile(UpdateProfileRequest request, ServerCallContext context) { var updateProfileModel = new UpdateProfileModel { ProfileId = Guid.Parse(request.ProfileId), FirstName = request.FirstName, LastName = request.LastName, PhotoThumbUrl = request.PhotoThumbUrl }; var updateProfileCommand = new UpdateProfileCommand(updateProfileModel); var result = await _commandBus.TransactionSendAsync(updateProfileCommand); if (result.IsOk) { var response = result.Value as dynamic; return(new UpdateProfileResponse { ProfileId = response.ProfileId, FirstName = response.FirstName, LastName = response.LastName, PhotoThumbUrl = response.PhotoThumbUrl, }); } var statusCode = (StatusCode)result.StatusCode; throw new RpcException(new Status(statusCode, result.Value?.ToString())); }
public async Task <IActionResult> Index(UpdateProfileCommand command) { try { var phoneNumberChanged = await Mediator.Send(command); if (!phoneNumberChanged) { return(RedirectToAction("Index")); } var result = await _identityService.SendConfirmationSmsAsync(CurrentUserService.UserId, command.PhoneNumber); return(result ? RedirectToAction("ConfirmPhoneNumber") : throw new Exception("خطا!")); } catch (ValidationException exception) { foreach (var(key, value) in exception.Errors) { ModelState.AddModelError(key, value[0]); } ViewBag.ProvinceId = new SelectList(await Mediator.Send(new GetProvincesQuery()), "Id", "Title"); return(View(_mapper.Map <UpdateProfileCommand, UserProfileVm>(command))); } }
public async Task <bool> UpdateProfileAsync(UpdateProfileCommand command) { var user = await _userManager.FindByNameAsync(command.Username); _userFactory.UpdateProfile(command, user); var claims = await _userManager.GetClaimsAsync(user); await AddOrUpdateClaim(claims, user, JwtClaimTypes.GivenName, command.Name); await AddOrUpdateClaim(claims, user, JwtClaimTypes.WebSite, command.Url); if (command.Birthdate.HasValue) { await AddOrUpdateClaim(claims, user, JwtClaimTypes.BirthDate, command.Birthdate.Value.ToString(CultureInfo.CurrentCulture)); } await AddOrUpdateClaim(claims, user, "company", command.Company); await AddOrUpdateClaim(claims, user, "job_title", command.JobTitle); await AddOrUpdateClaim(claims, user, "bio", command.Bio); await AddOrUpdateClaim(claims, user, "social_number", command.SocialNumber); var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(true); } foreach (var error in result.Errors) { await _bus.RaiseEvent(new DomainNotification(result.ToString(), error.Description)); } return(false); }
public async Task <APIResult> UpdateProfile([FromBody] UpdateProfileCommand command) { var rs = await mediator.Send(command); return(new APIResult() { Result = rs }); }
public async Task <IActionResult> Update( [FromServices] IMediator mediator, [FromBody] ProfileDto profileDto) { var query = new UpdateProfileCommand(profileDto); var data = await mediator.Send(query); return(new JsonResult(data.Profile)); }
public async Task <IActionResult> UpdateUser([FromBody] UpdateProfileRequest request, CancellationToken cancellationToken) { var command = UpdateProfileCommand.FromRequest(_currentUserId, request); var result = await _mediator.Send(command, cancellationToken); return(result.IsSuccess ? Ok() : result.ReturnErrorResponse()); }
public void UpdateProfile(UpdateProfileCommand command, CustomStringIdentity @string) { @string.Name = command.Name; @string.PhoneNumber = command.PhoneNumber; @string.Bio = command.Bio; @string.Company = command.Company; @string.JobTitle = command.JobTitle; @string.Url = command.Url; @string.SocialNumber = command.SocialNumber; @string.Birthdate = command.Birthdate; }
public IActionResult SetVoiceSecretPhrase(int userid, [FromBody] string phrase) { var profile = new UserProfile() { UserId = userid, VoiceSecretPhrase = phrase }; var command = new UpdateProfileCommand(profile, isPatch: true); return(ProcessCommand(command)); }
public IActionResult SetVoiceProfileId(int userid, [FromBody] Guid id) { var profile = new UserProfile() { UserId = userid, VoiceProfileId = id }; var command = new UpdateProfileCommand(profile, isPatch: true); return(ProcessCommand(command)); }
public async Task <IActionResult> UpdateProfile(UpdateProfileCommand updateProfileCommand) { var result = await Mediator.Send(updateProfileCommand); if (result.Success == false) { return(result.ApiResult); } return(NoContent()); }
public async Task <ActionResult <GetProfileDto> > Update([FromRoute] int id, [FromBody] UpdateProfileDto profile) { var command = new UpdateProfileCommand(id, profile); var result = await Mediator.Send(command); if (result == null) { return(NotFound()); } return(Ok(result)); }
public async Task <IActionResult> UpdateProfile([FromBody] UpdateProfileModel model) { var updateCommand = new UpdateProfileCommand { FirstName = model.FirstName, LastName = model.LastName, UserId = HttpContext.GetLoggedUserId() }; var response = await _mediator.Send(updateCommand); return(Ok(BaseResponse.Ok(response))); }
public async Task <Result <long> > Handle(UpdateProfileCommand request, CancellationToken cancellationToken) { var entity = this.repository.GetProfileById(request.ProfileId); if (entity is null) { return(Results.Fail("Profile doesn't exist.")); } this.mapper.Map(request.Profile, entity); this.repository.Update(entity); return(Results.Ok(entity.Id)); }
public async Task <ResultWithError <ErrorData> > Handle(UpdateProfileCommand request, CancellationToken cancellationToken) { var result = await this.Process(request, cancellationToken); var dbResult = await this._userRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); if (!dbResult) { return(ResultWithError.Fail(new ErrorData( ErrorCodes.SavingChanges, "Failed To Save Database"))); } return(result); }
public async Task <IActionResult> UpdateProfile([FromBody] UserToUpdateRequest user, CancellationToken cancellationToken) { var identifier = User.GetUserId(); var command = new UpdateProfileCommand { User = user, UserId = identifier }; var updatedUser = await _mediator.Send(command, cancellationToken); return(Ok(updatedUser)); }
private void UpdateCommand_Execute() { try { var command = new UpdateProfileCommand { Id = _id, Profile = _profile, Account = _account, Password = _password }; _updateProfileHandler.Execute(command); _navigation.Navigate(typeof(MainViewModel), _id); } catch (Exception ex) { //Log.Error(string.Format("Failed to update profile details {0}", _profile), ex); } }
public void EditProfile(Profile profile) { bool exists = IsUsernamePresentQuery <bool> .Execute(new { profile.Username }); if (exists) { UpdateProfileCommand.Execute(new { profile.Username, profile.FirstName, profile.LastName, profile.Email, profile.Mobile, profile.Description }); } }
public EmptyResult UpdateProfile(UpdateProfileCommand command) { if (!profileRepository.ProfileExistsForOrganizationUser(command.OrganizationUserId, command.OrganizationId)) { return(new Result <int>(ProfileServiceErrors.InvalidOrganizationUserId())); } var(invalidProfileParametersFound, invalidProfileParametersCollection) = ValidateProfileParameters(command.ProfileValues.ToList <IProfileValueModel>()); if (invalidProfileParametersFound) { return(new Result <int>(invalidProfileParametersCollection)); } profileRepository.UpdateProfile(command); return(new EmptyResult()); }
public override async Task <ProfileReply> UpdateProfile(UpdateProfileRequest request, ServerCallContext context) { var command = new UpdateProfileCommand(request.Id.ToAccountId(), request.FirstName, request.LastName, request.Nickname, request.Bio, request.DateOfBirth.ToDateTime(), request.Gender.FromGrpc(), request.Language, request.Timezone, request.CountryCode, request.CityName ?? string.Empty); await _mediator.Send(command, context.CancellationToken); var data = await _mediator.Send(new GetAccountByIdQuery(request.Id.ToAccountId())); if (data is not null) { return(data.ToGatewayProfileReply()); } context.Status = new Status(StatusCode.NotFound, ElwarkExceptionCodes.AccountNotFound); return(new ProfileReply()); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] UpdateProfileCommand command) { try { command.Id = id; if (!ModelState.IsValid) { return(base.BadRequest(ModelState)); } var result = await _mediator.Send <UpdateProfileCommandResult>(command); return(base.Ok(result)); } catch (NotFoundException) { return(base.NotFound()); } }
public async Task <ActionResult <GeekProfileResponse> > UpdatePersonalProfile([FromBody] GeekProfileModel model) { var user = await this.mediator.Send(new GetCurrentUserQuery()); var userProfile = await this.mediator.Send(new GetProfileByUserQuery(user.Id)); var command = new UpdateProfileCommand(model, userProfile.Id); var result = await this.mediator.Send(command); if (result.IsFailed) { return(this.UnprocessableEntity(result)); } var query = new GetProfileByIdQuery(result.Value); var profile = await this.mediator.Send(query); return(this.Ok(profile)); }
public void UpdateProfile(UpdateProfileCommand command) { using (var transaction = this.context.Database.BeginTransaction()) { //var currentProfile = GetProfileEntity(updateProfile.ProfileId); var currentProfile = GetProfileEntityByOrganizationUserId(command.OrganizationUserId, command.OrganizationId); //Removes all existing ProfileValues associated with the profile context.ProfileValues.RemoveRange(currentProfile.ProfileValues); //Creates the new entries from the request var newProfileValues = mapper.Map <List <ProfileValueEntity> >(command.ProfileValues).ToList(); currentProfile.ProfileValues = newProfileValues; currentProfile.UpdatedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); this.context.SaveChanges(); transaction.Commit(); } }
public ActionResult UpdateProfile(UpdateProfileCommand command) { if (!ModelState.IsValid) { return(View("UpdateProfile", command)); } var picture = PreparePicture(command.Picture.HttpPostedFileBase, MembershipPicturePath); command.UserId = CurrentUser.Id; command.Picture = picture; var result = _commandBus.Send(command); if (!result.Success) { return(JsonMessage(result)); } SavePicture(picture, MembershipPicturePath); return(JsonMessage(result)); }
private async Task <ResultWithError <ErrorData> > Process(UpdateProfileCommand request, CancellationToken cancellationToken) { var currentUserMaybe = this._currentUserService.CurrentUser; if (currentUserMaybe.HasNoValue) { return(ResultWithError.Fail(new ErrorData(ErrorCodes.UserNotFound))); } var userMaybe = await this._userRepository.Find(currentUserMaybe.Value.UserId, cancellationToken); if (userMaybe.HasNoValue) { return(ResultWithError.Fail(new ErrorData(ErrorCodes.UserNotFound))); } var user = userMaybe.Value; user.UpdateProfile(request.FirstName, request.LastName, request.EmailAddress); this._userRepository.Update(user); return(ResultWithError.Ok <ErrorData>()); }
public override Task <UpdateProfile.Types.Response> UpdateProfile(UpdateProfile.Types.Request request, ServerCallContext context) { var model = new UpdateProfileCommand { OrganizationUserId = request.OrganizationUserId.Value, OrganizationId = request.OrganizationId.Value, ProfileId = request.ProfileId.Value, ProfileValues = request.ProfileValuesListView?.Select(pv => new ProfileValueUpdateModel { Value = pv.Value, ProfileParameterId = pv.ProfileParameterId.Value }).ToList() }; var result = this.profileService.UpdateProfile(model); if (result.IsFailure) { HandleResultFailure(context, result); return(null); } return(Task.FromResult(new UpdateProfile.Types.Response())); }
public void EditProfile(Profile profile) { bool exists = IsUsernamePresentQuery <bool> .Execute(new { profile.Username }); if (exists) { UpdateProfileCommand.Execute(new { profile.Id, profile.Username, profile.FirstName, profile.LastName, profile.Email, profile.Mobile, profile.Description }); var hash = HashObject(profile).ToHexString(); Connector connector = new Connector(credentialManager.PublicKey, credentialManager.PrivateKey); connector.Call("editProfileHash", profile.Id, hash); } }
public MainViewModel(User user, Window window, IRailwayServiceProxyCreationFacade proxyCreationFacade, ILogging logger, IPrimaryEntityCommandManagement commandManager) { User = user; ProxyCreationFacade = proxyCreationFacade; Logger = logger; CommandManager = commandManager; Window = window; RefreshUsersCommand = new RefreshUsersCommand(this); UpdateProfileCommand = new UpdateProfileCommand(this); RefreshRoadsCommand = new RefreshRoadsCommand(this); RefreshStationsCommand = new RefreshStationsCommand(this); RefreshTracksCommand = new RefreshTracksCommand(this); RefreshPlacesCommand = new RefreshPlacesCommand(this); DeleteRoadCommand = new DeleteRoadCommand(this, commandManager); DeleteStationCommand = new DeleteStationCommand(this); DeleteTrackCommand = new DeleteTrackCommand(this); DeletePlaceCommand = new DeletePlaceCommand(this); CloneRoadCommand = new CloneRoadCommand(this, commandManager); LogoutCommand = new LogoutCommand(this); UndoCommand = new UndoCommand(commandManager); RedoCommand = new RedoCommand(commandManager); OpenAddUserDialogCommand = new OpenAddUserDialogCommand(this); OpenAddRoadDialogCommand = new OpenAddRoadDialogCommand(this); OpenChangeRoadDialogCommand = new OpenChangeRoadDialogCommand(this); OpenAddTrackDialogCommand = new OpenAddTrackDialogCommand(this); OpenChangeTrackDialogCommand = new OpenChangeTrackDialogCommand(this); OpenAddPlaceDialogCommand = new OpenAddPlaceDialogCommand(this); OpenChangePlaceDialogCommand = new OpenChangePlaceDialogCommand(this); OpenAddStationDialogCommand = new OpenAddStationDialogCommand(this); OpenChangeStationDialogCommand = new OpenChangeStationDialogCommand(this); SearchRoadsCommand = new SearchRoadsCommand(this); ClearSearchCommand = new ClearSearchCommand(this); RoadSearch = new RoadSearchModel(); ConnectToAllServices(); RefreshAllLists(); }