Example #1
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);
     }
 }
Example #2
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());
     }
 }
Example #3
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()));
     }
 }
Example #4
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);
     }
 }
Example #5
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);
        }