public PartialViewResult AddChildCommentEvent(int idOfParentId, string content) { if (SpamDetector.IsContentSpam(content)) { return(null); } var parentComment = context.CommentEvents.Find(idOfParentId); GamingEvent gameEvent = context.GamingEvents.Where(a => a.GamingEventId == parentComment.GamingEventId).First(); ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } CommentEvent commentEvent = new CommentEvent() { Body = content, DateOfInsert = DateTime.Now, GamingEventId = gameEvent.GamingEventId, UserId = User.Identity.GetUserId(), User = user, ParentCommentEventId = parentComment.CommentEventId, Parent = parentComment }; var sentimentalInt = new SentimentalInterpreter(); var isContentHappy = sentimentalInt.IsHappy(commentEvent.Body); if (isContentHappy) { commentEvent.IsHappy = true; } parentComment.Children.Add(commentEvent); context.CommentEvents.Add(commentEvent); context.SaveChanges(); CurrentCommentGameEventViewModel vm = new CurrentCommentGameEventViewModel { LoggedUser = user, Com = parentComment }; if (vm.Com.Children != null && vm.Com.Children.Count > 1) { vm.Com.Children = vm.Com.Children.OrderBy(a => a.DateOfInsert).ToList(); } return(PartialView("~/Views/GamingEvent/_ChildrenComments.cshtml", vm)); }
public ActionResult SaveEvent(EventCategoryViewModel vm, HttpPostedFileBase file, string newItem = null) { if (SpamDetector.IsContentSpam(vm.GamingEvent.Title)) { return(RedirectToAction("Index", "Post")); } //Verify whether user has neccessary data ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } int idd = vm.GamingEvent.GamingEventId; var gameEvent = vm.GamingEvent; if (file != null && file.ContentLength > 0) { if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png") { var sourceImage = Image.FromStream(file.InputStream); sourceImage = ResizeImage(sourceImage, 500, 500); //Generowanie plik var fileExt = Path.GetExtension(file.FileName); var filename = Guid.NewGuid() + fileExt; // Unikalny identyfikator + rozszerzenie //W jakim folderze ma byc umiesczony dany plik oraz jego nazwa! Oraz zapis var path = Path.Combine(Server.MapPath(AppConfig.ImagesGamingEventFolder), filename); //file.SaveAs(path); sourceImage.Save(path); gameEvent.MainPicture = filename; } } else if (file == null && newItem != null && newItem != String.Empty) { var fractImg = FractalGenerator.GenereateFractal1(user.Email); var filename = Guid.NewGuid() + ".jpg"; var path = Path.Combine(Server.MapPath(AppConfig.ImagesGamingEventFolder), filename); fractImg.Save(path); gameEvent.MainPicture = filename; } gameEvent.UserId = user.Id; gameEvent.Publisher = user; context.GamingEvents.AddOrUpdate(gameEvent); context.SaveChanges(); return(RedirectToAction("Events", "Manage")); }
public PartialViewResult AddComment(int gamingEventId, string content) { if (SpamDetector.IsContentSpam(content)) { return(null); } var gameEvent = context.GamingEvents.Where(a => a.GamingEventId == gamingEventId).First(); ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } CommentEvent commentEvent = new CommentEvent() { Body = content, DateOfInsert = DateTime.Now, GamingEventId = gameEvent.GamingEventId, UserId = User.Identity.GetUserId(), User = user }; var sentimentalInt = new SentimentalInterpreter(); var isContentHappy = sentimentalInt.IsHappy(commentEvent.Body); if (isContentHappy) { commentEvent.IsHappy = true; } context.CommentEvents.Add(commentEvent); context.SaveChanges(); gameEvent.Comments.Add(commentEvent); CurrentGameEventUserViewModel vm = new CurrentGameEventUserViewModel { LoggedUser = user, GamingEvent = gameEvent }; vm.GamingEvent.Comments = vm.GamingEvent.Comments.OrderBy(a => a.DateOfInsert).ToList(); return(PartialView("_ListOfComments", vm)); }
public PartialViewResult ReplyToQuestion(int questionId, string reply) { if (SpamDetector.IsContentSpam(reply)) { return(null); } Question question = context.Questions.Where(a => a.QuestionId == questionId).First(); ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } question.isReadedByReceiver = true; question.isReadedBySender = false; question.ReplyContent = reply; question.ReplyDate = DateTime.Now; context.SaveChanges(); return(PartialView("_Questions", question.Game.Questions)); }
public PartialViewResult AskQuestion(int gameId, string question) { if (SpamDetector.IsContentSpam(question)) { return(null); } Game game = context.Games.Where(a => a.GameId == gameId).First(); ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } var qs = new Question() { UserId = id, Sender = user, GameId = game.GameId, Game = game, QuestionContent = question, ReplyContent = "", isReadedBySender = true, isReadedByReceiver = false, QuestionDate = DateTime.Now, ReplyDate = DateTime.Now }; context.Questions.Add(qs); game.Questions.Add(qs); user.Questions.Add(qs); context.SaveChanges(); return(PartialView("_Questions", game.Questions)); }
// GET: Message public string SendMessage(string content, string userName) { if (SpamDetector.IsContentSpam(content)) { return(null); } ApplicationUser user = null; string id = GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } ApplicationUser Receiveruser = context.Users.Where(a => a.UserName == userName).First(); var conversation = context.Conversations.Where(a => (a.SenderId == user.Id && a.Receiver.UserName == userName) || (a.ReceiverId == user.Id && a.Sender.UserName == userName)).FirstOrDefault(); if (conversation == null) { //We know that this is their first message so add new Conversation conversation = new Conversation() { ReceiverId = Receiveruser.Id, Receiver = Receiveruser, SenderId = user.Id, Sender = user, SenderReceived = true, ReceiverReceived = false, }; context.Conversations.Add(conversation); } else { //Check who is sender of this message and set flag for notification if (conversation.ReceiverId == user.Id) { conversation.ReceiverReceived = true; conversation.SenderReceived = false; } else { conversation.SenderReceived = true; conversation.ReceiverReceived = false; } } Content con = new Content() { ConversationId = conversation.ConversationId, Conversation = conversation, MessageContent = content, SendDate = DateTime.Now, UserId = user.Id, UserSender = user }; var sentimentalInt = new SentimentalInterpreter(); var isContentHappy = sentimentalInt.IsHappy(con.MessageContent); if (isContentHappy) { con.IsHappy = true; } conversation.LastDateTimeSend = con.SendDate; context.Contents.Add(con); conversation.Contents.Add(con); context.SaveChanges(); return("OK"); }
public JsonResult IsSpam(string text) { bool isSpam = SpamDetector.IsContentSpam(text); return(Json(isSpam, JsonRequestBehavior.AllowGet)); }
public ActionResult SavePost(PostCategoryViewModel vm, HttpPostedFileBase file, string newItem = null) { #region Spam Detextion if (SpamDetector.IsContentSpam(vm.Post.Title)) { return(RedirectToAction("Index", "Post")); } #endregion #region GetUserAndSaveUserImage //Verify whether user has neccessary data ApplicationUser user = null; string id = User.Identity.GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } int idd = vm.Post.PostId; var post = vm.Post; if (file != null && file.ContentLength > 0) { if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png") { var sourceImage = Image.FromStream(file.InputStream); sourceImage = ResizeImage(sourceImage, 500, 500); //Generowanie plik var fileExt = Path.GetExtension(file.FileName); var filename = Guid.NewGuid() + fileExt; // Unikalny identyfikator + rozszerzenie //W jakim folderze ma byc umiesczony dany plik oraz jego nazwa! Oraz zapis var path = Path.Combine(Server.MapPath(AppConfig.ImagesPostFolder), filename); //file.SaveAs(path); sourceImage.Save(path); post.MainPicture = filename; } } else if (file == null && newItem != null && newItem != String.Empty) { var fractImg = FractalGenerator.GenereateFractal1(user.Email); var filename = Guid.NewGuid() + ".jpg"; var path = Path.Combine(Server.MapPath(AppConfig.ImagesPostFolder), filename); fractImg.Save(path); post.MainPicture = filename; } #endregion #region Sentimental Analisys var sentimentalInt = new SentimentalInterpreter(); var isContentHappy = sentimentalInt.IsHappy(post.Title); if (isContentHappy) { post.IsHappy = true; } #endregion post.DateOfInsert = DateTime.Now; post.UserId = user.Id; post.User = user; if (user.Posts.Where(a => a.PostId == post.PostId).Count() == 0) { user.Posts.Add(post); } context.Posts.AddOrUpdate(post); context.SaveChanges(); //InsertOrUpdate(post); return(RedirectToAction("Post", "Manage")); }