Beispiel #1
0
        public async Task <JsonResult> GetUserProfile(string userId)
        {
            var user = await _userService.GetUserByIdAsync(userId);

            var result = new ViewModels.UserProfileViewModel(user);

            return(Json(result));
        }
Beispiel #2
0
        public async Task <ViewModels.UserProfileViewModel> UpdateProfile([FromBody] UserProfileViewModel model)
        {
            var currentUser = await _userService.GetUserByNameAsync(HttpContext.User.Identity.Name);

            if (!currentUser.Id.ToString().Equals(model.Id))
            {
                throw new InvalidOperationException("You can't edit other user profile info.");
            }

            var user = await _userProfileService.UpdateProfile(model);

            var result = new ViewModels.UserProfileViewModel(user);

            return(result);
        }
        public UserProfile(User CurrentUser)
        {
            InitializeComponent();
            uSer = CurrentUser;

            if (uSer.IconUrl != "")
            {
                image.Source = uSer.IconUrl;
            }
            else
            {
                uSer.IconUrl = "userdefault.png";
            }
            if (Thaydoimatkhau.IsChecked)
            {
                uSer.PassWord = thaydoi.Matkhaumoi;
            }
            uSer.Sex                      = "";
            frame.BindingContext          = uSer;
            matkhauthaydoi.BindingContext = thaydoi;
            BindingContext                = new ViewModels.UserProfileViewModel();
            takePhoto.Clicked            += async(sender, args) =>
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");

                    return;
                }

                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
                    Directory = "Sample",
                    Name      = "test.jpg"
                });


                if (file == null)
                {
                    return;
                }
                uSer.IconUrl = file.Path;
                //await DisplayAlert("File Location", file.Path, "OK");

                image.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return(stream);
                });
            };
            pickPhoto.Clicked += async(sender, args) =>
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");

                    return;
                }
                var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
                });


                if (file == null)
                {
                    return;
                }
                uSer.IconUrl = file.Path;
                image.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return(stream);
                });
            };
            deletePhoto.Clicked += async(sender, args) =>
            {
                image.Source = "userdefault.png";
                uSer.IconUrl = "userdefault.png";
            };
            luu.Clicked += async(sender, args) =>
            {
                if (thaydoi.Matkhaumoi is null || thaydoi.Xacnhanmatkhau is null)
                {
                    thaydoi.Matkhaumoi     = "";
                    thaydoi.Xacnhanmatkhau = "";
                }