Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Nombre")] Rol rol)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rol);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rol));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Descripcion,Precio,Foto,UsuarioId,Disponible")] Producto producto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(producto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(producto));
        }
        public async Task <IActionResult> Create([Bind("Id,UsuarioId,ProductoId")] ProductoFavorito productoFavorito)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productoFavorito);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductoId"] = new SelectList(_context.Producto, "Id", "Descripcion", productoFavorito.ProductoId);
            ViewData["UsuarioId"]  = new SelectList(_context.Usuario, "Id", "Apellido", productoFavorito.UsuarioId);
            return(View(productoFavorito));
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,CompradorId,VendedorId")] VendedorFavorito vendedorFavorito)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vendedorFavorito);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompradorId"] = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.CompradorId);
            ViewData["VendedorId"]  = new SelectList(_context.Usuario, "Id", "Apellido", vendedorFavorito.VendedorId);
            return(View(vendedorFavorito));
        }
        public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,Correo,Foto,TipoRolId,Emprendimiento,DescEmprendimiento")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                if (usuario.Foto == null)
                {
                    Stream foto   = _env.WebRootFileProvider.GetFileInfo("images/user.png").CreateReadStream();
                    var    stream = new MemoryStream();
                    await foto.CopyToAsync(stream);

                    usuario.Foto = stream.ToArray();
                }
                _context.Add(usuario);
                await _context.SaveChangesAsync();

                HomeController.setRegistro(true);
                return(RedirectToAction("Index", "Home"));
            }

            ViewData["TipoRolId"] = new SelectList(_context.Rol, "Id", "Nombre", usuario.TipoRolId);
            return(View(usuario));
        }