Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Produkt,Antal,Enhet,Medelande")] Vegetables vegetables)
        {
            if (id != vegetables.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vegetables);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VegetablesExists(vegetables.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(vegetables));
        }
Exemplo n.º 2
0
        public async Task <Result <Product> > UpdateProductAsync(int id, string name, bool isActive, string term, int brandId)
        {
            _logger.LogDebug("UpdateProductAsync {0} {1} {2} {3} {4}", id, 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 = await _dbContext.Products.FindAsync(id);

            if (product == null)
            {
                return(Result <Product> .Fail($"Product with id = {id} does not exsts"));
            }

            product.Name     = name;
            product.IsActive = isActive;
            product.Term     = term;
            product.Brand    = brand;

            _dbContext.Update(product);
            await _dbContext.SaveChangesAsync();

            return(Result <Product> .Ok(product));
        }