Beispiel #1
0
        public async Task<IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.ProductId)
            {
                return BadRequest();
            }

            _context.Entry(products).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Beispiel #2
0
        public void Update(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            try
            {
                _context.Set <TEntity>().Attach(entity);
            }
            catch (Exception e)
            {
                _context.Entry(entity).State = EntityState.Detached;
                _context.Set <TEntity>().Attach(entity);
            }

            _context.Entry(entity).State = EntityState.Modified;
        }
Beispiel #3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Passwprd,Gender,Birthday,Memo")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }