Exemple #1
0
        public async Task <bool> newPubl(string foto, string name, THomeViewModel model)
        {
            if (model.TextoPublicacion == null)
            {
                return(false);
            }

            if (model != null)
            {
                var publ = new PublicacionViewModel
                {
                    UserId          = name,
                    HoraPublicacion = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt"),
                    Texto           = model.TextoPublicacion,
                    Foto            = foto
                };
                var dto   = _mapper.Map <PublicacionDTO>(publ);
                var final = _mapper.Map <Publicaciones>(dto);
                await Add(final);

                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
        public async Task <IActionResult> addPublicacion(THomeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueName = null;
                if (model.FotoPublicacion != null)
                {
                    var folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "imgs/publ");
                    uniqueName = Guid.NewGuid().ToString() + "_" + model.FotoPublicacion.FileName;
                    var filePath = Path.Combine(folderPath, uniqueName);

                    if (filePath != null)
                    {
                        var stream = new FileStream(filePath, mode: FileMode.Create);
                        model.FotoPublicacion.CopyTo(stream);
                        stream.Flush();
                        stream.Close();
                    }
                }
                if (await _repository.newPubl(uniqueName, User.Identity.Name, model))
                {
                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }

            return(View(model));
        }
Exemple #3
0
        public async Task <THomeViewModel> Home(string name)
        {
            var info = await _context.Usuario.FirstOrDefaultAsync(c => c.UserName == name);

            var filtro2 = new List <string>();
            var filtro3 = new List <string>();

            filtro2 = await _context.Amigos.Where(c => c.Amigo == info.UserName).Select(s => s.Usuario).ToListAsync();

            filtro3 = await _context.Amigos.Where(c => c.Usuario == info.UserName).Select(s => s.Usuario).ToListAsync();

            var Amigos = await _context.Amigos.Where(c => c.Usuario == info.UserName && c.Amigo != info.UserName).ToListAsync();

            var publicacions = await _context.Publicaciones.Where(c => filtro2.Contains(c.UserId) || filtro3.Contains(c.UserId)).OrderByDescending(a => a.Id).ToListAsync();

            if (publicacions.Count == 0)
            {
                publicacions = await _context.Publicaciones.Where(c => c.UserId == name).ToListAsync();
            }
            var viewModel = new THomeViewModel
            {
                Amigos        = Amigos,
                Publicaciones = publicacions,
                Usuario       = name,
                FotoUsuario   = info.Foto
            };

            return(viewModel);
        }
        public async Task <THomeViewModel> Index(string name)
        {
            var all = await getAll();

            var users = new THomeViewModel
            {
                Usuarios = all,
                Usuario  = name
            };

            return(users);
        }