예제 #1
0
        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());
        }
예제 #2
0
        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));
        }
예제 #3
0
        public async Task <IActionResult> PostAsync(AddFilmModel model)
        {
            _context.Films.Add(new Film
            {
                Title = model.Title
            });

            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #4
0
        public async Task <IActionResult> PostAsync(AddCarModel model)
        {
            _context.Cars.Add(new Car
            {
                Model = model.Model
            });

            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #5
0
        public async Task Create(TEntity item)
        {
            await _dataBase.AddAsync(item);

            await _dataBase.SaveChangesAsync();
        }
예제 #6
0
        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));
        }