Пример #1
0
        private void MakeVote(int votes)
        {
            try
            {
                Guid session = new Guid();
                //we've never seen this user before or they've cleared their cookies
                if (Request.Cookies["session"] != null && Guid.TryParse(Request.Cookies["session"].Value, out session))
                {
                    int userID = Auth.checkSession(session);
                    if (userID != 0)
                    {
                        try
                        {
                            Regex  reg      = new Regex(Settings.Default.WikiTitleRegex);
                            string urlmatch = reg.Match(Request["Article"]).Groups[2].Value;
                            if (urlmatch.EndsWith("noui"))
                            {
                                urlmatch = urlmatch.Substring(0, urlmatch.Length - 4);
                            }

                            DataClassesDataContext dc = new DataClassesDataContext();
                            dc.AddRating(userID, urlmatch, votes, DateTime.Now);
                            Auth.CreateEvent("New Vote Added", Auth.LookupUserName(userID) + " rated " +
                                             urlmatch + " a " + votes, Request.UserHostAddress);
                            UserRating.Text = votes.ToString();
                            if (RatingExists(urlmatch))
                            {
                                int rating = LookupRating(urlmatch);
                                WikiRaterRating.Text = "WikiRater would have rated this article: " + rating + "<br />";
                            }
                            else
                            {
                                try
                                {
                                    Article art = new Article(urlmatch);
                                    if (art.rating > 0)
                                    {
                                        WikiRaterRating.Text = "WikiRater would have rated this article: " + art.rating.ToString() + "<br />";
                                        SaveRating(urlmatch, art.rating);
                                    }
                                    else
                                    {
                                        WikiRaterRating.Visible = false;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Auth.CreateEvent("Could Not Rate Article: " + ex.Message, "by: " + Auth.LookupUserName(userID) + "\r\n" + ex.ToString(), Request.UserHostAddress);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Auth.CreateEvent("Could Not Add Rating: " + ex.Message, "by: " + Auth.LookupUserName(userID) + "\r\n" + ex.ToString(), Request.UserHostAddress);
                        }

                        CheckAndPopulateAchievements(userID);


                        VotePanel.Visible          = false;
                        VoteCompletedPanel.Visible = true;
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Auth.CreateEvent("Could Not Add Rating:" + ex.Message, ex.ToString(), Request.UserHostAddress);
                Response.Redirect("Login.aspx");
            }
        }
Пример #2
0
 private void SaveRating(string title, int value)
 {
     dc.AddRating(dc.Users.First(u => u.UserName == Settings.Default.WikiRaterName).UserID,
                  title, value, DateTime.Now);
 }