コード例 #1
0
        private async Task <int?> GetRandomJokeId(string category, IJokeRepository jokeRepository, IUnitOfWork uow)
        {
            var categoryRepository     = uow.GetRepository <ICategoryRepository>();
            ICollection <int> jokesIds = null;

            if (!string.IsNullOrEmpty(category))
            {
                if (!await categoryRepository.AnyAsync(c => c.Title.Equals(category)))
                {
                    throw new ArgumentException($"No jokes for category \"{category}\" found.");
                }
                else
                {
                    jokesIds = await jokeRepository.FindAndMapAsync(j => j.Id,
                                                                    j => j.JokeCategories.Any(jc => jc.Category.Title.Equals(category)));
                }
            }
            else
            {
                jokesIds = await jokeRepository.FindAndMapAsync(j => j.Id);
            }

            int?randomId = null;

            if (jokesIds != null && jokesIds.Count() != 0)
            {
                randomId = GetRandomElement(jokesIds);
            }

            return(randomId);
        }
コード例 #2
0
        public UnitOfWork(DbOptions opt)
        {
            if (opt.Environment == "Development" && String.IsNullOrEmpty(opt.ConnectionString))
            {
                optionsStatic = new DbContextOptionsBuilder <EASVContext>()
                                .UseInMemoryDatabase("TheDB")
                                .Options;
                _context = new EASVContext(optionsStatic);
            }
            else
            {
                var options = new DbContextOptionsBuilder <EASVContext>()
                              .UseSqlServer(opt.ConnectionString)
                              .Options;
                _context = new EASVContext(options);
            }

            JokeRepository = new JokeRepository(_context);
        }
コード例 #3
0
ファイル: JokeWorkflow.cs プロジェクト: moritzeck/Laughy
 //Contructor
 public JokeWorkflow(IJokeRepository jokeRepository, IJokeLogicMapper jokeLogicMapper, IJokeProcessor jokeProcessor)
 {
     _jokeRepository  = jokeRepository;
     _jokeLogicMapper = jokeLogicMapper;
     _jokeProcessor   = jokeProcessor;
 }
コード例 #4
0
ファイル: DataManipulator.cs プロジェクト: Josephson199/X
 public DataManipulator()
 {
     _jokeRepository  = DependencyService.Get <IJokeRepository>();
     _quoteRepository = DependencyService.Get <IQuoteRepository>();
 }
コード例 #5
0
 public JokeService(DbContext context) : base(context)
 {
     _jokeFactory    = new JokeFactory();
     _jokeRepository = unitOfWork.Jokes;
 }
コード例 #6
0
 public JokesController(IJokeRepository jokeRepository)
 {
     _jokeRepository = jokeRepository;
 }
コード例 #7
0
 public JokesController(IJokeRepository jokeProvider)
 {
     _jokeProvider = jokeProvider;
 }
コード例 #8
0
 public DataReader()
 {
     _jokeRepository  = DependencyService.Get <IJokeRepository>();
     _quoteRepository = DependencyService.Get <IQuoteRepository>();
 }
コード例 #9
0
 public JokeService(IJokeRepository jokeRepository)
 {
     _jokeRepository = jokeRepository;
 }
コード例 #10
0
 public Peristor()
 {
     _jokeRepository  = DependencyService.Get <IJokeRepository>();
     _quoteRepository = DependencyService.Get <IQuoteRepository>();
 }