예제 #1
0
        public async Task <JsonResult> FotoPerfil(IFormFile formFile)
        {
            string photoName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpeg";
            bool   exito     = false;
            var    imagePath = "wwwroot/images/" + photoName;

            if (formFile != null)
            {
                using (var stream = new FileStream(imagePath, FileMode.Create))
                {
                    formFile.CopyTo(stream);
                }

                var imagePathBd   = "/images/" + photoName;
                var userPrincipal = this.User;
                var currentUser   = await _userManager.GetUserAsync(userPrincipal);

                var user = new ApplicationUser
                {
                    Id     = currentUser.Id,
                    Avatar = imagePathBd
                };

                //dao.UpdateProfilePicture(avatar);
                await _fotoRepository.UpdateProfilePicture(user);

                return(Json(imagePathBd));
            }
            return(Json(exito));
        }