示例#1
0
        /// <summary>
        /// Inserts data with EntityFramework
        /// </summary>
        /// <param name="seed">Randomnumber generators seed</param>
        public static void InsertData(int seedID, int rows)
        {
            try
            {
                var sw = new Stopwatch();

                Console.WriteLine("--Inserting data!");

                sw.Start();

                var i      = 0;
                var result = false;
                var seed   = 0;

                using (var db = new ThesisContext())
                {
                    seed = (from sd in db.Seed
                            where sd.SeedID == seedID
                            select sd.SeedValue).FirstOrDefault();

                    Console.WriteLine("--Seed is : " + seed);

                    var gen = new Random(seed);

                    while (i < rows)
                    {
                        var row = new RandomObject()
                        {
                            RandomObjectID       = i,
                            RandomString         = RandomStringGenerator.RandomString(gen, 15),
                            RandomDateTimeOffset = RandomDateTimeOffsetGenerator.RandomDateTimeOffset(gen),
                            RandomInt            = gen.Next(),
                            SeedID = seedID
                        };

                        db.RandomObject.Add(row);

                        i++;
                    }

                    db.SaveChanges();

                    result = true;

                    sw.Stop();
                }

                Console.WriteLine("--Result was: " + result);
                Console.WriteLine("--Time Elapsed: " + sw.Elapsed + "\n");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occured: " + ex);
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
            }
        }
示例#2
0
        public PartialViewResult AddComment(int postId, string content)
        {
            if (SpamDetector.IsContentSpam(content))
            {
                return(null);
            }
            Post            post = context.Posts.Where(a => a.PostId == postId).First();
            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }

            CommentPost commentPost = new CommentPost()
            {
                Body = content, DateOfInsert = DateTime.Now, PostId = post.PostId, UserId = User.Identity.GetUserId(), User = user
            };



            var sentimentalInt = new SentimentalInterpreter();
            var isContentHappy = sentimentalInt.IsHappy(commentPost.Body);

            if (isContentHappy)
            {
                commentPost.IsHappy = true;
            }

            context.CommentPosts.Add(commentPost);
            context.SaveChanges();

            post.Comments.Add(commentPost);

            CurrentPostUserViewModel vm = new CurrentPostUserViewModel
            {
                LoggedUser = user,
                Post       = post
            };

            vm.Post.Comments = vm.Post.Comments.OrderBy(a => a.DateOfInsert).ToList();
            return(PartialView("_ListOfComments", vm));
        }
示例#3
0
        public JsonResult AddUserToGameEvent(int gameEventId = 1)
        {
            var gameEvent = context.GamingEvents.Where(a => a.GamingEventId == gameEventId).First();

            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }

            gameEvent.UsersToAttend.Add(user);
            user.AttendGamingEvent.Add(gameEvent);
            context.SaveChanges();

            return(Json(gameEvent.UsersToAttend.Select(x => new
            {
                userName = x.UserName
            }), JsonRequestBehavior.AllowGet));
        }
示例#4
0
        // GET: Comment
        public JsonResult LikePostComment(int commentId)
        {
            var  comment = context.CommentPosts.Find(commentId);
            bool isNew   = false;

            ApplicationUser user = null;
            string          id   = GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }

            if (user.LikedCommentsPosts.Contains(comment))
            {
                isNew = false;
                comment.Likes--;
                user.LikedCommentsPosts.Remove(comment);
            }
            else
            {
                isNew = true;
                comment.Likes++;
                user.LikedCommentsPosts.Add(comment);
            }

            context.SaveChanges();

            return(Json(new { amount = comment.Likes, isNewComment = isNew }, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        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));
        }
示例#6
0
        public async Task <ActionResult> AddGame(GameCategoryViewModel vm, HttpPostedFileBase file)
        {
            var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user.UserInformation == null)
            {
                RedirectToAction("Index", new { errorMessage = "Proszę wypełnić swoje dane przed dodaniem gry" });
            }
            var game = vm.Game;

            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.ImagesGameFolder), filename);
                    //file.SaveAs(path);
                    sourceImage.Save(path);
                    game.MainPicture = filename;
                }
            }

            game.UserId = user.Id;

            context.Games.Add(game);
            user.Games.Add(game);
            context.SaveChanges();
            //context.Exchanges.Add(new Exchange() { GameId = game.GameId, Game = game, DateOfInsert = DateTime.Now });
            //context.SaveChanges();

            return(RedirectToAction("Index", "Manage"));
        }
示例#7
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");
        }