Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateUser([FromBody] EditUserViewModel editedUser)
        {
            var user = await _myManager.GetCurrentUserAsync(HttpContext);

            user.FirstName = editedUser.FirstName;
            user.LastName  = editedUser.LastName;
            user.Handle    = editedUser.Handle;

            var result = await _myManager.UpdateUserAsync(user);



            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Upload()
        {
            try
            {
                var user = await _userManager.GetCurrentUserAsync(HttpContext);

                if (user == null)
                {
                    throw new Exception();
                }

                var bigImg = Request.Form.Files[0];
                var avatar = Request.Form.Files[1];

                var imgDbPath = await SaveFileReturnDbPath(bigImg);

                var avatarPath = await SaveFileReturnDbPath(avatar);

                if (imgDbPath != null && avatarPath != null)
                {
                    user.ThumbUrl = avatarPath;
                    user.ImageUrl = imgDbPath;
                    var result = await _userManager.UpdateUserAsync(user);

                    if (result.Succeeded)
                    {
                        return(Ok(new { ImageUrl = imgDbPath, ThumbUrl = avatarPath }));
                    }
                    else
                    {
                        return(StatusCode(500, "Error saving user data"));
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                return(StatusCode(500, "Internal Server error"));
            }
        }