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); }
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); }
//Contructor public JokeWorkflow(IJokeRepository jokeRepository, IJokeLogicMapper jokeLogicMapper, IJokeProcessor jokeProcessor) { _jokeRepository = jokeRepository; _jokeLogicMapper = jokeLogicMapper; _jokeProcessor = jokeProcessor; }
public DataManipulator() { _jokeRepository = DependencyService.Get <IJokeRepository>(); _quoteRepository = DependencyService.Get <IQuoteRepository>(); }
public JokeService(DbContext context) : base(context) { _jokeFactory = new JokeFactory(); _jokeRepository = unitOfWork.Jokes; }
public JokesController(IJokeRepository jokeRepository) { _jokeRepository = jokeRepository; }
public JokesController(IJokeRepository jokeProvider) { _jokeProvider = jokeProvider; }
public DataReader() { _jokeRepository = DependencyService.Get <IJokeRepository>(); _quoteRepository = DependencyService.Get <IQuoteRepository>(); }
public JokeService(IJokeRepository jokeRepository) { _jokeRepository = jokeRepository; }
public Peristor() { _jokeRepository = DependencyService.Get <IJokeRepository>(); _quoteRepository = DependencyService.Get <IQuoteRepository>(); }