public static int UserRating(int rating) { OKDbEntities Db = new OKDbEntities(); int totalpoint = 0; var items = Db.user.Where(x => x.Rating >= 500 && x.IsBanned == false); int average; if (items.Count() == 0) { var itemm = Db.user.Where(x => x.IsBanned == false); foreach (var item in itemm) { totalpoint += Convert.ToInt32(item.Rating); } average = totalpoint / itemm.Count(); } else { foreach (var item in items) { totalpoint += Convert.ToInt32(item.Rating); } average = totalpoint / items.Count(); } int point = rating * 3 / average; return(point > 5 ? 5 : point); }
public static int RatingScore(int id, string type, int userid) { OKDbEntities Db = new OKDbEntities(); var rating = Db.rating.SingleOrDefault(x => x.ItemId == id && x.UserId == userid && x.Type == type); return(rating == null ? 0 : Convert.ToInt32(rating.Score)); }
public static string UserState(int id, DateTime lastlogin) { OKDbEntities Db = new OKDbEntities(); TimeSpan ts = DateTime.Now - lastlogin; return(ts.Minutes <= 5 ? "online" : "offline"); }
protected void Session_Start() { Session["memberid"] = 0; Session["memberrole"] = "0"; Session["memberinfo"] = null; if (Session["userinfo"] == null && Request.Cookies["OK_password"] != null) { int userid = Convert.ToInt32(Request.Cookies["OK_userid"].Value); string password = Request.Cookies["OK_password"].Value; OKDbEntities Db = new OKDbEntities(); var user = Db.user.SingleOrDefault(x => x.Id == userid && x.Password == password); if (user != null) { Session["userinfo"] = user; Session["userid"] = user.Id; Session["role"] = 10; //user.TypeId.ToString(); } Db.Dispose(); } else if (Session["userinfo"] == null) { Session["role"] = 0; Session["userid"] = 0; } }
public static void UpdateRating(int id, int score) { OKDbEntities Db = new OKDbEntities(); var user = Db.user.Find(id); user.Rating += score; Db.SaveChanges(); }
public static void DeletePost(int userid, string itemid, string type) { OKDbEntities Db = new OKDbEntities(); var post = Db.post.SingleOrDefault(x => x.UserId == userid && x.ItemId == itemid && x.Type == type); if (post != null) { Db.post.Remove(post); } Db.SaveChanges(); }
public static void ChangePostApproval(int userid, string itemid, string type, bool isapproval) { OKDbEntities Db = new OKDbEntities(); var post = Db.post.SingleOrDefault(x => x.UserId == userid && x.ItemId == itemid && x.Type == type); if (post != null) { post.IsApproval = isapproval; } Db.SaveChanges(); }
public static void AddPost(int userid, string itemid, string type, bool isapproval) { OKDbEntities Db = new OKDbEntities(); post post = new post(); post.UserId = userid; post.ItemId = itemid; post.Type = type; post.CreationDate = DateTime.Now; post.IsApproval = isapproval; Db.post.Add(post); Db.SaveChanges(); }
public static MvcHtmlString UserInfo(this HtmlHelper html, int id) { OKDbEntities Db = new OKDbEntities(); string result = ""; UrlHelper url = new UrlHelper(html.ViewContext.RequestContext, html.RouteCollection); var user = Db.user.Single(x => x.Id == id); result = "<div class=\"image\" onclick=\"$.OK.Modal('" + url.Action("UserInfo", "Account", new { id = id }) + "');\"><img src=\"" + user.ImageFile + "\" /></div>" + "<div class=\"name\" onclick=\"$.OK.Modal('" + url.Action("UserInfo", "Account", new { id = id }) + "');\">" + OK.UserName(user) + "<img src=\"" + url.Content("~/Areas/Forum/Themes/" + OK.Config("site-theme") + "/Images/" + OK.UserState(user.Id, (DateTime)user.LastLoginDate) + ".png") + "\" /></div>" + "<div class=\"level\">" + user.type.Name + "</div>" + "<div class=\"rating\">" + html.UserRating((int)user.Rating) + "</div>"; return(MvcHtmlString.Create("<div class=\"user-info\">" + result + "</div>")); }
public static string Config(string key) { OKDbEntities Db = new OKDbEntities(); var config = Db.config.SingleOrDefault(x => x.Key == key); if (config != null) { return(config.Value); } else { return(null); } }
public static void SendEmail(string email, string title, string content) { try { string emailfrom = "*****@*****.**"; content = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body>" + content + "</body></html>"; OKDbEntities Db = new OKDbEntities(); SmtpClient client = new SmtpClient(Config("smtp-server"), Convert.ToInt32(Config("smtp-port"))); client.EnableSsl = true; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(Config("smtp-username"), Config("smtp-password")); MailMessage message = new MailMessage(emailfrom, email, title, content); message.IsBodyHtml = true; client.Send(message); } catch { } }
public static IEnumerable <topic> RelatedTopics(topic topic) { OKDbEntities Db = new OKDbEntities(); string sql = ""; string[] split = topic.Seo.Split('-'); for (int i = 0; i < split.Count(); i++) { sql += "Seo like '%" + ConvertSeo(split[i]) + "%' || "; } sql = sql.Substring(0, sql.Length - 3); Random random = new Random(); var topics = Db.topic.SqlQuery("Select * from topic where IsApproval = '1' and Id != '" + topic.Id + "' and (" + sql + ") order by ModifyDate desc").Take(5); for (int i = 0; i < 5 - topics.Count(); i++) { int skip = random.Next(0, Db.topic.Where(x => x.IsApproval == true).Count()); topics = topics.Concat(Db.topic.Where(x => x.IsApproval == true && x.Id != topic.Id).OrderByDescending(x => x.ModifyDate).Skip(skip).Take(1)); } return(topics.ToList()); }
public static MvcHtmlString ViewComment(this HtmlHelper html, comment comment) { UrlHelper url = new UrlHelper(html.ViewContext.RequestContext, html.RouteCollection); string result = ""; string quote = comment.QuoteId; if (!string.IsNullOrEmpty(quote)) { OKDbEntities Db = new OKDbEntities(); int id = Convert.ToInt32(quote.Split('-')[1]); if (quote.Split('-')[0] == "t") { var quotetopic = Db.topic.Find(id); result = "<div style=\"max-height: 300px; overflow-x: hidden; overflow-y: scroll;\"><blockquote><b>" + OK.UserName(quotetopic.user) + "</b>, <small>" + html.ShortDateTime((DateTime)quotetopic.CreationDate) + "</small><small style=\"float: right;\"><a href=\"" + url.Action("GoTopic", new { id = quotetopic.Id }) + "\">Konuya Git</a></small><div class=\"comment\">" + html.ViewTopic(quotetopic.Content) + "</blockquote></div>"; } else { var quotecomment = Db.comment.Find(id); result = "<div style=\"max-height: 300px; overflow-x: hidden; overflow-y: scroll;\"><blockquote><b>" + OK.UserName(quotecomment.user) + "</b>, <small>" + html.ShortDateTime((DateTime)quotecomment.CreationDate) + "</small><small style=\"float: right;\"><a href=\"" + url.Action("GoComment", new { id = quotecomment.Id }) + "\">Cevaba Git</a></small><div class=\"comment\">" + html.ViewComment(quotecomment) + "</blockquote></div>"; } } result += comment.Content; return(MvcHtmlString.Create(result.ToString())); }
public static topic NextTopic(int id) { OKDbEntities Db = new OKDbEntities(); return((topic)(Db.topic.Where(x => x.IsApproval == true && x.Id > id).FirstOrDefault())); }
public static topic PreviousTopic(int id) { OKDbEntities Db = new OKDbEntities(); return((topic)(Db.topic.Where(x => x.IsApproval == true && x.Id < id).OrderByDescending(x => x.Id).FirstOrDefault())); }
public static IEnumerable <topic> SortTopics(IEnumerable <topic> topics) { OKDbEntities Db = new OKDbEntities(); int day = HttpContext.Current.Request.QueryString["day"] == null ? 0 : Convert.ToInt32(HttpContext.Current.Request.QueryString["day"]); string sort = HttpContext.Current.Request.QueryString["sort"]; string order = HttpContext.Current.Request.QueryString["order"] == "asc" ? "asc" : "desc"; DateTime dt = DateTime.Now.AddDays(-1 * day); if (order == "asc") { if (sort == "title") { topics = topics.OrderBy(x => x.Title); } else if (sort == "writer") { topics = topics.OrderBy(x => UserName(x.user)); } else if (sort == "date") { topics = topics.OrderBy(x => x.ModifyDate); } else if (sort == "comments") { topics = topics.OrderBy(x => x.comments.Where(y => y.IsApproval == true).Count()); } else if (sort == "views") { topics = topics.OrderBy(x => x.ViewsCount); } else if (sort == "lastcomment") { topics = topics.OrderBy(x => LastComment(x) == null ? 0 : ((TimeSpan)(DateTime.Now - LastComment(x).CreationDate)).TotalDays); } else { topics = topics.OrderBy(x => 0.3 * x.ViewsCount + 0.3 * Convert.ToInt32(Convert.ToDateTime(x.ModifyDate).Day) + 0.2 * x.comments.Where(y => y.IsApproval == true).Count() + 0.1 * (Convert.ToInt32(x.Rating.Split('/')[0]) - Convert.ToInt32(x.Rating.Split('/')[1]))); } } else { if (sort == "title") { topics = topics.OrderBy(x => x.Title); } else if (sort == "writer") { topics = topics.OrderByDescending(x => UserName(x.user)); } else if (sort == "date") { topics = topics.OrderByDescending(x => x.ModifyDate); } else if (sort == "comments") { topics = topics.OrderByDescending(x => x.comments.Where(y => y.IsApproval == true).Count()); } else if (sort == "views") { topics = topics.OrderByDescending(x => x.ViewsCount); } else if (sort == "lastcomment") { topics = topics.OrderByDescending(x => LastComment(x) == null ? 0 : ((TimeSpan)(DateTime.Now - LastComment(x).CreationDate)).TotalDays); } else { topics = topics.OrderByDescending(x => 0.2 * x.ViewsCount + 0.6 * Convert.ToInt32(Convert.ToDateTime(x.ModifyDate).Day) + 0.1 * x.comments.Where(y => y.IsApproval == true).Count() + 0.05 * (Convert.ToInt32(x.Rating.Split('/')[0]) - Convert.ToInt32(x.Rating.Split('/')[1])) + 0.05 * x.user.Rating); } } return(topics.Where(x => x.IsApproval == true && x.forum.IsApproval == true && x.forum.category.IsApproval == true && day != 0 ? x.CreationDate > dt : true).ToList()); }