示例#1
0
        public async Task <int> SaveProduct(Guid id, Product product)
        {
            if (id != Guid.Empty)
            {
                product.Id = id;
                _productCatalogContext.Update(product);
            }
            else
            {
                _productCatalogContext.Add(product);
            }

            return(await _productCatalogContext.SaveChangesAsync());
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Quantity")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();

                    await _hubContext.Clients.All.SendAsync("ReceiveNewProduct");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
示例#3
0
        public async Task <Product> UpdateAsync(int id, Product entity)
        {
            var prd = await _context.Products.FindAsync(id);

            if (id != entity.ProductRowId || prd == null)
            {
                return(null);
            }
            var record = _context.Update <Product>(entity);
            await _context.SaveChangesAsync();

            return(record.Entity);
        }