Permalink
Browse files

comments toegevoegd

  • Loading branch information...
1 parent 8f7b9cb commit 076e6db589d6183d6fabe6a1f863d4610164fe1d @Stormram Stormram committed Apr 3, 2012
View
15 Source/NHLStackOverflow/Classes/AbstractBadge.cs
@@ -1,15 +0,0 @@
-
-namespace NHLStackOverflow.Classes
-{
- public abstract class AbstractBadge
- {
- // Name, id, aantal van iets?
- // Methode die checkt of je aan deze badge voldoet
- public static string badgeName;
- public static string badgeDescription;
- public static int badgeID;
- public static int RequiredAmmount;
- public abstract bool badgeAchieve(int userID);
- public abstract void awardBadge(int userID);
- }
-}
View
3 Source/NHLStackOverflow/Classes/BadgeCount.cs
@@ -6,6 +6,9 @@
namespace NHLStackOverflow.Classes
{
+ /// <summary>
+ /// A little class that holds a badge and the amount of badges that there are of that badge
+ /// </summary>
public class BadgeCount
{
public Badge badge;
View
14 Source/NHLStackOverflow/Classes/StringFilter.cs
@@ -3,15 +3,28 @@
namespace NHLStackOverflow.Classes
{
+ /// <summary>
+ /// A class that will trim all unneeded words so we can do a better search
+ /// </summary>
public static class StringFilter
{
+ /// <summary>
+ /// A method that will trim all unneeded words
+ /// </summary>
+ /// <param name="ToTrim">A string (sentence) which needs to be stripped of unnneeded words</param>
+ /// <returns>A string array with all the "good" words</returns>
public static string[] Trim(string ToTrim)
{
+ // the list of all the unneeded words
string[] TrimAgaist = new string[14] { "hoe", "wat", "wanneer", "de", "het", "een", "help", "hulp", "nodig", "taal", "maak", "je", "doe", "in" };
+ // the new array with all the words of the sentence (words are separated by a space)
string[] temp = ToTrim.Split(' ');
+ // we need a dynamic list where we can store strings
List<string> TrimArray = new List<string>();
+ // put all the strings in this array (so we can delete them)
foreach(string a in temp)
TrimArray.Add(a);
+ // now loop through all the string in this array and check if there are some which should be deleted
for (int i = 0; i < TrimArray.Count(); i++ )
{
if (TrimAgaist.Contains(TrimArray[i]))
@@ -21,6 +34,7 @@ public static string[] Trim(string ToTrim)
i--; // to prevent jumping over
}
}
+ // build the output string
string[] output = new string[TrimArray.Count()];
for (int i = 0; i < TrimArray.Count(); i++)
output[i] = TrimArray[i];
View
62 Source/NHLStackOverflow/Classes/StringToDateTime.cs
@@ -33,12 +33,21 @@ public static DateTime toDateTime(string invoer)
return datum;
}
+ /// <summary>
+ /// A method which will make an string (so many days ago) from an unix timestamp
+ /// </summary>
+ /// <param name="date">The unix timestamp</param>
+ /// <returns>A string containing how many minutes, seconds, hours, days, months, years ago it was made</returns>
public static string ConvertToUnixTimestamp(double date)
{
+ // get the origin time (of unix timestamps)
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
+ // get the difference since then
TimeSpan since = DateTime.Now - origin;
+ // the get the diffrene with the given unix timestamp
double delta = Math.Abs(since.TotalSeconds - date);
+ // then check the value and create a string of it
if (delta < 60)
{
return delta == 1 ? "één seconde" : (int)delta + " seconden";
@@ -72,58 +81,25 @@ public static string ConvertToUnixTimestamp(double date)
int months = Convert.ToInt32(Math.Abs((double)(delta / 60 / 60 / 24) / 30));
return months <= 1 ? "één maand" : months + " maanden";
}
+ // if we got here it's in the size of a year so get the amount of years
int years = Convert.ToInt32(Math.Abs((double)(delta / 60 / 60 / 24) / 365));
+ // and return the amount of years
return years <= 1 ? "één jaar" : years + " jaar";
}
+ /// <summary>
+ /// A method which takes dateTime and returns the unix timestamp of it
+ /// </summary>
+ /// <param name="date">A dateTime which needs to be converted</param>
+ /// <returns>A double with the amount of seconds since the unix time</returns>
public static double ToUnixTimeStamp(DateTime date)
{
+ // get the origin datetime
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
+ // and then calculate the difference in seconds since that time with the given date
TimeSpan diff = date - origin;
+ // and then return the abs of it
return Math.Floor(diff.TotalSeconds);
}
-
-
- //public static string toSmootherTime(DateTime dt)
- //{
- // var ts = new TimeSpan(DateTime.Now.Ticks - dt.Ticks);
- // double delta = Math.Abs(ts.TotalSeconds);
-
- // if (delta < 60)
- // {
- // return ts.Seconds == 1 ? "één seconde" : ts.Seconds + " seconden";
- // }
- // if (delta < 120)
- // {
- // return "één minuut";
- // }
- // if (delta < 2700) // 45 * 60
- // {
- // return ts.Minutes + " minuten";
- // }
- // if (delta < 5400) // 90 * 60
- // {
- // return "één uur";
- // }
- // if (delta < 86400) // 24 * 60 * 60
- // {
- // return ts.Hours + " uur";
- // }
- // if (delta < 172800) // 48 * 60 * 60
- // {
- // return "gisteren";
- // }
- // if (delta < 2592000) // 30 * 24 * 60 * 60
- // {
- // return ts.Days + " dagen";
- // }
- // if (delta < 31104000) // 12 * 30 * 24 * 60 * 60
- // {
- // int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
- // return months <= 1 ? "één maand" : months + " maanden";
- // }
- // int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
- // return years <= 1 ? "één jaar" : years + " jaar";
- //}
}
}
View
8 Source/NHLStackOverflow/Classes/TagsIDs.cs
@@ -6,8 +6,16 @@
namespace NHLStackOverflow.Classes
{
+ /// <summary>
+ /// A litle class which holds tag and the questionID that has this tag
+ /// </summary>
public class TagsIDs
{
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="tag">The tag that should be linked with</param>
+ /// <param name="questionTaggyID">this questionID</param>
public TagsIDs(Tag tag, int questionTaggyID)
{
this.Tag = tag;
View
38 Source/NHLStackOverflow/Controllers/AnswerController.cs
@@ -16,25 +16,33 @@ public class AnswerController : Controller
// GET: /Answer/Delete/AnswerID
public ActionResult Delete(int id)
{
+ // Get the infor of the answer which should be deleted
var AnswerDelete = from answerDelete in db.Answers
where answerDelete.AnswerID == id
select answerDelete;
+ // and get the rank of this user
int userRank = (from user in db.Users
where user.UserName == User.Identity.Name
select user.Rank).Single();
+ // if we found no answer of the rank is not right skip deleting
if (AnswerDelete.Count() == 1 && userRank >= 2)
{
// delete this awnser
var AwnserToDelete = AnswerDelete.First();
+ // remove the answer
db.Answers.Remove(AwnserToDelete);
+ // get all the votes on it
var answerVotes = from answerVote in db.Votes
where answerVote.AnswerID == id
select answerVote;
+ // loop through it and delete each
foreach (var vote in answerVotes)
db.Votes.Remove(vote);
+ // get all the flags on a answer
var flags = from flag in db.Flags
where flag.AnswerID == id
select flag;
+ // loop through it and delete each
foreach (var flag in flags)
db.Flags.Remove(flag);
// get the comments
@@ -45,9 +53,11 @@ public ActionResult Delete(int id)
foreach (var comment in commentsAwnsers)
{
db.Comments.Remove(comment);
+ // get the possible flags on this comment
var CommentFlag = from flag in db.Flags
where flag.CommentID == comment.CommentID
select flag;
+ // delete each flag
foreach (var comFlag in CommentFlag)
db.Flags.Remove(comFlag);
}
@@ -57,7 +67,7 @@ public ActionResult Delete(int id)
select user).Single();
userMetaAwnser.Answers -= 1;
- // get some stuff for genarating a message
+ // get some stuff for generating a message
var userDeleting = (from usertje in db.Users
where usertje.UserName == User.Identity.Name
select usertje).Single();
@@ -80,31 +90,36 @@ public ActionResult Delete(int id)
db.SaveChanges();
}
// should return us to the page we were at
-
return Redirect(Request.UrlReferrer.AbsolutePath);
}
//
// GET: answer/voteup/answerID
public ActionResult VoteUp(int id)
{
+ // check if we are logged in
if (User.Identity.IsAuthenticated)
{
+ // if so get the stuff of this user
var userVoiting = from userVote in db.Users
where userVote.UserName == User.Identity.Name
select userVote;
+ // get the stuff of this answer (which gets the vote up or down
var AnswerGettingVoted = from Answers in db.Answers
where Answers.AnswerID == id
select Answers;
-
+ // check if that did return some stuff
if (userVoiting.Count() == 1 && AnswerGettingVoted.Count() == 1)
{
+ // cast it to a single
var UserVoting = userVoiting.First();
// check if this is a up vote or a second time vote (so downvote)
var voteInfo = from vote in db.Votes
where vote.UserID == UserVoting.UserID && vote.AnswerID == id
select vote;
+ // cast the answer to a single
var answer = AnswerGettingVoted.First();
+ // get the userMeta of the person whoes answer it is
var userGettingVoted = (from user in db.UserMeta
where user.UserId == answer.UserId
select user).Single();
@@ -126,9 +141,10 @@ public ActionResult VoteUp(int id)
db.SaveChanges();
}
}
- else
- ModelState.AddModelError("", "Je account bestaat niet of de vraag bestaat niet.");
+ else // if we didn't find the answer of the account didn't exist
+ ModelState.AddModelError("", "Je account bestaat niet of het antwoord bestaat niet.");
}
+ // then return them back to their page they came from
if (!Request.UrlReferrer.AbsolutePath.Contains("vraag"))
return RedirectToAction("index", "default");
else
@@ -139,32 +155,41 @@ public ActionResult VoteUp(int id)
// GET: /answer/FlagAnswer/AnswerID
public ActionResult FlagAnswer(int id)
{
+ // check if we are logged in
if (User.Identity.IsAuthenticated)
{
+ // get info of the user that is hitting report
var UserFlagging = from usr in db.Users
where usr.UserName == User.Identity.Name
select usr;
+ // get stuff about the answer getting flagged
var AnswerFlagged = from answer in db.Answers
where answer.AnswerID == id
select answer;
+ // check if we got an user and an answer
if (UserFlagging.Count() == 1 && AnswerFlagged.Count() == 1)
{
+ // cast the to a single
var user = UserFlagging.First();
var answer = AnswerFlagged.First();
+
+ // get info to check if it is a upflag or a down flag
var flagged = from flag in db.Flags
where flag.AnswerID == id && flag.UserID == user.UserID
select flag;
+ // if there is a record of it the it is an unflag
if (flagged.Count() == 1)
{
// unflag
db.Flags.Remove(flagged.First());
db.SaveChanges();
+ // check if the answer still has flags or this was the only one
var totalFlags = from flags in db.Flags
where flags.AnswerID == id
select flags;
+ // if no unflag it
if (totalFlags.Count() == 0)
{
- // if there are no longer
answer.Flag = 0;
db.SaveChanges();
}
@@ -178,6 +203,7 @@ public ActionResult FlagAnswer(int id)
}
}
}
+ // through us back to the page we came from
return Redirect(Request.UrlReferrer.AbsolutePath);
}
View
23 Source/NHLStackOverflow/Controllers/BadgeController.cs
@@ -15,13 +15,13 @@ public class BadgeController : Controller
public ActionResult Index()
{
-
+ // get the list of badges and the amount of people that have such badage
var badgeList = from badges in db.Badges
group badges by badges.Name into a
select new BadgeCount() { badge = a.FirstOrDefault(), count = a.Count() };
-
+ // give it to the viewbag
ViewBag.badgesList = badgeList;
-
+ // a list which has a description of each badge
var badgeDesList = new List<BadgeDe>{
new BadgeDe(1, "Stel je eerste vraag", "Bronze"),
new BadgeDe(2, "Geef je eerste antwoord", "Bronze"),
@@ -39,26 +39,31 @@ public ActionResult Index()
return View();
}
+ //
+ // GET: /badge/search/badgeID
public ActionResult Search(string id)
{
+ // get a list of people having this badge
var badgeList = from badges in db.Badges
where badges.Name == id
select badges;
-
+ // give the info back to the viewbag
ViewBag.badgesList = badgeList;
ViewBag.badgesName = badgeList.First();
ViewBag.badgeCount = badgeList.Count();
- List<User> test = new List<Models.User>();
+ // create a list of users having this badge
+ List<User> userList = new List<Models.User>();
+ // foreach badge that was found get the info of the person which has this badge
foreach (var badgde in badgeList)
{
var badgeUsers = from users in db.Users
orderby users.Created_At descending
where users.UserID == badgde.UserId
select users;
- test.Add(badgeUsers.First());
+ userList.Add(badgeUsers.First());
}
- ViewBag.badgesUsers = test;
-
+ ViewBag.badgesUsers = userList;
+ // a list which has a description of all the badges
var badgeDesList = new List<BadgeDe>{
new BadgeDe(1, "Stel je eerste vraag", "Bronze"),
new BadgeDe(2, "Geef je eerste antwoord", "Bronze"),
@@ -70,7 +75,9 @@ public ActionResult Search(string id)
new BadgeDe(8, "Stel je 20e vraag", "Zilver"),
new BadgeDe(9, "Stel je 100e vraag", "Goud")
};
+ // select the bdage ID
int idtje = badgeList.First().BadgeID;
+ // give back only the description of the badge that we need
ViewBag.BadgeDescription = (from badgeDescript in badgeDesList
where badgeDescript.BadgeID == idtje
select badgeDescript.Description).First();
View
25 Source/NHLStackOverflow/Controllers/CommentController.cs
@@ -10,29 +10,33 @@ namespace NHLStackOverflow.Controllers
public class CommentController : Controller
{
NHLdb db = new NHLdb();
+
//
// GET: Comment/Delete/CommentID
-
public ActionResult Delete(int id)
{
+ // get the stuff of the comment that has been selected to delete
var deleteComment = from comment in db.Comments
where comment.CommentID == id
select comment;
+ // check if it gave back a comment if not show an error
if (deleteComment.Count() != 1)
ModelState.AddModelError("", "Er is iets mis gegaan. We hebben de comment niet kunnen vinden.");
-
+ // Get the info of the user that hitted delete, check if he exists and has the right rank
var userAllowed = from user in db.Users
where user.UserName == User.Identity.Name && user.Rank > 0
select user;
+ // check if it gave one user back, if not show an error
if (userAllowed.Count() != 1)
ModelState.AddModelError("", "U hebt geen toestemming om een comment te verwijderen.");
if (ModelState.IsValid)
{
- // allowed and post found :D
- // Let's delete it :D
+ // allowed and comment found :D
+ // get the flags on this comment
var commentFlags = from flag in db.Flags
where flag.CommentID == id
select flag;
+ // delete each flag
foreach (var flag in commentFlags)
db.Flags.Remove(flag);
db.Comments.Remove(deleteComment.First());
@@ -45,40 +49,49 @@ public ActionResult Delete(int id)
// GET: /comment/FlagComment/CommentID
public ActionResult FlagComment(int id)
{
+ // check if we are logged in
if (User.Identity.IsAuthenticated)
{
+ // get the info of the user hitting flag
var UserFlagging = from usr in db.Users
where usr.UserName == User.Identity.Name
select usr;
+ // get the info of the comment getting flagged
var CommentFlagged = from comment in db.Comments
where comment.CommentID == id
select comment;
+ // check if each is right
if (UserFlagging.Count() == 1 && CommentFlagged.Count() == 1)
{
+ // cast them to a single
var user = UserFlagging.First();
var comment = CommentFlagged.First();
+ // get the flags on this comment by this user
var flagged = from flag in db.Flags
where flag.CommentID == id && flag.UserID == user.UserID
select flag;
+ // if this equals to one then we are unflagging the comment
if (flagged.Count() == 1)
{
// unflag
db.Flags.Remove(flagged.First());
db.SaveChanges();
+ // get the amount of flags left on this comment
var totalFlags = from flags in db.Flags
where flags.CommentID == id
select flags;
+ // if this is 0 after deleting this flag of this user then unflag the comment
if (totalFlags.Count() == 0)
{
- // if there are no longer
comment.Flag = 0;
db.SaveChanges();
}
}
- else
+ else // we are flagging this comment
{
// flag
comment.Flag = 1;
+ // so add a new flag
db.Flags.Add(new Flag() { CommentID = comment.CommentID, UserID = user.UserID });
db.SaveChanges();
}
View
12 Source/NHLStackOverflow/Controllers/DefaultController.cs
@@ -22,7 +22,7 @@ public ViewResult Index()
orderby questions.Created_At descending
select questions;
List<User> usersList = new List<User>();
- List<TagsIDs> abc = new List<TagsIDs>();
+ List<TagsIDs> tagList = new List<TagsIDs>();
foreach (Question vraag in QuestionList)
{
// Strip all HTML tags from the question content
@@ -37,18 +37,20 @@ public ViewResult Index()
join c in db.QuestionTags on tagsQuestion.TagID equals c.TagId
where c.QuestionId == vraag.QuestionID
select tagsQuestion;
-
+ // create a list of all the tags linked to the question which has this tag
foreach (Tag i in TagList)
- abc.Add(new TagsIDs(i, vraag.QuestionID));
-
+ tagList.Add(new TagsIDs(i, vraag.QuestionID));
+ // get the user stuff (for displaying the username)
var UserList = from users in db.Users
where users.UserID == vraag.UserId
select users;
+ // check ifthe list already has this user if not add it
if(!usersList.Contains(UserList.First()))
usersList.Add(UserList.First());
}
- ViewBag.Helper = abc;
+ // give it all back to the viewbag
+ ViewBag.Helper = tagList;
ViewBag.UsersList = usersList;
ViewBag.QuestionList = QuestionList;
View
20 Source/NHLStackOverflow/Controllers/LoginController.cs
@@ -11,6 +11,7 @@ namespace NHLStackOverflow.Controllers
{
public class LoginController : Controller
{
+ // the stuff needed to be able to send a real e-mail
private IUserMailer _userMailer = new UserMailer();
public IUserMailer UserMailer
{
@@ -29,7 +30,6 @@ public ActionResult Index()
//
// POST: /Login/
-
[HttpPost]
public ActionResult Index(Login user)
{
@@ -69,28 +69,29 @@ public ActionResult Index(Login user)
//
// GET: /login/wachtwoordkwijt
-
public ActionResult WachtwoordKwijt()
{
return View();
}
//
// POST: /login/wachtwoordkwijt
-
[HttpPost]
public ActionResult WachtwoordKwijt(PassLostEmail user)
{
- // Todo wachtwoordkwijt mailer maken
+ // get this info of the user that has lost his password
var passLostPerson = from userPassLost in db.Users
where userPassLost.Email == user.Email && userPassLost.Activated == 1
&& userPassLost.PassLost == null
select userPassLost;
+ // if the didn't yield a result show an error
if (passLostPerson.Count() != 1)
ModelState.AddModelError("", "Er is geen juiste user gevonden.");
+ // if this is valid
if(ModelState.IsValid)
{
+ // in a try catch so that if mailing failed we can try again
try
{
passLostPerson.First().PassLost = Cryptography.UrlHash(passLostPerson.First().Password + passLostPerson.First().Email);
@@ -101,6 +102,7 @@ public ActionResult WachtwoordKwijt(PassLostEmail user)
{
ModelState.AddModelError("", "Er is iets mis gegaan. Onze excuses voor het ongemak. Probeer het over enkele momenten overnieuw.");
}
+ // if it all went right link us to the succes page and save the datebase changes
if (ModelState.IsValid)
{
db.SaveChanges();
@@ -124,25 +126,28 @@ public ActionResult KwijtVeranderen(string id)
[HttpPost]
public ActionResult KwijtVeranderen(string id, PassLost user)
{
+ // check if the two passwords are equal
if (user.Password1 != user.Password2)
ModelState.AddModelError("", "Het eerste en het tweede wachtwoord kwamen niet overeen.");
-
+ // get the info of the person that has lost his password
var kwijtUser = from userKwijt in db.Users
where userKwijt.PassLost == id
select userKwijt;
+ // check if this yielded some result
if (kwijtUser.Count() != 1)
ModelState.AddModelError("", "De meegegeven string komt niet overeen met een gebruiker.");
-
+ // if so continue
if (ModelState.IsValid)
{
+ // set the new password
kwijtUser.First().Password = Cryptography.PasswordHash(user.Password1);
kwijtUser.First().PassLost = null;
db.SaveChanges();
// to a static page saying it has been changed
return RedirectToAction("wachtwoordveranderd", "Login");
}
-
+ // if we get here it wasn't valid
return View();
}
@@ -162,7 +167,6 @@ public ActionResult KwijtVerstuurd()
//
// GET: /login/logout
-
public ActionResult LogOut()
{
FormsAuthentication.SignOut();
View
8 Source/NHLStackOverflow/Controllers/RegistreerController.cs
@@ -31,9 +31,10 @@ public ActionResult Index()
[HttpPost]
public ActionResult Index(User user)
{
- // create a new user and fill in the required fields
+ // check if the conditions are checked
if (Request.Form.Get("ConditionsAccepted") == "false" ) // check if the conditions has been checked
ModelState.AddModelError("", "De gebruikersvoorwaarden dienen te worden geacepteerd");
+ // check if the two passwords are equal
if (Request.Form.Get("PassWord2") != user.Password) // check if password1 and password2 are the same, preventing password typos
ModelState.AddModelError("", "De ingevulde wachtwoorden komen niet overeen");
// check if the email is being used
@@ -53,6 +54,7 @@ where user.UserName.ToLower() == NameUser.UserName.ToLower()
{
// everything is right
// hash the password
+ // in a try catch incase we are unable to send an mail
try
{
user.Password = Cryptography.PasswordHash(user.Password);
@@ -98,10 +100,12 @@ public ActionResult activeren(string id, AccountActivation user)
ModelState.AddModelError("", "Het wachtwoord kwam niet overeen met de database.");
if (ModelState.IsValid)
{
- // everything was valid. Change the persons state to activated.
+ // get the userID
int activatingUserID = passPerson.First().UserID;
+ // create a new userMeta for this user
UserMeta newUserMeta = new UserMeta() { UserId = activatingUserID };
db.UserMeta.Add(newUserMeta);
+ // everything was valid. Change the persons state to activated.
passPerson.First().Activated = 1;
passPerson.First().ActivationLink = null;
db.SaveChanges();
View
18 Source/NHLStackOverflow/Controllers/TagsController.cs
@@ -16,6 +16,7 @@ public ActionResult Index()
{
HTMLSanitizer hs = new HTMLSanitizer();
+ // get a list of all the tags
var TagsList = from tags in db.Tags
orderby tags.Count descending
select tags;
@@ -37,20 +38,16 @@ public ActionResult Index()
// GET: /Tags/search/int TagID
public ActionResult Search(int id)
{
- // Get the name of the tag.
- ViewBag.TagName = (from t in db.Tags
- where t.TagID == id
- select t.Name).Single();
-
HTMLSanitizer hs = new HTMLSanitizer();
-
+ // get all the questions which have this tag
var TagsSearched = from questionView in db.Questions
join c in db.QuestionTags on questionView.QuestionID equals c.QuestionId
where c.TagId == id
select questionView;
ViewBag.TagSearch = TagsSearched;
+ // get the info about this tag
var TagsNames = from tagsName in db.Tags
where tagsName.TagID == id
select tagsName;
@@ -59,26 +56,27 @@ public ActionResult Search(int id)
List<TagsIDs> abc = new List<TagsIDs>();
List<User> userTags = new List<User>();
- //tags in question
-
+ // Get all the tags of each question and the user(for the username)
foreach (Question t in TagsSearched)
{
+ // get all the tags
var TagList = from tagsQuestion in db.Tags
join c in db.QuestionTags on tagsQuestion.TagID equals c.TagId
where c.QuestionId == t.QuestionID
select tagsQuestion;
-
+ // add each to the list
foreach (Tag i in TagList)
{
abc.Add(new TagsIDs(i, t.QuestionID));
// Sanitize each tag its name
i.Name = hs.Sanitize(i.Name, HTMLSanitizerOption.StripTags);
}
-
+ // get the user stuff
var UsersList = from users in db.Users
where users.UserID == t.UserId
select users;
+ // if not in the list add it
if (!userTags.Contains(UsersList.First()))
userTags.Add(UsersList.First());
View
45 Source/NHLStackOverflow/Controllers/UserController.cs
@@ -30,12 +30,16 @@ public ActionResult Index()
//
// POST: /User/
+ // this is the main page of user when he submits more info about him
[HttpPost]
public ActionResult Index(Account newUserInfo)
{
+
+ // get the info of the user
var userInfo = from user in db.Users
where user.UserName == User.Identity.Name
select user;
+ // if the submittings are valid add them
if(ModelState.IsValid)
{
userInfo.First().Location = newUserInfo.Location;
@@ -44,7 +48,7 @@ public ActionResult Index(Account newUserInfo)
userInfo.First().Languages = newUserInfo.Languages;
db.SaveChanges();
}
-
+ // give back the user
ViewBag.User = userInfo.First();
return View();
@@ -63,44 +67,53 @@ public ActionResult Instellingen()
[HttpPost]
public ActionResult Instellingen(PassEmail passEmail)
{
+ // check if the sendings are the stuff for changing pass
if (passEmail.NowPassword != null && passEmail.Email == null)
{
// going to change the password
var userInfos = from userInfo in db.Users
where userInfo.UserName == User.Identity.Name
select userInfo;
+ // check if the submitted pass equals the real pass
if (userInfos.First().Password != Cryptography.PasswordHash(passEmail.NowPassword))
ModelState.AddModelError("", "Het wachtwoord komt nier overeen.");
+ // check if both new passwords are equal and not null
if (passEmail.Password1 != passEmail.Password2 || passEmail.Password1 == null)
ModelState.AddModelError("", "Het eerste wachtwoord en de tweede kwamen niet overeen.");
if (ModelState.IsValid)
{
- // Allowed for a password change
+ // Allowed for a password change and passwords are right
userInfos.First().Password = Cryptography.PasswordHash(passEmail.Password1);
db.SaveChanges();
ViewBag.Message = "Het wachtwoord is succesvol veranderd.";
return View();
}
- }
+ } // check if we are going to change the password
else if (passEmail.Email != null && passEmail.NowPassword == null)
{
// going to change the password
+
+ // get the info of the current user
var userInfos = from userInfo in db.Users
where userInfo.UserName == User.Identity.Name
select userInfo;
+ // check if this pass exists
var emailUsers = from emailUser in db.Users
where emailUser.Email == passEmail.Email
select emailUser;
+ // check if we got such email in the db (thus not allowing this new email)
if (emailUsers.Count() != 0)
ModelState.AddModelError("", "Dit email adress is al opgenomen in de database.");
if (ModelState.IsValid)
{
+ // all proper so change it
userInfos.First().Email = passEmail.Email;
db.SaveChanges();
ViewBag.MessageDuex = "Het email is succesvol veranderd.";
return View();
}
}
+ // got here nothing sumbitted or invalid
return View();
}
@@ -119,6 +132,7 @@ public ActionResult View(int id)
// GET: User/Admin
public ActionResult Beheer()
{
+ // check if logged in
if (User.Identity.IsAuthenticated)
{
// Needed to check if we are allowed to see some bad stuff happening
@@ -144,44 +158,51 @@ public ActionResult Beheer()
var commentOnQuestion = from qcomment in db.Comments
where qcomment.CommentID == comment.CommentID
select qcomment.QuestionId;
+ // get all the comments and add then to the list
foreach (var qcomment in commentOnQuestion)
{
+ // check if not null (since this is not a valid one)
if (qcomment != 0)
QuestionCommentList.Add(new CommentQuestion(comment.CommentID, qcomment));
}
+ // get the answers comments
var canswer = from answer in db.Answers
where answer.AnswerID == comment.AnswerId
select answer.QuestionId;
+ // add all the comments on answers which are bad
foreach (var acomment in canswer)
{
+ // check if not null
if (acomment != 0)
QuestionCommentList.Add(new CommentQuestion(comment.CommentID, acomment));
}
}
+
+ // give em back to the viewbag
ViewBag.QCList = QuestionCommentList;
ViewBag.badCommentList = badCommets;
}
if (userRanking.First() > 1)
{
// Allowed to see bad anwsers that are flagged
+ // so get them
var badAwnsers = from awnser in db.Answers
where awnser.Flag == 1
select awnser;
+ // give these back
ViewBag.badAwnserList = badAwnsers;
}
if (userRanking.First() > 2)
{
- // allowed to see em all, show evil questions aswell
+ // allowed to see em all, show give the questions aswell
var badQuestions = from question in db.Questions
where question.Flag == 1
select question;
+
+ // give them back to the viewbag
ViewBag.badQuestionList = badQuestions;
}
}
- else
- {
- // Give some error bag somewhere :<
- }
return View();
}
@@ -311,11 +332,13 @@ where userSend.UserName.ToLower() == User.Identity.Name.ToLower()
var userTo = from toUser in db.Users
where toUser.UserName == berichtje.SendTo
select toUser;
+ // check if the user gave valid stuff back
if (userTo.Count() != 1 || berichtje.SendTo == null)
ModelState.AddModelError("", "De ingevoerde gebruiker bestaat niet.");
if (ModelState.IsValid)
{
+ // if so create the message
Message newMessage = new Message() { SenderId = userSending.First().UserID, Title = berichtje.Title, ReceiverId = userTo.First().UserID, Content = berichtje.Content };
db.Messages.Add(newMessage);
db.SaveChanges();
@@ -360,24 +383,30 @@ public ActionResult deleteMail(int id)
// GET: /user/markeergelezen
public ActionResult MarkeerGelezen()
{
+ // check if logged in
if (User.Identity.IsAuthenticated)
{
+ // get the userID of the person
var userID = from user in db.Users
where user.UserName == User.Identity.Name
select user.UserID;
if (userID.Count() == 1)
{
+ // cast it to an int so we can compare
int UserID = userID.First();
+ // get all the messages of this person
var allMails = from mail in db.Messages
where mail.ReceiverId == UserID
select mail;
+ // mark them all as read
foreach (var mail in allMails)
{
mail.Viewed = 1;
}
db.SaveChanges();
}
}
+ // go back to the inbox
return RedirectToAction("inbox", "user");
}
#endregion // mailstuff
View
183 Source/NHLStackOverflow/Controllers/VraagController.cs
@@ -25,9 +25,10 @@ public ActionResult View(int id)
select questionDetail;
questionDetails.First().Views += 1;
db.SaveChanges();
- // get the user rank
+ // check if logged in
if (User.Identity.IsAuthenticated)
{
+ // give back the rank of this user
ViewBag.UserRank = (from user in db.Users
where user.UserName == User.Identity.Name
select user.Rank).Single();
@@ -44,12 +45,12 @@ public ActionResult View(int id)
List<TagsIDs> abc = new List<TagsIDs>();
- //tags in question
+ // get all the tags on this question
var TagList = from tagsQuestion in db.Tags
join c in db.QuestionTags on tagsQuestion.TagID equals c.TagId
where c.QuestionId == id
select tagsQuestion;
-
+ // add each to the list
foreach (Tag i in TagList)
{
abc.Add(new TagsIDs(i, id));
@@ -60,24 +61,24 @@ public ActionResult View(int id)
ViewBag.Helper = abc;
- //user verificatie
+ // get the user of this question (for the username and link)
var useringlist = from users in db.Users
where users.UserID == questionDetailView.UserId
select users;
ViewBag.QuestionUser = useringlist.First();
- //comments
+ // get the comments on this question
var commentList = from comments in db.Comments
orderby comments.Created_At descending
where comments.QuestionId == id
select comments;
-
+ // add each to the list
List<Comment> commentUserView = new List<Comment>(commentList);
ViewBag.CommentsList = commentList;
-
+ // get a list of all the users that made the comment
List<User> CommentingUsers = new List<User>();
foreach (Comment commentje in commentUserView)
{
@@ -89,6 +90,7 @@ public ActionResult View(int id)
ViewBag.UserCommentList = CommentingUsers;
+ // get the answers
var answerQuestion = from answers in db.Answers
orderby answers.Created_At descending
where answers.QuestionId == id
@@ -103,26 +105,29 @@ public ActionResult View(int id)
List<User> AnsweringUsers = new List<User>();
List<Comment> AnswerComments = new List<Comment>();
List<User> qCommentUsers = new List<User>();
-
+ // for each answer
foreach (Answer answertje in answerQuestionView)
{
+ // get the userID (for the username)
var userAnswer = from answerse in db.Users
where answerse.UserID == answertje.UserId
select answerse;
AnsweringUsers.Add(userAnswer.First());
+ // get al the comments
var answerCommentList = from qcomments in db.Comments
orderby qcomments.Created_At descending
where qcomments.AnswerId == answertje.AnswerID
select qcomments;
if (answerCommentList.Count() > 0)
{
+ // if there are some comments add them
foreach (Comment cba in answerCommentList)
AnswerComments.Add(cba);
}
-
+ // foreach comment get the user (for the username again)
foreach (Comment qCommentje in answerCommentList)
{
var userQComment = from qcommentse in db.Users
@@ -145,52 +150,62 @@ public ActionResult View(int id)
//
// POST: /Vraag/View/QuestionID
+ // on a post we submitted an comment or an asnwer
[HttpPost]
public ActionResult View(int id, CommentAnswer input)
{
+ // check if we are adding a comment on an asnwer
if (input.awnserComment != null)
{
// add a new awnser comment
- if (!Request.IsAuthenticated)
+ if (!Request.IsAuthenticated) // check if we are logged in
ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
if (ModelState.IsValid)
{
+ // all valid
+ // get the info of the user that is making a comment
var userAwnsering = from user in db.Users
where user.UserName == User.Identity.Name
select user;
if (userAwnsering.Count() == 1)
{
+ // if this yielded some user we can actually create the new comment
Comment awnserComment = new Comment() { AnswerId = input.awnserID, Content = input.awnserComment, UserId = userAwnsering.First().UserID };
db.Comments.Add(awnserComment);
db.SaveChanges();
}
+ // return them to the page where this question is at
return RedirectToAction("view", "vraag", id);
}
}
- else if (input.questionComment != null)
+ else if (input.questionComment != null) // check if we are adding a comment on a question
{
// add a new comment to the question
+ // check if we are logged in
if (!Request.IsAuthenticated)
ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
if (ModelState.IsValid)
{
+ // all valid then get the info of the user which is writing this comment
var userAwnsering = from user in db.Users
where user.UserName == User.Identity.Name
select user;
- if (userAwnsering.Count() == 1)
+ if (userAwnsering.Count() == 1) // check if we could find this user
{
+ // add the new comment
Comment questionComment = new Comment() { UserId = userAwnsering.First().UserID, QuestionId = id, Content = input.questionComment };
db.Comments.Add(questionComment);
db.SaveChanges();
}
+ // go back to the question we came from
return RedirectToAction("view", "vraag", id);
}
}
- else if (input.awnser != null)
+ else if (input.awnser != null) // check if we are giving a new asnwer
{
- // Add a new awnser
- // add a new comment to the question
+ // Add a new awnser
+ // check if we are logged in
if (!Request.IsAuthenticated)
ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
if (ModelState.IsValid)
@@ -205,7 +220,6 @@ public ActionResult View(int id, CommentAnswer input)
select questions;
if (userAwnsering.Count() == 1 && thisQuestion.Count() == 1)
{
-
// cast the userID to an int to use it again
int userID = userAwnsering.First().UserID;
// get the usermeta
@@ -215,19 +229,27 @@ public ActionResult View(int id, CommentAnswer input)
// add one to the amount of answers given
userAwnseringMeta.Answers += 1;
+ // get the userID of the person which is giving an asnwer
int AwnserUserID = userAwnsering.First().UserID;
-
+ // mark this question as one which has a new answer
thisQuestion.First().Answers += 1;
+ // add the answer
Answer questionAwnser = new Answer() { QuestionId = id, UserId = AwnserUserID, Content = input.awnser };
db.Answers.Add(questionAwnser);
db.SaveChanges();
+
+ // ###################################
+ // check if we got a new badge
+ // ###################################
if (AnswerBadge.badgeAchieve(AwnserUserID))
AnswerBadge.awardBadge(AwnserUserID);
if (AnswerCreatorBadge.badgeAchieve(AwnserUserID))
AnswerCreatorBadge.awardBadge(AwnserUserID);
if (AnswerLordBadge.badgeAchieve(AwnserUserID))
AnswerLordBadge.awardBadge(AwnserUserID);
+ // ###################################
}
+ // go back to the current question where we got from
return RedirectToAction("view", "vraag", id);
}
@@ -250,34 +272,42 @@ public ActionResult Check()
[ValidateInput(false)]
public ActionResult Check(string vraag)
{
+ // check if there is a question filled in
if (vraag == null)
ModelState.AddModelError("", "Vraag is leeg.");
- if (vraag.Length < 10 || vraag.Length > 140)
+ if (vraag.Length < 10 || vraag.Length > 140) // check if it is of the right lenght
ModelState.AddModelError("", "De vraag moet minimaal 10 karakters lang zijn en maximaal 140 karakters lang zijn.");
if (ModelState.IsValid)
{
- // For cleaing up the spaces
+ // if all valid goon
+ // Take out all the unneeded stuff (for check in there is such a question)
char[] toTrim = new char[7] { '?', '.', ',', '!', ':', ';', '/' };
+ // trim these of the question
string vraagTrimmed = vraag.Trim(toTrim);
+ // and make it lower
vraagTrimmed = vraagTrimmed.ToLower();
List<Question> questionResultList = new List<Question>();
- // check the database for an existing somewhat simalair question
+ // remove all unneeded words from the string
string[] toSearch = StringFilter.Trim(vraagTrimmed);
foreach (string a in toSearch)
{
+ // now go through each word and check if there is a question containing this word
var questionsFound = from question in db.Questions
where question.Title.Contains(a)
select question;
+ // and add each to the list off results
foreach (Question abc in questionsFound)
questionResultList.Add(abc);
}
+ // give the results back grouped by the amount of times it showed up
ViewBag.SearchResults = from question in questionResultList
group question by question.QuestionID into qsorted
orderby qsorted.Count() descending
select qsorted.First();
+ // change this stuff so we go to the next page this time
ViewBag.ActionName = "nieuw";
ViewBag.ControllerName = "vraag";
}
@@ -299,13 +329,14 @@ public ActionResult Nieuw(Vraag info)
{
HTMLSanitizer hs = new HTMLSanitizer();
Markdown md = new Markdown();
-
+ // to mark the first time (meaning don't check the tags if there are some new ones)
bool firstTime = false;
+ // check where we came from
if (Request.UrlReferrer.LocalPath == "/vraag/check")
- firstTime = true;
- if (info.vraag == null)
+ firstTime = true; // set the first time if we came from there
+ if (info.vraag == null) // check if the question isn't empty
ModelState.AddModelError("", "Ga terug en voer een titel voor je vraag in.");
- else if (info.vraag != null && (info.tags == null || info.content == null) && !firstTime)
+ else if (info.vraag != null && (info.tags == null || info.content == null) && !firstTime) // check if all the fields are filled in
ModelState.AddModelError("", "Vul alle velden in aub.");
else if (!firstTime)
{
@@ -316,14 +347,16 @@ public ActionResult Nieuw(Vraag info)
if (tags.Count() > 5)
ModelState.AddModelError("", " U mag niet meer dan 5 tags meegeven.");
List<string> foundTags = new List<string>();
+ // check if the given tag exits in the datebase
foreach (string tag in tags)
{
var temp = from taggies in db.Tags
where taggies.Name.Contains(tag)
select taggies;
- if (temp.Count() == 0) // if a tag is in the database the above query should find it. Else it is a new one :D
+ // if a tag is in the database the above query should find it. Else it is a new one.
+ if (temp.Count() == 0) // not found add it to the list of new tags
tagsList.Add(tag);
- else
+ else // else mark it as one we have already
foundTags.Add(tag);
}
@@ -337,7 +370,7 @@ where taggies.Name.Contains(tag)
ModelState.AddModelError("", "U bent niet ingelogd."); // aan name dat de join lukt
ViewBag.LoggedIn = false;
}
- // add a check for the info class
+ // check if we got all new tags filled in and everything is valid
if ((tagsList.Count() - info.CountTagsSumbitted()) == 0 && ModelState.IsValid)
{
// add the stuff since we are done :D
@@ -346,12 +379,15 @@ where taggies.Name.Contains(tag)
var userPostingMeta = (from usermeta in db.UserMeta
where usermeta.UserId == UserID
select usermeta).Single();
+
+ // add each new tag to the database
for (int i = 0; i < tagsList.Count(); i++)
{
Tag newTag = new Tag() { Description = info.returnTagContent(i), Name = tagsList.ElementAt(i), Count = 1 };
userPostingMeta.Tags += 1;
db.Tags.Add(newTag);
}
+ // inceremnt the amount of questions that there are with this tag
foreach (string tagName in foundTags)
{
var tagAdd = from tagSelected in db.Tags
@@ -360,18 +396,25 @@ where tagSelected.Name.Contains(tagName)
tagAdd.First().Count += 1;
}
+ // add the amount of questions asked by this person with one
userPosting.First().Questions += 1;
UserMeta userInfo = userPosting.First();
-
+ // create the question
Question newQuestion = new Question() { Title = info.vraag, UserId = userInfo.UserId, Content = info.content };
+ // add it to the db
db.Questions.Add(newQuestion);
db.SaveChanges(); // to make sure that if there were new tags they are added propperly (so we can query the id's right)
+
+ // ####################################
+ // check if we got a new badge
+ // ####################################
if (TagBadge.badgeAchieve(userInfo.UserId))
TagBadge.awardBadge(userInfo.UserId);
if (TagCreatorBadge.badgeAchieve(userInfo.UserId))
TagCreatorBadge.awardBadge(userInfo.UserId);
if (TagLordBadge.badgeAchieve(userInfo.UserId))
TagLordBadge.awardBadge(userInfo.UserId);
+ // ####################################
// query back our last question
// should be the first of this list
@@ -381,6 +424,7 @@ where tagSelected.Name.Contains(tagName)
select questionAsked;
// query all the id's needed
Question justAskedQuestion = justAsked.First();
+ // foreach tag that there in on this question craete a tagID - QuestionID line
foreach (string tagje in tags)
{
// get the id and created an new QuestionTag for it
@@ -393,15 +437,20 @@ where tagIDje.Name.Contains(tagje)
db.QuestionTags.Add(newQuestTag);
}
db.SaveChanges();
+
+ // #################################
+ // Check if we got a new badge
+ // #################################
if (QuestionBadge.badgeAchieve(userInfo.UserId))
QuestionBadge.awardBadge(userInfo.UserId);
if (QuestionCreatorBadge.badgeAchieve(userInfo.UserId))
QuestionCreatorBadge.awardBadge(userInfo.UserId);
if (QuestionLordBadge.badgeAchieve(userInfo.UserId))
QuestionLordBadge.awardBadge(userInfo.UserId);
+ // #################################
+
+ // if we get here we are done :D so take us to our just asked question
return RedirectToAction("view", "vraag", new { id = justAskedQuestion.QuestionID });
- // Now add our question :D
- // and on done, go to the page showing our question :D
}
else
{
@@ -420,14 +469,18 @@ where tagIDje.Name.Contains(tagje)
// GET: /Vraag/Delete/ID
public ActionResult Delete(int id)
{
+ // check if we are logged in
if (User.Identity.IsAuthenticated)
{
+ // get our rank
int userRank = (from user in db.Users
where user.UserName == User.Identity.Name
select user.Rank).Single();
+ // get the question which we are trying to delete
var questionDelete = (from vraag in db.Questions
where vraag.QuestionID == id
select vraag);
+ // check if the rank is right and we got a right question
if (userRank >= 3 && questionDelete.Count() == 1)
{
// Allowed to delete a question
@@ -445,18 +498,23 @@ public ActionResult Delete(int id)
var questionTagsDelete = from questionTag in db.QuestionTags
where questionTag.QuestionId == id
select questionTag;
+ // get all the flaggs on this question
var flags = from flag in db.Flags
where flag.QuestionID == id
select flag;
+ // delete each
foreach (var flag in flags)
db.Flags.Remove(flag);
+ // get all the votes on the question
var votes = from vote in db.Votes
where vote.QuestionID == id
select vote;
+ // remove each
foreach (var vote in votes)
db.Votes.Remove(vote);
- // loop through them
+
+ // go through all the tags linking to this question
foreach (var vraagTag in questionTagsDelete)
{
// get the tag of this question
@@ -468,6 +526,7 @@ public ActionResult Delete(int id)
// remove this QuestionTag
db.QuestionTags.Remove(vraagTag);
}
+
// get all the awnsers given to this question
var antwoorden = from antwoord in db.Answers
where antwoord.QuestionId == id
@@ -479,19 +538,24 @@ public ActionResult Delete(int id)
var commentsOnAwnser = from comments in db.Comments
where comments.AnswerId == antwoordje.AnswerID
select comments;
+ // get all the votes on this answer
var answerVotes = from answerVote in db.Votes
where answerVote.AnswerID == antwoordje.AnswerID
select answerVote;
+ // delete those
foreach (var vote in answerVotes)
db.Votes.Remove(vote);
// delete each comment
foreach (var deleteComment in commentsOnAwnser)
{
+ // get all the flags on this comment
var flagsComment = from flagCom in db.Flags
where flagCom.CommentID == deleteComment.CommentID
select flagCom;
+ // delete each comment flag
foreach (var flag in flagsComment)
db.Flags.Remove(flag);
+ // remove the actual comment
db.Comments.Remove(deleteComment);
}
// get the stuff of the person who made this awnser
@@ -510,9 +574,11 @@ public ActionResult Delete(int id)
// Remove each one of them
foreach (var commentQuestion in questionComments)
{
+ // get the flags on this question
var flagsQuestion = from flagque in db.Flags
where flagque.CommentID == commentQuestion.CommentID
select flagque;
+ // delete those
db.Comments.Remove(commentQuestion);
}
// get the other stuff of the user who is deleting
@@ -527,8 +593,9 @@ public ActionResult Delete(int id)
Content = "De volgende vraag is verwijderd:"
+ questionToDelete.Title + ". \n\nIndien u vragen heeft over het verwijderen van dit bericht kunt u een reactie op dit bericht versturen. \n\nDit bericht is verwijderd door: "
+ userDeleting.UserName + " \n\nWe wensen u nog een fijne dag.", ReceiverId = questionToDelete.UserId, SenderId = userDeleting.UserID };
- // save the changes
+ // add the new message to the db
db.Messages.Add(newMessage);
+ // save the database
db.SaveChanges();
// show a succes message
ViewBag.Message = "De vraag is succesvol verwijderd.";
@@ -553,43 +620,46 @@ public ActionResult Delete(int id)
// GET: /vraag/VoteUp/QuestionID
public ActionResult VoteUp(int id)
{
- if (User.Identity.IsAuthenticated)
+ if (User.Identity.IsAuthenticated) // check if logged in
{
// get user stuff
var userVoiting = from userVote in db.Users
where userVote.UserName == User.Identity.Name
select userVote;
+ // get the info of the question which is getting the vote
var QuestionGettingVoted = from vraag in db.Questions
where vraag.QuestionID == id
select vraag;
-
+ // check if they yielded some info (and not more then one)
if (userVoiting.Count() == 1 && QuestionGettingVoted.Count() == 1)
{
var UserVoting = userVoiting.First();
// check if this is a up vote or a second time vote (so downvote)
var voteInfo = from vote in db.Votes
where vote.UserID == UserVoting.UserID && vote.QuestionID == id
select vote;
+ // cast this question to a single so we can do somestuff
var Question = QuestionGettingVoted.First();
+ // get the info of the person which made this question
var userGettingVoted = from user in db.UserMeta
where user.UserId == Question.UserId
select user;
- if (voteInfo.Count() == 1)
+ if (voteInfo.Count() == 1) // if so we are downvotting
{
- // downvote :<
+ // remove the vote from the datebase
db.Votes.Remove(voteInfo.First());
- Question.Votes -= 1;
- userGettingVoted.First().Votes -= 1;
- db.SaveChanges();
+ Question.Votes -= 1; // lower the votes on this question
+ userGettingVoted.First().Votes -= 1; // and on the user
+ db.SaveChanges(); // save
}
- else
+ else // else we are upvoting (firsttime)
{
- // upvote
+ // create a new vote
VoteUser newVote = new VoteUser() { QuestionID = Question.QuestionID, UserID = UserVoting.UserID };
- Question.Votes += 1;
- userGettingVoted.First().Votes += 1;
- db.Votes.Add(newVote);
- db.SaveChanges();
+ Question.Votes += 1; // increase the votes on this question with one
+ userGettingVoted.First().Votes += 1; // and the user that made this question
+ db.Votes.Add(newVote); // add the vote to the db
+ db.SaveChanges(); // save
}
}
else
@@ -598,6 +668,7 @@ public ActionResult VoteUp(int id)
else
ModelState.AddModelError("", "Je moet ingelogd zijn om te stemmen.");
+ // redirect us to the right page
if (!Request.UrlReferrer.AbsolutePath.Contains("vraag"))
return RedirectToAction("index", "default");
else
@@ -606,47 +677,55 @@ public ActionResult VoteUp(int id)
//
// GET: vraag/flagvraag/QuestionID
+ // om een vraag to flagged als slecht
public ActionResult FlagVraag(int id)
{
+ // check if we are logged in
if (User.Identity.IsAuthenticated)
{
+ // get the stuff of the user hitting the flag button
var UserFlagging = from usr in db.Users
where usr.UserName == User.Identity.Name
select usr;
+ // get the stuff of the question getting (un)flagged
var questionGettingFlagged = from question in db.Questions
where question.QuestionID == id
select question;
+ // check if we got some stuff back
if (UserFlagging.Count() == 1 && questionGettingFlagged.Count() == 1)
{
+ // cast it to a single
var user = UserFlagging.First();
var question = questionGettingFlagged.First();
+
+ // check if we got a flag on this by this user
var flagged = from flag in db.Flags
where flag.QuestionID == id && flag.UserID == user.UserID
select flag;
- if (flagged.Count() == 1)
+ if (flagged.Count() == 1) // if so we are unflagging
{
- // unflag
- db.Flags.Remove(flagged.First());
+ db.Flags.Remove(flagged.First()); // remove this flag
db.SaveChanges();
+ // get the flags left on this question
var totalFlags = from flags in db.Flags
where flags.QuestionID == id
select flags;
- if (totalFlags.Count() == 0)
+ if (totalFlags.Count() == 0) // if this equals 0 then mark the question as not flagged
{
- // if there are no longer
question.Flag = 0;
db.SaveChanges();
}
}
- else
+ else // else we are flagging a question
{
- // flag
question.Flag = 1;
+ // create a new flag
db.Flags.Add(new Flag() { QuestionID = question.QuestionID, UserID = user.UserID });
db.SaveChanges();
}
}
}
+ // get us back to the page we came from
if (!Request.UrlReferrer.AbsolutePath.Contains("vraag"))
return RedirectToAction("index", "default");
else
View
2 Source/NHLStackOverflow/Controllers/WidgetController.cs
@@ -55,9 +55,11 @@ public ViewResult Account()
public ViewResult Tags()
{
+ // get a list of all the tags
var TagsList = from tags in db.Tags
orderby tags.Count descending
select tags;
+ // and take the top 20 tags
ViewBag.TagList = TagsList.Take(20);
return View();
View
4 Source/NHLStackOverflow/Mailers/IUserMailer.cs
@@ -4,10 +4,8 @@ namespace NHLStackOverflow.Mailers
{
public interface IUserMailer
{
-
+ // what we give along when we create a mail
MailMessage MailConfirm(string link, string email);
MailMessage MailPassForgotten(string link, string email);
-
-
}
}
View
15 Source/NHLStackOverflow/Mailers/UserMailer.cs
@@ -15,21 +15,28 @@ public class UserMailer : MailerBase, IUserMailer
public virtual MailMessage MailConfirm(string link, string email)
{
- var mailMessage = new MailMessage { Subject = "Account registratie bevestigen - Question Jamw", Body = link };
+ // create the variables which we give allong
+ var mailMessage = new MailMessage { Subject = "Account registratie bevestigen - Question Jam", Body = link };
+ // add the email adress to the message
mailMessage.To.Add(email);
- //ViewBag.Data = someObject;
- ViewBag.WebLink = link;
+ ViewBag.WebLink = link; // add the link to it
+ // create the actual email
PopulateBody(mailMessage, viewName: "MailConfirm");
-
+ // and return this
return mailMessage;
}
public virtual MailMessage MailPassForgotten(string link, string email)
{
+ // create the variables which we give allong
var mailMessage = new MailMessage { Subject = "Wachtwoord vergeten - Question Jam", Body = link };
+
+ // add the email adress to the message
mailMessage.To.Add(email);
+ // give along the link
ViewBag.Link = link;
+ // create the actual email
PopulateBody(mailMessage, viewName: "MailPassForgotten");
return mailMessage;
View
111 Source/NHLStackOverflow/NHLStackOverflow.Publish.xml
@@ -1,50 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<publishData>
- <publishProfile publishUrl="ftp://mijnnhl.org" deleteExistingFiles="True" ftpAnonymousLogin="False" ftpPassiveMode="True" msdeploySite="NHLStackOverflow" msdeploySiteID="" msdeployRemoteSitePhysicalPath="" msdeployAllowUntrustedCertificate="False" msdeploySkipExtraFilesOnServer="True" msdeployMarkAsApp="False" profileName="WebDeploy" publishMethod="FTP" replaceMatchingFiles="False" userName="mijnnhl5" savePWD="True" userPWD="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA+K57BTs7xU2ZA1xOYY98rQAAAAACAAAAAAAQZgAAAAEAACAAAAA8FgYM6l2kehIwefrdaAcnOQFGz/oHS+lgGbNTULkF0QAAAAAOgAAAAAIAACAAAACnbCk9KUk8TQYUSXx+TIm3KLwO4siyiNDNq+2XLb3K8yAAAAAqvjwsLSy3AWQXOqeUKuuKwM+XV/MFUuFclz5QVUS250AAAAAwWFAZdkEJ+GK+tfaPoZYDLjvd3MP6rXzpHekGs6q0UTMNntlxTe4j6cygQ2aZT8HXiPiom0FjKpSmDLHLBvwk" SelectedForPublish="True">
- <file relUrl="Views/Login/WachtwoordVeranderd.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Registreer/index.cshtml" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Views/Tags/Index.cshtml" publishTime="03/13/2012 20:29:07" />
- <file relUrl="Views/Login/KwijtVeranderen.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Scripts/script.js" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Views/Shared/_NavPartial.cshtml" publishTime="03/13/2012 20:29:07" />
- <file relUrl="Styles/check.png" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Views/Layouts/_Main.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Default/Index.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Web.config" publishTime="03/14/2012 09:45:11" />
- <file relUrl="Views/Login/Index.cshtml" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Views/Shared/_LogInPartial.cshtml" publishTime="03/13/2012 20:29:07" />
- <file relUrl="Views/Widget/Account.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Scripts/modernizr.js" publishTime="03/04/2012 14:41:27" />
- <file relUrl="Views/Widget/Tags.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Registreer/Gelukt.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Vraag/View.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="bin/EntityFramework.xml" publishTime="03/12/2012 20:39:17" />
- <file relUrl="Views/Shared/_TagsPartial.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Tags/Search.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/User/Instellingen.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="packages.config" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/Layouts/_Login.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="Views/User/Admin.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Views/Login/WachtwoordKwijt.cshtml" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Views/User/Index.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Views/Layouts/_User.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Views/Shared/Error.cshtml" publishTime="03/04/2012 14:41:27" />
- <file relUrl="Views/User/View.cshtml" publishTime="03/14/2012 08:46:22" />
- <file relUrl="bin/NHLStackOverflow.dll" publishTime="03/14/2012 09:49:09" />
- <file relUrl="Global.asax" publishTime="03/04/2012 14:41:27" />
- <file relUrl="Views/Web.config" publishTime="03/04/2012 14:41:27" />
- <file relUrl="Views/Widget/User.cshtml" publishTime="03/13/2012 12:22:30" />
- <file relUrl="bin/EntityFramework.dll" publishTime="03/12/2012 20:39:17" />
- <file relUrl="Styles/seen.png" publishTime="03/12/2012 15:55:18" />
- <file relUrl="bin/mysql.data.dll" publishTime="03/05/2012 14:19:08" />
- <file relUrl="Views/Registreer/activeren.cshtml" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Styles/logo.png" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Views/_ViewStart.cshtml" publishTime="03/12/2012 15:55:18" />
- <file relUrl="Styles/aplus.png" publishTime="03/12/2012 15:55:18" />
- <file relUrl="bin/MySql.Web.dll" publishTime="03/05/2012 14:19:08" />
- <file relUrl="Styles/style.css" publishTime="03/14/2012 08:46:22" />
- <file relUrl="Styles/dot.png" publishTime="03/12/2012 15:55:18" />
- <file relUrl="bin/MySql.Data.Entity.dll" publishTime="03/05/2012 14:19:10" />
- <file relUrl="Views/Shared/_QuestionsPartial.cshtml" publishTime="03/13/2012 20:29:11" />
+ <publishProfile publishUrl="ftp://mijnnhl.org" deleteExistingFiles="True" ftpAnonymousLogin="False" ftpPassiveMode="True" msdeploySite="NHLStackOverflow" msdeploySiteID="" msdeployRemoteSitePhysicalPath="" msdeployAllowUntrustedCertificate="False" msdeploySkipExtraFilesOnServer="True" msdeployMarkAsApp="False" profileName="WebDeploy" publishMethod="FTP" replaceMatchingFiles="False" userName="mijnnhl5" savePWD="True" userPWD="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAtrN9Y6+1r0mBQOcz9Xr9YwAAAAACAAAAAAAQZgAAAAEAACAAAADBiYvAueFq9RvYvQ5eMm//MDqcrmDx5kcThtVyZFo0sAAAAAAOgAAAAAIAACAAAAA1Y1R8KbGK+T2NtwS/k+d0V2uVl/02pnhTbzJ6ib5ZVyAAAAAkAzaI71AJG7jL6JmnJIeNZJ0I+Xb7cUwDdrpHpU7KNEAAAADzROGLxIFHokVVAa9oKWTPUamBVSKf0h2bDhkb0CmoQ/pKCdeS77UAhwm00QW6oSBb5Mz2RUd0geiEeFFhQxvC" SelectedForPublish="True">
+ <file relUrl="Views/Login/WachtwoordVeranderd.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/Registreer/index.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/Tags/Index.cshtml" publishTime="03/28/2012 09:11:24" />
+ <file relUrl="Views/Login/KwijtVeranderen.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="bin/NHLStackOverflow.dll" publishTime="03/29/2012 08:49:16" />
+ <file relUrl="Scripts/script.js" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Profiel/Overzicht.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Vraag/Nieuw.cshtml" publishTime="03/20/2012 10:47:57" />
+ <file relUrl="Scripts/lib.js" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Layouts/_Main.cshtml" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Default/Index.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Web.config" publishTime="03/29/2012 08:46:10" />
+ <file relUrl="Views/Login/Index.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/Shared/_LogInPartial.cshtml" publishTime="03/16/2012 09:58:20" />
+ <file relUrl="Scripts/script-user.js" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Badge/Index.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Widget/Account.cshtml" publishTime="03/28/2012 16:58:27" />
+ <file relUrl="Views/Badge/Search.cshtml" publishTime="03/28/2012 09:11:24" />
+ <file relUrl="Views/Widget/Tags.cshtml" publishTime="03/28/2012 09:11:24" />
+ <file relUrl="bin/Mvc.Mailer.dll" publishTime="03/20/2012 10:56:11" />
+ <file relUrl="Views/Registreer/Gelukt.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/UserMailer/MailPassForgotten.cshtml" publishTime="03/20/2012 13:45:06" />
+ <file relUrl="Views/Vraag/View.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Scripts/script-login.js" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="bin/EntityFramework.xml" publishTime="03/13/2012 09:09:48" />
+ <file relUrl="Views/User/Instellingen.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Shared/_TagsPartial.cshtml" publishTime="03/16/2012 09:58:20" />
+ <file relUrl="Views/Tags/Search.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/UserMailer/_Layout.cshtml" publishTime="03/20/2012 11:02:15" />
+ <file relUrl="Views/Login/KwijtVerstuurd.cshtml" publishTime="03/20/2012 13:54:36" />
+ <file relUrl="Views/User/Reply.cshtml" publishTime="03/28/2012 09:46:41" />
+ <file relUrl="Views/User/Beheer.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="packages.config" publishTime="03/20/2012 10:56:20" />
+ <file relUrl="Views/Layouts/_Login.cshtml" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/User/Inbox.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Login/WachtwoordKwijt.cshtml" publishTime="03/12/2012 13:58:25" />
+ <file relUrl="Views/User/Index.cshtml" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Layouts/_User.cshtml" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Shared/Error.cshtml" publishTime="03/05/2012 15:19:23" />
+ <file relUrl="Scripts/modernizr.js" publishTime="03/05/2012 15:19:23" />
+ <file relUrl="bin/NHLStackOverflow.pdb" publishTime="03/29/2012 08:49:16" />
+ <file relUrl="Views/User/View.cshtml" publishTime="03/19/2012 08:31:45" />
+ <file relUrl="Views/Shared/_NavPartial.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/User/ViewMail.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Shared/_QuestionsPartial.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Web.config" publishTime="03/20/2012 10:56:18" />
+ <file relUrl="Views/Widget/User.cshtml" publishTime="03/28/2012 09:11:24" />
+ <file relUrl="Scripts/script-main.js" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Views/UserMailer/MailConfirm.cshtml" publishTime="03/28/2012 11:00:45" />
+ <file relUrl="bin/EntityFramework.dll" publishTime="03/13/2012 09:09:48" />
+ <file relUrl="Views/Registreer/ActiverenGelukt.cshtml" publishTime="03/20/2012 16:09:40" />
+ <file relUrl="Views/Registreer/activeren.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Styles/logo.png" publishTime="03/07/2012 14:21:48" />
+ <file relUrl="Views/_ViewStart.cshtml" publishTime="03/21/2012 16:40:17" />
+ <file relUrl="Styles/aplus.png" publishTime="03/12/2012 13:58:25" />
+ <file relUrl="scaffolding.config" publishTime="03/20/2012 11:15:10" />
+ <file relUrl="Views/Profiel/Index.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Views/Vraag/Check.cshtml" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Styles/style.css" publishTime="03/29/2012 08:32:23" />
+ <file relUrl="Styles/check.png" publishTime="03/12/2012 13:58:25" />
+ <file relUrl="Styles/dot.png" publishTime="03/07/2012 14:21:48" />
+ <file relUrl="Global.asax" publishTime="03/05/2012 15:19:23" />
+ <file relUrl="Views/User/MaakBericht.cshtml" publishTime="03/28/2012 10:02:07" />
+ <file relUrl="Styles/seen.png" publishTime="03/12/2012 13:58:25" />
</publishProfile>
</publishData>
View
1 Source/NHLStackOverflow/NHLStackOverflow.csproj
@@ -89,7 +89,6 @@
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Classes\AbstractBadge.cs" />
<Compile Include="Classes\BadgeCount.cs" />
<Compile Include="Classes\HTMLSanitizer.cs" />
<Compile Include="Classes\Markdown.cs" />
View
2 Source/NHLStackOverflow/Views/Tags/Search.cshtml
@@ -1,5 +1,5 @@
@{
- ViewBag.Title = "Tag: " + ViewBag.TagName + " - Question Jam";
+ ViewBag.Title = "Tag: " + ViewBag.TagNames.Name + " - Question Jam";
if (Request.Headers["X-PJAX"] == null) {
Layout = "~/Views/Layouts/_Main.cshtml";
ViewBag.TitleTag = null;
View
5 Source/NHLStackOverflow/Views/UserMailer/MailConfirm.cshtml
@@ -1,5 +1,6 @@
<p>U bent aangemeld voor de site QuestionJam met dit email adres.<br />
Om uw account in gebruik te nemen dient u op de onderstaande link te klikken of deze te kopieren naar de adresbalk van uw browser</p>
-
+@*
@Html.ActionLink("Klik hier om te activeren", "activeren", "registreer", new { id = ViewBag.WebLink }, "")
-localhost/registreer/activeren/@ViewBag.WebLink
+*@
+<a href="http://localhost:16868/registreer/activeren/@ViewBag.WebLink">http://localhost:16868/registreer/activeren/@ViewBag.WebLink</a>
View
2 Source/NHLStackOverflow/Views/UserMailer/MailPassForgotten.cshtml
@@ -1,3 +1,3 @@
<p>Klik op de volgende link om uw wachtwoord te resetten.</p>
-@ViewBag.Link
+<a href="http://localhost:16868/login/kwijtveranderen/@ViewBag.Link">http://localhost:16868/login/kwijtveranderen/@ViewBag.Link</a>

0 comments on commit 076e6db

Please sign in to comment.