public async Task <IActionResult> PutProduct(int id, Product product) { if (id != product.Id) { return(BadRequest()); } _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,Produkt,Antal,Enhet,Medelande")] Vegetables vegetables) { if (ModelState.IsValid) { _context.Add(vegetables); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(vegetables)); }
public async Task <IActionResult> PostAsync(AddFilmModel model) { _context.Films.Add(new Film { Title = model.Title }); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PostAsync(AddCarModel model) { _context.Cars.Add(new Car { Model = model.Model }); await _context.SaveChangesAsync(); return(Ok()); }
public async Task Create(TEntity item) { await _dataBase.AddAsync(item); await _dataBase.SaveChangesAsync(); }
public async Task <Result <Product> > CreateProductAsync(string name, bool isActive, string term, int brandId) { _logger.LogDebug("CreateProductAsync {0} {1} {2} {3}", name, isActive, term, brandId); var brand = await _dbContext.Brands.FindAsync(brandId); if (brand == null) { return(Result <Product> .Fail($"Brand with id = {brandId} does not exsts")); } var product = new Product() { Name = name, IsActive = isActive, Term = term, BrandId = brandId }; await _dbContext.Products.AddAsync(product); await _dbContext.SaveChangesAsync(); return(Result <Product> .Ok(product)); }