コード例 #1
0
        public async Task <IActionResult> PutBlog(int id, Blog blog)
        {
            if (id != blog.IDBlog)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task UpdateAsync(TEntity entity)
        {
            using (var db = new DpContext())
            {
                entity.ModifiedDateTime = DateTimeOffset.UtcNow;

                db.Set <TEntity>().Attach(entity);
                db.Entry(entity).State = EntityState.Modified;

                await db.SaveChangesAsync();
            }
        }