コード例 #1
0
        public ActionResult Update(Hokejista hokejista, HttpPostedFileBase picture, int ligaId, int postId)
        {
            try
            {
                HokejistaDao     hokejistaDao     = new HokejistaDao();
                HokejistaLigaDao hokejistaLigaDao = new HokejistaLigaDao();
                HokejistaLiga    hokejistaLiga    = hokejistaLigaDao.GetById(ligaId);
                hokejista.Liga = hokejistaLiga;
                HokejistaPostDao hokejistaPostDao = new HokejistaPostDao();
                HokejistaPost    hokejistaPost    = hokejistaPostDao.GetById(postId);
                hokejista.Post = hokejistaPost;

                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 = ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap h          = new Bitmap(smallImage);
                            h.Save(Server.MapPath("~/uploads/hokejista/" + imageName), ImageFormat.Jpeg);
                            smallImage.Dispose();
                            h.Dispose();
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/hokejista/" + picture.FileName));
                        }

                        if (!String.IsNullOrEmpty(hokejista.ImageName))
                        {
                            System.IO.File.Delete(Server.MapPath("~/uploads/hokejista/" + hokejista.ImageName));
                        }


                        hokejista.ImageName = imageName;
                    }
                }

                hokejistaDao.Update(hokejista);

                TempData["message-success"] = "Hráč " + hokejista.Jmeno + " byl upraven.";
            }
            catch (Exception exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Players"));
        }
コード例 #2
0
        public ActionResult Add(Hokejista hokejista, HttpPostedFileBase picture, int ligaId, int postId)
        {
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    //picture.SaveAs(Server.MapPath("~/Uploads/Hokejista/") + picture.FileName);
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);

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

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

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

                            smallImage.Dispose();
                            h.Dispose();

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

                HokejistaLigaDao hokejistaLigaDao = new HokejistaLigaDao();
                HokejistaLiga    hokejistaLiga    = hokejistaLigaDao.GetById(ligaId);

                hokejista.Liga = hokejistaLiga;

                HokejistaPostDao hokejistaPostDao = new HokejistaPostDao();
                HokejistaPost    hokejistaPost    = hokejistaPostDao.GetById(postId);

                hokejista.Post = hokejistaPost;

                HokejistaDao hokejistaDao = new HokejistaDao();
                hokejistaDao.Create(hokejista);

                TempData["message-success"] = "Hokejista " + hokejista.Jmeno + " byl úspěšně přidán.";
            }
            else
            {
                return(View("Create", hokejista));
            }

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public ActionResult Create()
        {
            HokejistaLigaDao      hokejistaLigaDao = new HokejistaLigaDao();
            HokejistaPostDao      hokejistaPostDao = new HokejistaPostDao();
            IList <HokejistaLiga> ligy             = hokejistaLigaDao.GetAll();
            IList <HokejistaPost> posty            = hokejistaPostDao.GetAll();

            ViewBag.Ligy  = ligy;
            ViewBag.Posty = posty;

            return(View());
        }
コード例 #4
0
        public ActionResult EditTrener(int id)
        {
            HokejistaDao     hokejistaDao     = new HokejistaDao();
            HokejistaLigaDao hokejistaLigaDao = new HokejistaLigaDao();
            HokejistaPostDao hokejistaPostDao = new HokejistaPostDao();

            Hokejista h = hokejistaDao.GetById(id);

            ViewBag.Ligy  = hokejistaLigaDao.GetAll();
            ViewBag.Posty = hokejistaPostDao.GetAll();

            return(View(h));
        }
コード例 #5
0
        public ActionResult UpdateTrener(Hokejista hokejista, int ligaId, int postId)
        {
            try
            {
                HokejistaDao     hokejistaDao     = new HokejistaDao();
                HokejistaLigaDao hokejistaLigaDao = new HokejistaLigaDao();
                HokejistaLiga    hokejistaLiga    = hokejistaLigaDao.GetById(ligaId);
                hokejista.Liga = hokejistaLiga;

                HokejistaPostDao hokejistaPostDao = new HokejistaPostDao();
                HokejistaPost    hokejistaPost    = hokejistaPostDao.GetById(postId);
                hokejista.Post = hokejistaPost;

                hokejistaDao.Update(hokejista);

                TempData["message-success"] = "Hráč " + hokejista.Jmeno + " byl upraven.";
            }
            catch (Exception exception)
            {
                throw;
            }

            return(RedirectToAction("Index", "Players"));
        }