コード例 #1
0
        public ActionResult CreateCategories()
        {
            GameCategoryDao      gameCategoryDao = new GameCategoryDao();
            IList <GameCategory> categories      = gameCategoryDao.GetAll();

            ViewBag.Categories = categories;

            return(View("CreateCategories"));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            GameDao         gameDao         = new GameDao();
            GameCategoryDao gameCategoryDao = new GameCategoryDao();

            Game g = gameDao.GetById(id);

            ViewBag.Categories = gameCategoryDao.GetAll();

            return(View(g));
        }
コード例 #3
0
        public ActionResult Update(Game game, HttpPostedFileBase picture, int categoryId)
        {
            try
            {
                GameDao         gameDao         = new GameDao();
                GameCategoryDao gameCategoryDao = new GameCategoryDao();

                GameCategory gameCategory = gameCategoryDao.GetById(categoryId);

                game.Category = gameCategory;

                if (picture != null)
                {
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);

                        Guid   guid      = Guid.NewGuid();
                        string imageName = guid.ToString() + ".jpg";

                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image  smallImage = Class.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b          = new Bitmap(smallImage);



                            b.Save(Server.MapPath("~/uploads/game/" + imageName), ImageFormat.Jpeg);

                            smallImage.Dispose();
                            b.Dispose();
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/game/" + picture.FileName));
                        }


                        game.ImageName = imageName;
                    }
                }

                gameDao.Update(game);

                TempData["message-success"] = "Hra" + game.Name + "byla upravena";
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Games"));
        }
コード例 #4
0
        public ActionResult Add(Game game, HttpPostedFileBase picture, int categoryId)
        {
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);
                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image  smallImage = Class.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b          = new Bitmap(smallImage);

                            Guid   guid      = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";

                            b.Save(Server.MapPath("~/uploads/game/" + imageName), ImageFormat.Jpeg);

                            smallImage.Dispose();
                            b.Dispose();

                            game.ImageName = imageName;
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/game/" + picture.FileName));
                        }
                    }
                }

                GameCategoryDao gameCategoryDao = new GameCategoryDao();
                GameCategory    gameCategory    = gameCategoryDao.GetById(categoryId);

                game.Category = gameCategory;

                GameDao gameDao = new GameDao();
                gameDao.Create(game);

                TempData["message-success"] = "Hra byla úspěšně vytvořena";
            }
            else
            {
                return(View("Create", game));
            }



            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public ActionResult Update(GameCategory gameCategory)
        {
            try
            {
                GameCategoryDao gameCategoryDao = new GameCategoryDao();


                gameCategoryDao.Update(gameCategory);

                TempData["message-success"] = "Žánr" + gameCategory.Name + "byl upraven";
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Games"));
        }
コード例 #6
0
        public ActionResult Add(GameCategory gameCategory)
        {
            if (ModelState.IsValid)
            {
                GameCategoryDao gameCategoryDao = new GameCategoryDao();

                gameCategoryDao.Create(gameCategory);

                TempData["message-success"] = "Žánr byl úspěšně vytvořen";
            }
            else
            {
                return(View("Create", gameCategory));
            }



            return(RedirectToAction("Index", "Games"));
        }
コード例 #7
0
        public ActionResult EditCategory()
        {
            GameCategoryDao gameCategoryDao = new GameCategoryDao();

            return(View("EditCategory"));
        }