public ActionResult Make(string author, string comment, string url) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath("~") + @"\LogFreeSpeechLoad.txt", true)) { file.Write(author + "," + comment + "," + url); } FREECOMMENT freecomment = new FREECOMMENT { AUTHOR = author, COMMENT = comment, FREEURL = url }; try { _echoDb.FREECOMMENTs.Add(freecomment); _echoDb.SaveChanges(); return(Json("done")); } catch (Exception exception) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath("~") + @"\LogFreeSpeechLoad.txt", true)) { file.Write(exception.Message); } return(Json("error")); } }
public ActionResult Load(string userId, string url) { try { using (System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath("~") + @"\LogFreeSpeechLoad.txt", true)) { file.Write(url); } FREECOMMENT f = new FREECOMMENT(); int UserId = int.Parse(userId); var allFreeComment = _echoDb.FREECOMMENTs.Where(p => p.FREEURL == url).Select(p => new{ p.ID, p.COMMENT, p.AUTHOR, p.FREEURL, LIKES = _echoDb.FREEVOTEs.Count(n => n.CommentId == p.ID), LIKED = _echoDb.FREEVOTEs.Any(m => m.UserId == UserId && m.CommentId == p.ID) }).OrderBy(v => v.LIKES).ToList(); return (Json(allFreeComment)); } catch (Exception) { return(Json("error")); } }