Example #1
0
        public ActionResult Edit([Bind(Include = "Id,Name,Description,Quantity,Price")] Item item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(item).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException ex)
            {
                if (ExceptionHelper.IsUniqueConstraintViolation(ex))
                {
                    ModelState.AddModelError("Name", $"The Name '{item.Name}' is already in use, please enter a different name.");
                    return(View(nameof(Create), item));
                }
            }

            return(View(item));
        }
Example #2
0
 public async Task Update(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }