Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("id,nombre,foto,stock,precio,descripcion")] Productos productos)
        {
            if (id != productos.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductosExists(productos.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productos));
        }
Example #2
0
        public async Task <IActionResult> Create(Slide s)
        {
            string wwwRootPath = _iwebhost.WebRootPath;
            string namefile    = Path.GetFileNameWithoutExtension(s.NameFile.FileName);
            string extension   = Path.GetExtension(s.NameFile.FileName);

            s.foto = namefile = namefile + DateTime.Now.ToString("yymmssfff") + extension;
            string path = Path.Combine(wwwRootPath + "/img/Slide/", namefile);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                await s.NameFile.CopyToAsync(fileStream);
            }

            _context.slides.Add(s);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }