Beispiel #1
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"));
        }
Beispiel #2
0
        public ActionResult aktivace2(String _id)
        {
            int     id      = int.Parse(_id);
            GameDao gameDao = new GameDao();
            Hra     hra     = gameDao.GetById(id);

            if (hra.Aktivovano)
            {
                hra.Aktivovano = false;
            }
            else
            {
                hra.Aktivovano = true;
            }


            gameDao.Update(hra);
            // return RedirectToAction("Hra", new { _page = _page, vse = vse, _itemsOnPage = _itemsOnPage });
            return(RedirectToAction("DetailHry", new { id = hra.Id }));
        }
Beispiel #3
0
        public ActionResult Update(Hra hra, string _platforma, string _vydavatel, HttpPostedFileBase obrazek)
        {
            // tato zatracená část musí existovat, jinak by  if (ModelState.IsValid) řval, protože viewbagy by byly prázdné
            PlatformaDao      platformaDao = new PlatformaDao();
            IList <Platforma> platformy    = platformaDao.GetlAll();

            VydavatelDao      vydavateleDao = new VydavatelDao();
            IList <Vydavatel> vydavatele    = vydavateleDao.GetlAll();

            ViewBag.platformy  = platformy;
            ViewBag.vydavatele = vydavatele;



            GameDao gameDao = new GameDao();

            Vydavatel vyd;
            Platforma plat;



            if (ModelState.IsValid)
            {
                vyd           = vydavateleDao.GetById(int.Parse(_vydavatel));
                plat          = platformaDao.GetById(int.Parse(_platforma));
                hra.Vydavatel = vyd;
                hra.Platforma = plat;
                if (obrazek != null)
                {
                    if (obrazek.ContentType == "image/jpeg" || obrazek.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(obrazek.InputStream);
                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image smallImage = ImageHelper.ScaleImage(image, 200, 200);

                            Bitmap b         = new Bitmap(smallImage);
                            Guid   guid      = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";
                            b.Save(Server.MapPath("~/uploads/hry/" + imageName), ImageFormat.Jpeg);
                            smallImage.Dispose();
                            b.Dispose();
                            if (hra.Ikona != null)
                            {
                                try
                                {
                                    System.IO.File.SetAttributes(Server.MapPath("~/uploads/hry/" + hra.Ikona), FileAttributes.Normal);
                                    System.IO.File.Delete(Server.MapPath("~/uploads/hry/" + hra.Ikona));
                                }
                                catch (Exception e)
                                {
                                }
                            }

                            hra.Ikona = imageName;
                        }
                        else
                        {
                            hra.Ikona = Server.MapPath("~´/uploads/hry/" + obrazek.FileName);
                            obrazek.SaveAs(Server.MapPath("~´/uploads/hry/" + obrazek.FileName));
                        }
                    }
                    else
                    {
                        TempData["error"] = "obrázek není jpg / png";
                        return(View("EditHra", hra));
                    }
                }
                Vydavatel Vstary = vydavateleDao.GetByGame(hra.Id);

                if (hra.Vydavatel.Id != Vstary.Id)
                {
                    Vydavatel novy = hra.Vydavatel;

                    Vstary.Pocet--;
                    vydavateleDao.Update(Vstary);
                    novy.Pocet++;
                    vydavateleDao.Update(novy);
                }

                Platforma Pstary = platformaDao.GetByGame(hra.Id);
                if (hra.Platforma.Id != Pstary.Id)
                {
                    Platforma novy = hra.Platforma;
                    Pstary.Pocet--;
                    platformaDao.Update(Pstary);
                    hra.Platforma.Pocet++;
                    platformaDao.Update(hra.Platforma);
                }



                gameDao.Update(hra);
                TempData["message-success"] = "Hra " + hra.Nazev + "byla upravena.";
                return(RedirectToAction("hra"));
            }
            else
            {
                return(View("EditHra", hra));
            }
        }