예제 #1
0
        public async Task <ActionResult <Users> > PostUser(Users user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("obtenerUser", new { id = user.Id }, user));
        }
예제 #2
0
        public async Task <ActionResult <Product> > PostTodoItem(Product product)
        {
            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("obtenerProdu", new { id = product.Id }, product));
        }
예제 #3
0
        public async Task <ActionResult> probando([FromForm] CrearProducto model)
        {
            if (model.File != null)
            {
                var a        = _env.WebRootPath;
                var fileName = Path.GetFileName(model.File.FileName);
                var filePath = Path.Combine(_env.WebRootPath, "Assets\\Images", fileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))  {
                    await model.File.CopyToAsync(fileStream);
                }
                Product pr = new Product();
                pr.Name        = model.Name;
                pr.Category    = model.Category;
                pr.Price       = model.Price;
                pr.Description = model.Description;
                pr.Photo       = filePath;
                pr.Quantity    = model.Quantity;
                pr.Color       = model.Color;
                _context.Add(pr);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }