Ejemplo 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?");
                }
            }
        }
Ejemplo n.º 2
0
        public List <Joke> GetJokes()
        {
            var repo  = new JokeRepository(_connection);
            var jokes = JokesApi.GetJokes();

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

            _container.RegisterInstanceAs(jokeRepository);
            _container.RegisterInstanceAs(userRepository);
        }
Ejemplo 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"));
        }
Ejemplo 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));
        }
Ejemplo 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));
        }
Ejemplo 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;
 }
Ejemplo 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);
        }
Ejemplo 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));
        }
Ejemplo 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;
        }
Ejemplo 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"));
        }
Ejemplo n.º 12
0
 public CategoryJokesController()
 {
     _repository = new JokeRepository();
 }
Ejemplo n.º 13
0
 public virtual void Initialize()
 {
     _sut = new JokeRepository();
 }
Ejemplo n.º 14
0
        public IEnumerable <Joke> GetAllJokes()
        {
            var repo = new JokeRepository(_connectionString);

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

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

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

            repo.UpdateLike(likeJoke.Id, likeJoke.Liked, User.Identity.Name);
        }
Ejemplo n.º 19
0
 public JokeSteps(UserContext user, JokeRepository jokeRepository)
 {
     _user = user;
     _jokeRepository = jokeRepository;
 }
Ejemplo n.º 20
0
 public JokeController()
 {
     _repository = new JokeRepository();
 }
Ejemplo 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)));
        }
Ejemplo n.º 22
0
 public JokeService(DbConnection dbConn)
 {
     _jokeRepository = new JokeRepository(dbConn);
 }
Ejemplo n.º 23
0
 public BaseViewModel()
 {
     JokeRepository  = DependencyService.Get <JokeRepository>();
     FavoriteService = DependencyService.Get <FavoriteService>();
 }
Ejemplo n.º 24
0
 public JokeSQL(ServerDatabaseContext context)
 {
     x = new JokeRepository(context);
     y = new UserRepository(context);
 }