Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ansers and views to the question page

  • Loading branch information...
commit 7b0ea11e89a27c366c6391f4fa6e61a9aca5206f 1 parent 05c42c8
@Stormram Stormram authored
View
0  Notulen/notulen 19 3.txt
No changes.
View
BIN  Notulen/~$tulen 12-3-2012.docx
Binary file not shown
View
8 Source/NHLStackOverflow.tests/Models/QuestionModelValidationTest.cs
@@ -57,14 +57,14 @@ public void DefaultsForNewQuestion()
// Should not be null
Assert.IsNotNull(q.Votes, "Votes should not be null");
Assert.IsNotNull(q.Views, "Views should not be null");
- Assert.IsNotNull(q.Answered, "Answered should not be null");
+ Assert.IsNotNull(q.Answers, "Answered should not be null");
Assert.IsNotNull(q.Flag, "Flag should not be null");
Assert.IsNotNull(q.Created_At, "Created_At should not be null");
//Expected Default values
Assert.AreEqual(0, q.Votes, "Votes should be initialized to 0");
Assert.AreEqual(0, q.Views, "Views should be initialized to 0");
- Assert.AreEqual(0, q.Answered, "Answered should be initialized to 0");
+ Assert.AreEqual(0, q.Answers, "Answered should be initialized to 0");
Assert.AreEqual(0, q.Flag, "Flag should be initialized to 0;");
Assert.IsTrue(q.Created_At == StringToDateTime.ToUnixTimeStamp(DateTime.Now), "Created At should be initialized to DateTime.Now.ToString()");
}
@@ -76,7 +76,7 @@ public void ValidQuestions()
{
new Question { UserId = 1, Title = "Hello world!1", Content = "1Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" },
new Question { UserId = 2, Votes = 10, Title = "Hello world!2", Content = "2Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" },
- new Question { UserId = 3, Answered = 1, Title = "Hello world!3", Content = "3Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" },
+ new Question { UserId = 3, Answers = 1, Title = "Hello world!3", Content = "3Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" },
new Question { UserId = 2, Flag = 0, Title = "Hello world!2", Content = "2Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" }
};
@@ -128,7 +128,7 @@ public void InvalidQuestion4()
[ExpectedException(typeof(System.Data.Entity.Validation.DbEntityValidationException), "Saving invalid question should throw an DbEntityValidationException exception")]
public void InvalidQuestion5()
{
- Question q = new Question { UserId = 1, Answered = 3, Title = "Hello world12!", Content = "1Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" };
+ Question q = new Question { UserId = 1, Answers = 3, Title = "Hello world12!", Content = "1Lorem ipsum text here. So I didn't have to type this. Because I a programmer which are lazies :D. Lorem impsum dor sil ammet. This is an question: Do you work?" };
db.Questions.Add(q);
db.SaveChanges();
View
73 Source/NHLStackOverflow/Controllers/VraagController.cs
@@ -15,7 +15,6 @@ public class VraagController : Controller
// GET: Vraag/View/detailNum
public ActionResult View(int id)
{
-
Markdown md = new Markdown();
HTMLSanitizer hs = new HTMLSanitizer();
@@ -23,6 +22,8 @@ public ActionResult View(int id)
var questionDetails = from questionDetail in db.Questions
where questionDetail.QuestionID == id
select questionDetail;
+ questionDetails.First().Views += 1;
+ db.SaveChanges();
Question questionDetailView = questionDetails.First();
@@ -118,6 +119,76 @@ public ActionResult View(int id)
}
//
+ // POST: /Vraag/View/QuestionID
+ [HttpPost]
+ public ActionResult View(int id, CommentAnswer input)
+ {
+ if (input.awnserComment != null)
+ {
+ // add a new awnser comment
+ if (!Request.IsAuthenticated)
+ ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
+ if (ModelState.IsValid)
+ {
+ var userAwnsering = from user in db.Users
+ where user.UserName == User.Identity.Name
+ select user;
+ if (userAwnsering.Count() == 1)
+ {
+ Comment awnserComment = new Comment() { AnswerId = input.awnserID, Content = input.awnserComment, UserId = userAwnsering.First().UserID };
+ db.Comments.Add(awnserComment);
+ db.SaveChanges();
+ }
+ return RedirectToAction("view", "vraag", id);
+ }
+ }
+ else if (input.questionComment != null)
+ {
+ // add a new comment to the question
+ if (!Request.IsAuthenticated)
+ ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
+ if (ModelState.IsValid)
+ {
+ var userAwnsering = from user in db.Users
+ where user.UserName == User.Identity.Name
+ select user;
+ if (userAwnsering.Count() == 1)
+ {
+ Comment questionComment = new Comment() { UserId = userAwnsering.First().UserID, QuestionId = id, Content = input.questionComment };
+ db.Comments.Add(questionComment);
+ db.SaveChanges();
+ }
+ return RedirectToAction("view", "vraag", id);
+ }
+ }
+ else if (input.awnser != null)
+ {
+ // Add a new awnser
+ // add a new comment to the question
+ if (!Request.IsAuthenticated)
+ ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
+ if (ModelState.IsValid)
+ {
+ var userAwnsering = from user in db.Users
+ where user.UserName == User.Identity.Name
+ select user;
+ var thisQuestion = from questions in db.Questions
+ where questions.QuestionID == id
+ select questions;
+ if (userAwnsering.Count() == 1 && thisQuestion.Count() == 1)
+ {
+ thisQuestion.First().Answers += 1;
+ Answer questionAwnser = new Answer() { QuestionId = id, UserId = userAwnsering.First().UserID, Content = input.awnser };
+ db.Answers.Add(questionAwnser);
+ db.SaveChanges();
+ }
+ return RedirectToAction("view", "vraag", id);
+ }
+
+ }
+ return View(id);
+ }
+ //
// GET: /Vraag/StelEen
public ActionResult Check()
{
View
13 Source/NHLStackOverflow/Models/FormDataModels/Vraag.cs
@@ -38,6 +38,19 @@ public class Vraag
public string tag5 { get; set; }
}
+ public class CommentAnswer
+ {
+ [MinLength(140, ErrorMessage = "De inhoud van een antwoord moet minstens 140 karakters lang zijn.")]
+ public string awnser { get; set; }
+
+ [MinLength(10)]
+ public string awnserComment { get; set; }
+ [MinLength(10)]
+ public string questionComment { get; set; }
+
+ public int awnserID { get; set; }
+ }
+
public static class tagsCount
{
/// <summary>
View
9 Source/NHLStackOverflow/Models/NHLdb.cs
@@ -29,8 +29,13 @@ protected override void Seed(NHLdb context)
{
new User { UserName = "Piet25", Password = PasswordHasher.Hash("test"), Email = "test1@testmail.com", Rank = 3, Activated = 1 }, // admin allowed to view all!
new User { UserName = "Klaas538", Password = PasswordHasher.Hash("admin"), Email = "test2@testmail.com", Rank = 0, Activated = 1 },
- new User { UserName = "Kees1979", Password = PasswordHasher.Hash("abc"), Email = "test3@testmail.com", Rank = 0, Activated = 1, PassLost = "BCLob11SgwNtcanBG3ZmayFehZfpBz67rIrNuPNO8xTHU4JJHZD1EKpSfXDnouNJeyK572UGaBpaSau+xjRfSw" } // only person
- };
+ new User { UserName = "Kees1979", Password = PasswordHasher.Hash("abc"), Email = "test3@testmail.com", Rank = 0, Activated = 1, PassLost = "BCLob11SgwNtcanBG3ZmayFehZfpBz67rIrNuPNO8xTHU4JJHZD1EKpSfXDnouNJeyK572UGaBpaSau+xjRfSw" }, // only person
+ new User { UserName = "HiteshPatel", Password = PasswordHasher.Hash("Patel"), Email = "Patel@Hitesh.com", Rank = 1, Activated = 1 },
+ new User { UserName = "RajPAtel", Password = PasswordHasher.Hash("PAtel"), Email = "info@Raj.nl", Rank = 2, Activated = 1 },
+ new User { UserName = "user1217685", Password = PasswordHasher.Hash("user"), Email = "info@user.com", Rank = 0, Activated = 1 },
+ new User { UserName = "HiteshPatel", Password = PasswordHasher.Hash("Patel"), Email = "Patel@Hitesh.com", Rank = 1, Activated = 1 },
+ new User { UserName = "HiteshPatel", Password = PasswordHasher.Hash("Patel"), Email = "Patel@Hitesh.com", Rank = 1, Activated = 1 }
+};
users.ForEach(s => context.Users.Add(s));
context.SaveChanges();
View
7 Source/NHLStackOverflow/Models/QuestionModel.cs
@@ -12,7 +12,7 @@ public Question()
this.Views = 0;
this.Votes = 0;
this.Flag = 0;
- this.Answered = 0;
+ this.Answers = 0;
}
// GUID
@@ -31,9 +31,8 @@ public Question()
public int Votes { get; set; }
public int Views { get; set; }
- [Range(0,1)]
- public int Answered { get; set; }
- [Range(0,1)]
+ public int Answers { get; set; }
+ [Range(0, 1)]
public int Flag { get; set; }
// Timestamps
View
2  Source/NHLStackOverflow/NHLStackOverflow.csproj
@@ -250,7 +250,7 @@
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
- <DevelopmentServerPort>3930</DevelopmentServerPort>
+ <DevelopmentServerPort>16868</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:3930/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
View
2  Source/NHLStackOverflow/Views/Shared/_QuestionsPartial.cshtml
@@ -9,7 +9,7 @@
<img src="../../Styles/check.png" alt="Stemmen"/>@question.Votes
</span>
<span title="Antwoorden">
- <img src="../../Styles/aplus.png" alt="Antwoorden"/>@question.Answered
+ <img src="../../Styles/aplus.png" alt="Antwoorden"/>@question.Answers
</span>
<span title="Bekeken">
<img src="../../Styles/seen.png" alt="Bekeken"/>@question.Views
View
20 Source/NHLStackOverflow/Views/Vraag/View.cshtml
@@ -20,7 +20,7 @@
<img src="../../Styles/check.png" alt="Stemmen"/>@ViewBag.QuestionDetail.Votes
</span>
<span title="Antwoorden">
- <img src="../../Styles/aplus.png" alt="Antwoorden"/>@ViewBag.QuestionDetail.Answered
+ <img src="../../Styles/aplus.png" alt="Antwoorden"/>@ViewBag.QuestionDetail.Answers
</span>
<span title="Bekeken">
<img src="../../Styles/seen.png" alt="Bekeken"/>@ViewBag.QuestionDetail.Views
@@ -58,13 +58,17 @@
if (user.UserID == comment.UserId)
{
<b>@Html.ActionLink((string)user.UserName, "view", "user", new { id = user.UserID }, new { target = "_blank" })</b>
+ break;
}
}
</li>
}
}
<li class="respond">
- <input type="text" placeholder="Reageer"/>
+ @using (Html.BeginForm())
+ {
+ @Html.TextBox("questionComment", "", new { placeholder = "Reageer" });
+ }
</li>
</ul>
</article>
@@ -117,18 +121,28 @@ else
if (user.UserID == acomment.UserId)
{
<b>@Html.ActionLink((string)user.UserName, "view", "user", new { id = user.UserID }, new { target = "_blank" })</b>
+ break;
}
}
</li>
}
}
<li class="respond">
- <input type="text" placeholder="Reageer"/>
+ @using (Html.BeginForm())
+ {
+ string aID = Convert.ToString(answer.AnswerID);
+ @Html.TextBox("awnserComment", "", new { placeholder = "Reageer" });
+ @Html.TextBox("awnserID", aID, new { type = "hidden" });
+ }
</li>
</ul>
</article>
}
+@using (Html.BeginForm())
+{
+ @Html.TextBox("awnser", "", new { placeholder = "Schrijf een antwoord" });
+}

0 comments on commit 7b0ea11

Please sign in to comment.
Something went wrong with that request. Please try again.