示例#1
0
 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());
     }
 }
示例#2
0
 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()));
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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);
     }
 }
示例#5
0
 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));
 }
示例#8
0
        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();
     }
 }