//detalles del usuario tener encuenta la consulta a la bd
        public async Task <IActionResult> AddContent(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _dataContext.Users.FindAsync(id.ToString());

            if (user == null)
            {
                return(NotFound());
            }

            //var userInDB = await _userHelper.GetUserByEmailAsync(user.ToString());
            //instanciamos la clase ContentViewModel que creamos en la carpeta models, para el modelo del contenido
            var model = new ContentViewModel
            {
                Date   = DateTime.Now,
                UserId = user.Id,
                //creamos una clase ICombosHelps para poder traer la lista de ContentTypes
                ContentTypes = _combosHelper.GetComboContentTypes(),
                Parks        = _combosHelper.GetComboParks()
            };

            return(View(model));
        }
        //agregar contenido al contents
        public async Task <IActionResult> AddContent()
        {
            var user = await _dataContext.Users
                       .Include(ct => ct.Contents)
                       .FirstOrDefaultAsync(u => u.UserName.ToLower().Equals(User.Identity.Name.ToLower()));

            /*var content = await _dataContext.Contents
             *                  .Include(c => c.User)
             *                  .Include(ct => ct.ContentType)
             *                  .FirstOrDefaultAsync();*/
            if (user == null)
            {
                return(NotFound());
            }

            //instanciamos la clase ContentViewModel que creamos en la carpeta models, para el modelo del contenido
            var model = new ContentViewModel
            {
                Date   = DateTime.Now,
                UserId = user.Id,
                //Id = content.Id,
                //creamos una clase ICombosHelps para poder traer la lista de ContentTypes
                ContentTypes = _combosHelper.GetComboContentTypes(),
                Parks        = _combosHelper.GetComboParks()
            };

            return(View(model));
        }
Exemplo n.º 3
0
 //editar publicaciones
 public ContentViewModel ToContentViewModel(Content content)
 {
     return(new ContentViewModel
     {
         Description = content.Description,
         Date = content.Date,
         ImageUrl = content.ImageUrl,
         Like = content.Like,
         DisLike = content.DisLike,
         Comments = content.Comments,
         User = content.User,
         ContentType = content.ContentType,
         Park = content.Park,
         //Location = content.Location,
         Id = content.Id,
         UserId = content.User.Id,
         ContentTypeId = content.ContentType.Id,
         ContentTypes = _combosHelper.GetComboContentTypes(),
         ParkId = content.Park.Id,
         Parks = _combosHelper.GetComboParks()
                 //LocationId = content.Location.Id
     });
 }