public void DeleteBy(Expression <Func <TEntity, bool> > predicate) { IEnumerable <TEntity> items = context.Set <TEntity>().Where(predicate).AsEnumerable(); foreach (TEntity item in items) { context.Entry(item).State = EntityState.Deleted; } }
// POST api/boardapi public List Post([FromBody] CreateList input) { using (var ctx = new BoardContext()) { Board board = ctx.Boards.Where(b => b.Id == input.BoardId).First(); var list = new List { Name = input.name }; board.Lists.Add(list); ctx.Set <List>().Add(list); ctx.SaveChanges(); return(list); } }
// POST api/boardtask public Task Post([FromBody] CreateTask value) { using (var ctx = new BoardContext()) { Board board = ctx.Boards.First(b => b.Id == value.BoardId); var t = new Task { Name = value.name }; board.Lists.First().InsertTask(0, t); ctx.Set <Task>().Add(t); ctx.SaveChanges(); return(t); } }
protected IActionResult DeleteById <T>(int id, Action <T> onDelete = null) where T : Entity { var set = _context.Set <T>(); var entity = set.FirstOrDefault(x => x.Id == id); if (entity == null) { return(new HttpNotFoundResult()); } set.Remove(entity); _context.SaveChanges(); if (onDelete != null) { onDelete(entity); } return(new NoContentResult()); }
protected HttpResponseMessage DeleteById <T>(int id, Action <T> onDelete = null) where T : Entity { var set = Context.Set <T>(); var entity = set.FirstOrDefault(x => x.Id == id); if (entity == null) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } set.Remove(entity); Context.SaveChanges(); if (onDelete != null) { onDelete(entity); } return(new HttpResponseMessage(HttpStatusCode.NoContent)); }
protected GenericEfRepository(BoardContext context) { EntitySet = context.Set <T>(); _context = context; }