Esempio n. 1
0
        static void Main(string[] args)
        {
            ConsoleWriter writer = null;

            try                                                   //BugFix #2b
            {
                HttpClient httpClient = new HttpClient();

                JokeRepository jokeRepository = new JokeRepository(httpClient);
                NameRepository nameRepository = new NameRepository(httpClient);

                writer = new ConsoleWriter();
                IReader reader = new ConsoleReader(writer);

                UserQuestions    userQuestions    = new UserQuestions(reader, writer);
                UserInteractions userInteractions = new UserInteractions(writer, userQuestions);

                JokeService jokeService = new JokeService();

                ProgramRunner programRunner = new ProgramRunner(userInteractions, jokeRepository, nameRepository, jokeService);

                programRunner.Run();
            }
            catch (Exception)
            {
                if (writer != null)
                {
                    writer.WriteLine("Something went terribly wrong.");
                    writer.WriteLine("Are you sure you're connected to the internet?");
                }
            }
        }
Esempio n. 2
0
        public List <Joke> GetJokes()
        {
            var repo  = new JokeRepository(_connection);
            var jokes = JokesApi.GetJokes();

            repo.AddJokes(jokes);
            return(jokes);
        }
        public void InitializeRepositories()
        {
            var jokeRepository = new JokeRepository();
            var userRepository = new UserRepository();

            _container.RegisterInstanceAs(jokeRepository);
            _container.RegisterInstanceAs(userRepository);
        }
Esempio n. 4
0
        public IActionResult AddSignup(User user)
        {
            user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
            JokeRepository repo = new JokeRepository(_connectionString);

            repo.AddUser(user);
            return(Redirect("/home/index"));
        }
Esempio n. 5
0
        public IActionResult Jokes()
        {
            JokeRepository repo = new JokeRepository(_connectionString);
            JokesViewModel vm   = new JokesViewModel();

            vm.Jokes       = repo.GetAllJokes();
            vm.CurrentUser = repo.GetUserByEmail(User.Identity.Name);
            return(View(vm));
        }
Esempio n. 6
0
        public IActionResult Index(int?jokeId)
        {
            JokeRepository repo = new JokeRepository(_connectionString);
            IndexViewModel vm   = new IndexViewModel();

            vm.Joke        = jokeId.HasValue ?  repo.GetJokeByid(jokeId.Value) : repo.GetJoke();
            vm.LikeCount   = repo.GetLikeCount(vm.Joke.Id);
            vm.CurrentUser = repo.GetUserByEmail(User.Identity.Name);
            return(View(vm));
        }
Esempio n. 7
0
 public ProgramRunner(
     UserInteractions userInteractions,
     JokeRepository jokeRepository,
     NameRepository nameRepository,
     JokeService jokeService)
 {
     this.userInteractions = userInteractions;
     this.jokeRepository   = jokeRepository;
     this.nameRepository   = nameRepository;
     this.jokeService      = jokeService;
 }
Esempio n. 8
0
        public void AddJokeTest_correct()
        {
            string[] actualUser = { "admin", "admin" };
            var      result     = _JokeSQL.AddJoke("ala ma kota", ref actualUser);

            Assert.IsTrue(result);
            var repo = new JokeRepository(_context);
            int id   = repo.GetNum();
            var obj  = repo.GetByID(id);

            repo.Delete(obj);
        }
Esempio n. 9
0
        public Joke GetJoke()
        {
            var joke     = JokeApi.GetJoke();
            var repo2    = new UserRepository(_connectionString);
            var user     = repo2.GetByEmail(User.Identity.Name);
            var repo     = new JokeRepository(_connectionString);
            var wasliked = repo.UserLikedJoke(joke.Id, user.Id);

            if (!wasliked)
            {
                return(joke);
            }
            return(repo.GetJokeWithLikes(joke.Id));
        }
Esempio n. 10
0
        public void LikeJoke(LikeJokeViewModel vm)
        {
            var repo  = new JokeRepository(_connectionString);
            var repo2 = new UserRepository(_connectionString);
            var user  = repo2.GetByEmail(User.Identity.Name);

            vm.Joke.UserId = user.Id;
            var wasLiked = repo.UserLikedJoke(vm.Joke.Id, user.Id);

            if (!wasLiked)
            {
                repo.LikeJoke(vm.Joke, user.Id, vm.Liked);
                return;
            }
            repo.ChangeLikeStatusForJoke(vm.Joke, user.Id, vm.Liked);
            return;
        }
Esempio n. 11
0
        public IActionResult AddLogIn(string email, string password)
        {
            JokeRepository repo = new JokeRepository(_connectionString);
            User           user = repo.Verify(email, password);

            if (user == null)
            {
                return(Redirect("/home/index"));
            }
            var claims = new List <Claim> {
                new Claim("user", email)
            };

            HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait();

            return(Redirect("/home/index"));
        }
Esempio n. 12
0
 public CategoryJokesController()
 {
     _repository = new JokeRepository();
 }
Esempio n. 13
0
 public virtual void Initialize()
 {
     _sut = new JokeRepository();
 }
Esempio n. 14
0
        public IEnumerable <Joke> GetAllJokes()
        {
            var repo = new JokeRepository(_connectionString);

            return(repo.GetJokes());
        }
Esempio n. 15
0
 public HomeController(IConfiguration configuration)
 {
     _connectionString = configuration.GetConnectionString("ConStr");
     _repo             = new JokeRepository(_connectionString);
     _urepo            = new UserRepository(_connectionString);
 }
Esempio n. 16
0
        public List <Joke> GetAllJokes()
        {
            var repo = new JokeRepository(_connection);

            return(repo.GetAllJokes());
        }
Esempio n. 17
0
        public UserLikedJokes GetLike(int id)
        {
            var repo = new JokeRepository(_connection);

            return(repo.GetLike(id, User.Identity.Name));
        }
Esempio n. 18
0
        public void UpdateLike(LikeJoke likeJoke)
        {
            var repo = new JokeRepository(_connection);

            repo.UpdateLike(likeJoke.Id, likeJoke.Liked, User.Identity.Name);
        }
Esempio n. 19
0
 public JokeSteps(UserContext user, JokeRepository jokeRepository)
 {
     _user = user;
     _jokeRepository = jokeRepository;
 }
Esempio n. 20
0
 public JokeController()
 {
     _repository = new JokeRepository();
 }
Esempio n. 21
0
        public IActionResult AddLike(int jokeId, bool likes)
        {
            JokeRepository repo = new JokeRepository(_connectionString);

            return(Json(repo.AddLike(jokeId, repo.GetUserByEmail(User.Identity.Name).Id, likes)));
        }
Esempio n. 22
0
 public JokeService(DbConnection dbConn)
 {
     _jokeRepository = new JokeRepository(dbConn);
 }
Esempio n. 23
0
 public BaseViewModel()
 {
     JokeRepository  = DependencyService.Get <JokeRepository>();
     FavoriteService = DependencyService.Get <FavoriteService>();
 }
Esempio n. 24
0
 public JokeSQL(ServerDatabaseContext context)
 {
     x = new JokeRepository(context);
     y = new UserRepository(context);
 }