Пример #1
0
        private async Task UploadFiles(InputFileChangeEventArgs e)
        {
            file = e.File;
            if (file != null)
            {
                var format    = "image/png";
                var imageFile = await e.File.RequestImageFileAsync(format, 250, 250);

                var buffer = new byte[imageFile.Size];
                await imageFile.OpenReadStream().ReadAsync(buffer);

                ImageDataUrl = $"data:{format};base64,{Convert.ToBase64String(buffer)}";
                var request = new UpdateProfilePictureRequest()
                {
                    ProfilePictureDataUrl = ImageDataUrl
                };
                var result = await _accountManager.UpdateProfilePictureAsync(request, UserId);

                if (result.Succeeded)
                {
                    _navigationManager.NavigateTo("/account", true);
                }
                else
                {
                    foreach (var error in result.Messages)
                    {
                        _snackBar.Add(error, Severity.Success);
                    }
                }
            }
        }
        private async Task UploadFiles(InputFileChangeEventArgs e)
        {
            file = e.File;
            if (file != null)
            {
                var extension = Path.GetExtension(file.Name);
                var fileName  = $"{UserId}-{Guid.NewGuid()}{extension}";
                var format    = "image/png";
                var imageFile = await e.File.RequestImageFileAsync(format, 400, 400);

                var buffer = new byte[imageFile.Size];
                await imageFile.OpenReadStream().ReadAsync(buffer);

                var request = new UpdateProfilePictureRequest()
                {
                    Data = buffer, FileName = fileName, Extension = extension, UploadType = Application.Enums.UploadType.ProfilePicture
                };
                var result = await _accountManager.UpdateProfilePictureAsync(request, UserId);

                if (result.Succeeded)
                {
                    await _localStorage.SetItemAsync("userImageURL", result.Data);

                    _navigationManager.NavigateTo("/account", true);
                }
                else
                {
                    foreach (var error in result.Messages)
                    {
                        _snackBar.Add(localizer[error], Severity.Error);
                    }
                }
            }
        }
        private async Task DeleteAsync()
        {
            var parameters = new DialogParameters();

            parameters.Add("ContentText", $"Do you want to delete the profile picture of {profileModel.Email} ?");
            var options = new DialogOptions()
            {
                CloseButton = true, MaxWidth = MaxWidth.Small, FullWidth = true, DisableBackdropClick = true
            };
            var dialog = _dialogService.Show <Shared.Dialogs.DeleteConfirmation>("Delete", parameters, options);
            var result = await dialog.Result;

            if (!result.Cancelled)
            {
                var request = new UpdateProfilePictureRequest()
                {
                    ProfilePictureDataUrl = string.Empty
                };
                var data = await _accountManager.UpdateProfilePictureAsync(request, UserId);

                if (data.Succeeded)
                {
                    ImageDataUrl = string.Empty;
                    _navigationManager.NavigateTo("/account", true);
                }
                else
                {
                    foreach (var error in data.Messages)
                    {
                        _snackBar.Add(error, Severity.Success);
                    }
                }
            }
        }
Пример #4
0
        public async Task <IResult> UpdateProfilePictureAsync(UpdateProfilePictureRequest request, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Result.Fail("User Not Found"));
            }
            user.ProfilePictureDataUrl = request.ProfilePictureDataUrl;
            var identityResult = await _userManager.UpdateAsync(user);

            var errors = identityResult.Errors.Select(e => e.Description).ToList();

            return(identityResult.Succeeded ? Result.Success() : Result.Fail(errors));
        }
        public async Task <IResult <string> > UpdateProfilePictureAsync(UpdateProfilePictureRequest request, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(await Result <string> .FailAsync(message : _localizer["User Not Found"]));
            }
            var filePath = _uploadService.UploadAsync(request);

            user.ProfilePictureDataUrl = filePath;
            var identityResult = await _userManager.UpdateAsync(user);

            var errors = identityResult.Errors.Select(e => _localizer[e.Description].ToString()).ToList();

            return(identityResult.Succeeded ? await Result <string> .SuccessAsync(data : filePath) : await Result <string> .FailAsync(errors));
        }
        public IActionResult UpdateProfilePicture([FromBody] UpdateProfilePictureRequest request)
        {
            var user = this.GetUserAuthorize();

            if (user == null)
            {
                return(Unauthorized());
            }
            var success = UserLogic.Instance.UpdateProfilePicture(user, request.Content);

            if (success)
            {
                return(Ok());
            }
            else
            {
                return(Forbid());
            }
        }
Пример #7
0
        private async Task DeleteAsync()
        {
            var request = new UpdateProfilePictureRequest()
            {
                ProfilePictureDataUrl = string.Empty
            };
            var result = await _accountManager.UpdateProfilePictureAsync(request, UserId);

            if (result.Succeeded)
            {
                _navigationManager.NavigateTo("/account", true);
            }
            else
            {
                foreach (var error in result.Messages)
                {
                    _snackBar.Add(error, Severity.Success);
                }
            }
        }
Пример #8
0
        public async Task <IActionResult> UpdateProfilePicture(
            [FromForm] UpdateProfilePictureRequest request)
        {
            try
            {
                var result =
                    await mUsersService.UpdateThumbnail(request.picture, ClaimsExtractor.GetUserIdClaim(User.Claims));

                return(Ok(new ResponseApiModel <UpdateProfilePictureResponse>
                {
                    IsSuccessfull = true,
                    Response = result
                }));
            }
            catch (InvalidDataException ex)
            {
                return(BadRequest(new ResponseApiModel <bool>
                {
                    IsSuccessfull = false,
                    ErrorMessage = ex.Message
                }));
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound(new ResponseApiModel <bool>
                {
                    IsSuccessfull = false,
                    ErrorMessage = ex.Message
                }));
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiModel <bool>
                {
                    IsSuccessfull = false
                }));
            }
        }
        public async Task <IResult <string> > UpdateProfilePictureAsync(UpdateProfilePictureRequest request, string userId)
        {
            var response = await _httpClient.PostAsJsonAsync(Routes.AccountEndpoint.GetProfilePicture(userId), request);

            return(await response.ToResult <string>());
        }
Пример #10
0
 public async Task <IActionResult> UpdateProfilePictureAsync(UpdateProfilePictureRequest request)
 {
     return(Ok(await _accountService.UpdateProfilePictureAsync(request, _currentUser.UserId)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateProfilePictureCommand" /> class.
 /// </summary>
 /// <param name="eventId">The multicode identifier.</param>
 /// <param name="Request">The request.</param>
 public UpdateProfilePictureCommand(int profilePictureId, UpdateProfilePictureRequest request)
 {
     Id      = profilePictureId;
     Request = request;
 }