Пример #1
0
        //
        // GET: /Ranking/Create
        public ActionResult Create()
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            ctx.SimpleRanking();

            TempData["SimpleRankingMsg"]= "Simple Ranking Created";
            return RedirectToAction("Index");
            //return View();
        }
Пример #2
0
        public ActionResult Create(FormCollection collection)
        {
            DataSet picSet = new DataSet();
            var dataSetName = collection.Get("name");
            picSet.Name = dataSetName;

            try
            {
                if (string.IsNullOrEmpty(dataSetName))
                    ModelState.AddModelError("name", "Prosze podaj mi nazwę");

                if (!ModelState.IsValid)
                    return View(picSet);

                // TODO: Add insert logic here
                var datasetRepository = "PicturesSets";

                var virtulaDs = VirtualPathUtility.GetDirectory("~/");

                var destinationFolder = Path.Combine(Server.MapPath("~/"), datasetRepository);
                //Server.MapPath(datasetRepository);
                //var ma = Server.MapPath("~/");

                var postedFile = Request.Files["datafile"];
                if (Path.GetExtension(postedFile.FileName) != ".zip")
                {
                    throw new NotSupportedException("Przyjmuję tylko pliki .zip");
                }

                var diskFolder = Path.Combine(destinationFolder, dataSetName);
                //string.Format("{0}/{1}",destinationFolder,dataSetName);

                var fileName = Path.Combine(diskFolder, postedFile.FileName);
                //string.Format("{0}/{1}", datasetFolder, postedFile.FileName);

                if (postedFile.ContentLength > 0)
                {
                    Directory.CreateDirectory(diskFolder);

                    postedFile.SaveAs(fileName);

                    picSet.FolderPath = diskFolder;

                    List<Picture> pictures = new List<Picture>();
                    string zipToUnpack = fileName;
                    string unpackDirectory = diskFolder;
                    using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
                    {
                        // here, we extract every entry, but we could extract conditionally
                        // based on entry name, size, date, checkbox status, etc.
                        int picCount = 0;
                        foreach (ZipEntry zipItem in zip1)
                        {
                            //zipItem.InputStream

                            zipItem.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
                            picCount++;
                            string zipItemFile = Path.Combine(unpackDirectory, zipItem.FileName);
                            //string.Format("{0}/{1}", unpackDirectory,zipItem.FileName);
                            var isImg = PictureHelpers.IsValidImage(zipItemFile);
                            if (!isImg)
                            {
                                System.IO.File.Delete(zipItemFile);
                                picCount--;
                                continue;
                            }

                            string picRelativePath = string.Format("{0}/{1}/{2}", datasetRepository, dataSetName, zipItem.FileName);
                            //Path.Combine( datasetRepository,dataSetName,zipItem.FileName);
                            picSet.Pictures.Add(new Picture { FullPath = picRelativePath, Name = zipItem.FileName });

                        }
                        picSet.PicCoutn = picCount;

                        PicRankDBDataContext ctx = new PicRankDBDataContext();
                        ctx.DataSets.InsertOnSubmit(picSet);
                        ctx.SubmitChanges();
                    }

                }
                return RedirectToAction("Details", new { id = picSet.Id });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("datafile", ex.Message);
                return View(picSet);
            }
        }
Пример #3
0
        public ActionResult Index()
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var picSet = (from ds in ctx.DataSets
                          orderby ds.Active descending, ds.Id
                          select ds).ToList();
            return View(picSet);
        }
Пример #4
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                PicRankDBDataContext ctx = new PicRankDBDataContext();

                var ds = (from t in ctx.DataSets
                          where t.Id == id
                          select t).SingleOrDefault();

                ds.Name = collection["name"];
                ds.Active = Convert.ToBoolean(collection["active"]);

                ctx.SubmitChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #5
0
        public ActionResult Edit(int id)
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var ds = (from t in ctx.DataSets
                      where t.Id == id
                      select t).SingleOrDefault();

            return View(ds);
        }
Пример #6
0
        public ActionResult Details(int id)
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var picSet = (from ds in ctx.DataSets
                          where ds.Id == id
                          select ds).SingleOrDefault();

            return View(picSet);
        }
Пример #7
0
        //
        // GET: /Ranking/
        public ActionResult Index()
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var basePictures = ctx.GetPicForRanking(20);

            List<PictureView> pic = new List<PictureView>();
            foreach (var item in basePictures)
            {
                pic.Add(new PictureView() { Id = item.Id, FullPath = item.FullPath });
            }

            ViewBag.SimpleRankingMsg = TempData["SimpleRankingMsg"];

            return View(pic);
        }
Пример #8
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);
        }
Пример #9
0
        public ActionResult Win(int gameId, int winnerId)
        {
            PicRankDBDataContext ctx = new PicRankDBDataContext();

            var game = (from g in ctx.Games
                        where g.Id == gameId
                        select g).SingleOrDefault(); ;

            game.IsFinished = true;

            var participant = (from p in ctx.GameParticipants
                               where p.GameId == gameId && p.PictureId == winnerId
                               select p).SingleOrDefault();

            participant.IsWinner = true;

            ctx.SubmitChanges();

            return RedirectToAction("Play"); //View(mainPicList);
        }
Пример #10
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);
        }