public async Task <IActionResult> Edit(long id, [Bind("ID,Name")] Product product)
        {
            if (id != product.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
예제 #2
0
 public IActionResult Edit(Product pro)
 {
     if (ModelState.IsValid)
     {
         context.Update(pro);
         context.SaveChanges();
         ViewData["Message"] = "Product Updated!";
     }
     return(View(pro));
 }
예제 #3
0
 public IActionResult Edit(Product p)
 {
     if (ModelState.IsValid)
     {
         context.Update(p);
         context.SaveChanges();
         ViewData["Message"] = "Product Updated!";
         //Return same page with message, or redirect to another page
         return(View(p));
     }
     //Return view with errors
     return(View(p));
 }
예제 #4
0
        public async Task <TEntity> UpdateAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(UpdateAsync)} entity must not be null");
            }

            try
            {
                context.Update(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be updated: {ex.Message}");
            }
        }
예제 #5
0
 public void Update(TEntity entity)
 {
     _dbSet.Attach(entity);
     _dbContext.Update(entity).State = EntityState.Modified;
 }