示例#1
0
        public static async Task ActualizaVisitas(FriensifyContext _context, PerfilViewModel usuario)
        {
            var resultado = _context.VisitasPerfil
                            .SingleOrDefault(u => u.IdUsuario == usuario.UserId &&
                                             u.Fecha.Date == DateTime.Now.Date);

            if (resultado == null)
            {
                var visitasPerfil = new VisitasPerfil
                {
                    IdUsuario = usuario.UserId,
                    Nombre    = usuario.NombreCompleto(),
                    Fecha     = DateTime.Now.Date,
                    Visitas   = 1
                };

                await _context.VisitasPerfil.AddAsync(visitasPerfil);

                await _context.SaveChangesAsync();
            }
            else
            {
                resultado.Visitas = resultado.Visitas + 1;
                await _context.SaveChangesAsync();
            }
        }
示例#2
0
        public async Task <IActionResult> CrearPost(PostInput post)
        {
            if (!ModelState.IsValid)
            {
                RedirectToAction("Ver", null);
            }


            if (!String.IsNullOrEmpty(post.ImagenPost?.FileName))
            {
                string wwwRoothRuta  = _hostEnvironment.WebRootPath;
                string nombreArchivo = Path.GetFileNameWithoutExtension(post.ImagenPost.FileName);
                string extension     = Path.GetExtension(post.ImagenPost.FileName);
                nombreArchivo  = nombreArchivo + DateTime.Now.ToString("yymmssfff") + extension;
                post.URLImagen = nombreArchivo;


                string ruta = Path.Combine(wwwRoothRuta + "\\img", nombreArchivo);
                using (var fileStream = new FileStream(ruta, FileMode.Create))
                {
                    await post.ImagenPost.CopyToAsync(fileStream);
                }
            }

            var postDB = new Post
            {
                Contenido = post.Contenido,
                Fecha     = DateTime.Now,
                URLImagen = post.URLImagen,
                UserId    = post.UserId
            };


            await _context.Post.AddAsync(postDB);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Ver"));
            // return Content($"userid: {post?.UserId} fecha: {postDB?.Fecha} contenido: {post?.Contenido} url: {post?.URLImagen}");
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            var usuario = await _context.Users.FirstOrDefaultAsync(id => id.UserName == userName);


            if (Input.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
                }
            }

            if (!String.IsNullOrEmpty(Input.ImagenArchivo?.FileName))
            {
                string wwwRoothRuta  = _hostEnvironment.WebRootPath;
                string nombreArchivo = Path.GetFileNameWithoutExtension(Input.ImagenArchivo.FileName);
                string extension     = Path.GetExtension(Input.ImagenArchivo.FileName);
                nombreArchivo      = nombreArchivo + DateTime.Now.ToString("yymmssfff") + extension;
                Input.ImagenPerfil = nombreArchivo;

                usuario.Nombre       = Input.Nombre;
                usuario.Apellido     = Input.Apellido;
                usuario.ImagenPerfil = Input.ImagenPerfil;
                usuario.Biografia    = Input.Biografia;
                await _context.SaveChangesAsync();

                string ruta = Path.Combine(wwwRoothRuta + "\\img", nombreArchivo);
                using (var fileStream = new FileStream(ruta, FileMode.Create))
                {
                    await Input.ImagenArchivo.CopyToAsync(fileStream);
                }
            }
            else
            {
                usuario.Nombre    = Input.Nombre;
                usuario.Apellido  = Input.Apellido;
                usuario.Biografia = Input.Biografia;
                await _context.SaveChangesAsync();
            }



            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Su perfil ha sido actualizado";
            return(RedirectToPage());
        }