public void Delete(T entity)
        {
            // do not remove entirely. Instead, use deferred deletion and only mark as deleted.
            entity.IsDeleted = true;
            entity.UpdTs     = DateTime.Now;

            _context.Entry(entity).Property(x => x.IsDeleted).IsModified = true;
            _context.Entry(entity).Property(x => x.UpdTs).IsModified     = true;
        }
Esempio n. 2
0
        public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.Id)
            {
                return(BadRequest());
            }

            db.Entry(department).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> Patch(Guid key, Delta <Blog> patch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var blog = await _db.Blogs.FindAsync(key);

            if (blog == null)
            {
                return(NotFound());
            }

            patch.Patch(blog);
            _db.Entry(blog).State = EntityState.Modified;

            await _db.SaveChangesAsync();

            return(Updated(blog));
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> Patch(Guid key, Delta <Post> patch)
        {
            Validate(patch.GetInstance());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var post = await _db.Posts.FindAsync(key);

            if (post == null)
            {
                return(NotFound());
            }

            patch.Patch(post);
            _db.Entry(post).State = EntityState.Modified;

            await _db.SaveChangesAsync();

            return(Updated(post));
        }
 public void Update(TEntity obj)
 {
     Ctx.Entry(obj).State = EntityState.Modified;
     Ctx.SaveChanges();
 }