public virtual List <T> GetList(Specification <T> specification = null) { using (var db = new DbTodosContext()) { specification = specification ?? new AllRecordsSpecification <T>(); return(db.GetDbSet <T>(dbSet).Where(specification.ToExpression()).ToList()); } }
public virtual T Get(Specification <T> specification = null) { using (var db = new DbTodosContext()) { specification = specification ?? new AllRecordsSpecification <T>(); return(db.GetDbSet <T>(dbSet).FirstOrDefault(specification.ToExpression())); } }
public virtual T Update(T entity) { using (var db = new DbTodosContext()) { var teamMemberDb = db.GetDbSet <T>(dbSet).First(t => t.Id == entity.Id); ReflectionUtil.CopyValues <T>(teamMemberDb, entity); db.SaveChanges(); return(teamMemberDb); } }
public T Delete(T entity) { using (var db = new DbTodosContext()) { var teamMemberDb = db.GetDbSet <T>(dbSet).First(t => t.Id == entity.Id); db.GetDbSet <T>(dbSet).Remove(teamMemberDb); db.SaveChanges(); return(teamMemberDb); } }
public override List <TeamMember> GetList(Specification <TeamMember> specification = null) { if (specification is TeamMembersInRoleSpecification) { using (var db = new DbTodosContext()) { return(db.Roles.First(x => x.Id == (specification as TeamMembersInRoleSpecification).role.Id).TeamMembers); } } return(base.GetList(specification)); }
public override List <Todo> GetList(Specification <Todo> specification = null) { if (specification is TodosInTeamMemberSpecification) { using (var db = new DbTodosContext()) { return(db.TeamMembers.First(x => x.Id == (specification as TodosInTeamMemberSpecification).teamMember.Id).Todos); } } return(base.GetList(specification)); }
public override List <Role> GetList(Specification <Role> specification = null) { if (specification is RolesInTeamMemberSpecification) { using (var db = new DbTodosContext()) { return(db.TeamMembers.First(t => t.Id == (specification as RolesInTeamMemberSpecification).teamMember.Id).Roles); } } return(base.GetList(specification)); }
public virtual T Add(T entity) { T toReturn = default(T); using (var db = new DbTodosContext()) { var set = db.GetDbSet <T>(dbSet); toReturn = set.Add(entity); db.SaveChanges(); } return(toReturn); }
public void setRolesFor(TeamMember teamMember, List <Role> roles) { using (var db = new DbTodosContext()) { var roleIds = roles.Select(r => r.Id).ToList(); teamMember = db.TeamMembers.First(x => x.Id == teamMember.Id); roles = db.Roles.Where(r => roleIds.Contains(r.Id)).ToList(); teamMember.Roles.Clear(); teamMember.Roles.AddRange(roles); db.SaveChanges(); } }