public async Task <IActionResult> PutCategory(long id, [Bind("Name")] Category category)
        {
            // if (id != category.Id)
            // {
            //     return BadRequest();
            // }

            category.Id = id;

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public async Task InsertAsync(Seller seller)
 {
     Context.Add(seller);
     //We put async here because this is actually the operation that does some operations in the db.
     //The Add() operation specified above does everything in memory.
     await Context.SaveChangesAsync();
 }
        public async Task <IActionResult> PutProduct(long id, Product product)
        {
            // if (id != product.Id)
            // {
            //     return BadRequest();
            // }
            product.Id = id;

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("Id,Nome")] Departamento departamento)
        {
            if (ModelState.IsValid)
            {
                _context.Add(departamento);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(departamento));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,CategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", product.CategoryId);
            return(View(product));
        }
Esempio n. 7
0
 public async Task InsertAsync(Seller obj)
 {
     _context.Add(obj);
     await _context.SaveChangesAsync();
 }