Example #1
0
        // GET: Home
        public ActionResult Index()
        {
            var  sentimentalInt = new SentimentalInterpreter();
            var  m    = sentimentalInt.IsHappy("zła gra nie polecam");
            Game game = context.Games.First();

            return(View(game));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        // 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");
        }
Example #5
0
        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"));
        }