示例#1
0
        public async Task <IEnumerable <T> > GetAll()
        {
            using (RatDbContext context = _contextFactory.CreateDbContext())
            {
                IEnumerable <T> entities = await context.Set <T>().ToListAsync();

                return(entities);
            }
        }
示例#2
0
        public async Task <T> Get(int id)
        {
            using (RatDbContext context = _contextFactory.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id);

                return(entity);
            }
        }
示例#3
0
        public async Task <T> Update(int id, T entity)
        {
            using (RatDbContext context = _contextFactory.CreateDbContext())
            {
                entity.Id = id;
                context.Set <T>().Update(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
示例#4
0
        public async Task <T> Create(T entity)
        {
            using (RatDbContext context = _contextFactory.CreateDbContext())
            {
                var createdEntity = await context.Set <T>().AddAsync(entity);

                await context.Set <T>().AddAsync(entity);

                return(createdEntity.Entity);
            }
        }
示例#5
0
        public async Task <bool> Delete(int id)
        {
            using (RatDbContext context = _contextFactory.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id);

                context.Set <T>().Remove(entity);
                await context.SaveChangesAsync();

                return(true);
            }
        }
示例#6
0
        private static void AddUser(RatDbContext context)
        {
            var user = context.Users.FirstOrDefault(x => x.UserId == TestUserProvider.UserId);

            if (user == null)
            {
                context.Users.Add(new UserEntity {
                    UserId = TestUserProvider.UserId
                });

                context.SaveChanges();
            }
        }
示例#7
0
        private static void AddProjectType(RatDbContext context, string name)
        {
            var projectType = context.ProjectTypes.FirstOrDefault(x => x.Name == name);

            if (projectType == null)
            {
                context.ProjectTypes.Add(new ProjectTypeEntity {
                    Name = name
                });
            }

            context.SaveChanges();
        }
示例#8
0
 public DeleteProjectCommand(RatDbContext context)
 {
     _context = context;
 }
示例#9
0
 public CreateProjectCommand(RatDbContext context)
 {
     _context = context;
 }
示例#10
0
 public GetProjectByIdQuery(RatDbContext context)
 {
     _context = context;
 }
示例#11
0
 public PatchProjectCommand(RatDbContext context)
 {
     _context = context;
 }
 public GetProjectsForUserQuery(RatDbContext context)
 {
     _context = context;
 }