Beispiel #1
0
        //
        // GET: /Ranking/Details/5
        public ActionResult Ranking(int id)
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var basePictures = (from r in ctx.Rankings
                                join
                                p in ctx.Pictures on r.PicId equals p.Id
                                where r.BasePicId == id
                                orderby r.Score descending
                                select new { PicRank = r, Pic = p }).Take(20);

            var mainPic = (from p in ctx.Pictures
                           where p.Id == id
                           select p).SingleOrDefault();

            MainPicWithList ranking = new MainPicWithList();
            ranking.MainPicture = new PictureView() { FullPath = mainPic.FullPath, Id = mainPic.Id };

            foreach (var item in basePictures)
            {
                ranking.Pictures.Add(new PictureView()
                {
                    Id = item.Pic.Id,
                    FullPath = item.Pic.FullPath,
                    RankingScore = item.PicRank.Score.Value
                });
            }
            return View(ranking);
        }
Beispiel #2
0
        public ActionResult Play()
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var pictures = ctx.RandomPictures(1 + 12);

            MainPicWithList gameView = new MainPicWithList();

            Game game = new Game();

            game.GameDate = DateTime.Now;

            bool hasMain = false;
            foreach (var item in pictures)
            {
                if (!hasMain)
                {
                    gameView.MainPicture = new PictureView() { Id = item.Id, FullPath = item.FullPath };
                    //game main picture
                    game.BasePicId = gameView.MainPicture.Id;
                    hasMain = true;
                }
                else
                {
                    //game participants
                    game.GameParticipants.Add(new GameParticipant() { PictureId = item.Id });

                    gameView.Pictures.Add(new PictureView() { Id = item.Id, FullPath = item.FullPath });
                }

            }

            ctx.Games.InsertOnSubmit(game);
            ctx.SubmitChanges();

            gameView.GameId = game.Id;

            //only for test
            //if (gameView.MainPicture == null)
            //    gameView.MainPicture = new PictureView() { FullPath = @"http://picrank.eastgroup.pl/PicturesSets/pierscionki/image_2702399.jpg", Id = 123 };
            //for (int i = 0; i < 10; i++)
            //{
            //    gameView.Pictures.Add(gameView.MainPicture);
            //}

            return View(gameView);
        }