Exemple #1
0
        public Chat GetById(int id)
        {
            try
            {
                using (var con = new SqlConnection(Env.ConnectionString))
                {
                    con.Open();
                    var cmdString = "SELECT * FROM Chatbericht WHERE Id = @id";
                    var command   = new SqlCommand(cmdString, con);
                    command.Parameters.AddWithValue("@id", id);
                    var reader = command.ExecuteReader();

                    Chat chat = null;

                    while (reader.Read())
                    {
                        var gsql  = new GebruikerSqlContext();
                        var grepo = new GebruikerRepository(gsql);
                        var g1    = grepo.GetById(reader.GetInt32(1));
                        var g2    = grepo.GetById(reader.GetInt32(2));
                        chat = new Chat(reader.GetInt32(0), g1, g2, reader.GetDateTime(3), reader.GetString(4));
                    }
                    con.Close();
                    return(chat);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #2
0
        //Get /Details/{id}
        public ActionResult Details(int id)
        {
            if (!AuthRepository.CheckIfUserCanAcces(GebruikerType.All, (Gebruiker)Session["LoggedInUser"]))
            {
                return(View("~/Views/Error/AuthError.cshtml"));
            }

            //  try {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);

            ReviewSqlContext rsc = new ReviewSqlContext();
            ReviewRepository rr  = new ReviewRepository(rsc);

            Gebruiker loggedUser = (Gebruiker)Session["LoggedInUser"];

            ViewBag.SelectedUser = gr.GetById(id);

            if (loggedUser != null)
            {
                ViewBag.CanReview = rr.CanReview(loggedUser.Id, id);
            }

            ViewBag.SelectedUser = gr.GetById(id);
            ViewBag.Reviews      = rr.GetReviewByVrijwilligerId(id);
            return(View("~/Views/Gebruiker/Details.cshtml"));
            // }

            /*
             * catch (Exception e)
             * {
             *  return RedirectToAction("Index", "Error");
             * }
             */
        }
Exemple #3
0
        public List <Chat> GetAll()
        {
            try
            {
                List <Chat> chats = new List <Chat>();
                using (var con = new SqlConnection(Env.ConnectionString))
                {
                    con.Open();
                    var cmdString = "SELECT * FROM Chatbericht";
                    var command   = new SqlCommand(cmdString, con);

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var gsql  = new GebruikerSqlContext();
                        var grepo = new GebruikerRepository(gsql);
                        var g1    = grepo.GetById(reader.GetInt32(1));
                        var g2    = grepo.GetById(reader.GetInt32(2));
                        var chat  = new Chat(reader.GetInt32(0), g1, g2, reader.GetDateTime(3), reader.GetString(4));
                        chats.Add(chat);
                    }
                    con.Close();
                    return(chats);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void Create()
        {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);

            var User = gr.GetById(1);

            int id         = gr.Create(User);
            var nieuweUser = gr.GetById(id);

            Assert.AreEqual(id, nieuweUser.Id);
        }
Exemple #5
0
        public void TestCreateChat()
        {
            var sql   = new ChatSqlContext();
            var repo  = new ChatRepository(sql);
            var gsql  = new GebruikerSqlContext();
            var grepo = new GebruikerRepository(gsql);
            var g1    = grepo.GetById(1);
            var g2    = grepo.GetById(4);

            var chat = new Chat(g1, g2, DateTime.Now, "Hallo jongens");

            repo.Create(chat);
        }
Exemple #6
0
        public JsonResult SendChatMessage(int autheurId, int ontvangerId, string bericht)
        {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);
            var sql      = new ChatSqlContext();
            var chatRepo = new ChatRepository(sql);

            Gebruiker auteur       = gr.GetById(autheurId);
            Gebruiker ontvanger    = gr.GetById(ontvangerId);
            Chat      nieuwBericht = new Chat(auteur, ontvanger, DateTime.Now, bericht);

            chatRepo.Create(nieuwBericht);

            return(null);
        }
Exemple #7
0
        public Gebruiker ReturnAutheurObj()
        {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);

            return(gr.GetById(this.AuteurId));
        }
        public void GetById()
        {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);
            int id   = 1;
            var User = gr.GetById(id);

            Assert.AreEqual(id, User.Id);
        }
        public void Update()
        {
            GebruikerSqlContext gsc = new GebruikerSqlContext();
            GebruikerRepository gr  = new GebruikerRepository(gsc);

            Gebruiker g = gr.GetById(1);

            g.Uitschrijfdatum = DateTime.Now;
            g.Naam            = g.Naam + "aangepast";
            gr.Update(g);
        }
 public void GetGebruikerById()
 {
     //Assert
     Assert.AreEqual(gebruikers[0], repo.GetById(1), "Gebruikerobjecten komen niet overeen");
 }