Пример #1
0
        public ActionResult Detail(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            HotelDao bookDao = new HotelDao();
            Hotel    h       = bookDao.GetById(id.Value);

            if (h.fotky == null)
            {
                FotografieDao fotografieDao = new FotografieDao();
                h.fotky = fotografieDao.GetPhotosByHotelId(h.Id);
            }
            return(View(h));
        }
Пример #2
0
        public ActionResult UpdateInDB(IEnumerable <HttpPostedFileBase> files, Hotel hotel, int stravovani)
        {
            HotelDao hd = new HotelDao();
            StatDao  sd = new StatDao();
            Stat     s  = sd.FindStat(hotel.destinace.stat.jmeno);

            if (s == null)
            {
                sd.Create(hotel.destinace.stat);
            }
            else
            {
                hotel.destinace.stat = s;
            }

            DestinaceDao dd = new DestinaceDao();
            Destinace    d  = dd.FindDestinace(hotel.destinace.nazev);

            if (d == null)
            {
                dd.Create(hotel.destinace);
            }
            else
            {
                hotel.destinace = d;
            }

            ZpusobStravovani st = new ZpusobStravovaniDao().GetById(stravovani);

            hotel.stravovani = st;

            FotografieDao fd = new FotografieDao();

            hotel.fotky = fd.GetPhotosByHotelId(hotel.Id);
            hd.Update(hotel);

            foreach (var file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    Fotografie f = new Fotografie();

                    Stream str = file.InputStream;

                    Image image      = Image.FromStream(file.InputStream);
                    Image smallImage = ImageHelper.ScaleImage(Image.FromStream(str), 300, 200);

                    Bitmap b         = new Bitmap(image);
                    Bitmap sb        = new Bitmap(smallImage);
                    Guid   guid      = Guid.NewGuid();
                    string imageName = guid.ToString() + ".png";

                    b.Save(Server.MapPath("~/Images/hotely/" + imageName), ImageFormat.Jpeg);
                    sb.Save(Server.MapPath("~/Images/hotely/nahled/" + imageName), ImageFormat.Jpeg);
                    smallImage.Dispose();
                    b.Dispose();

                    f.fotografie = "~/Images/hotely/" + imageName;
                    f.nahled     = "~/Images/hotely/nahled/" + imageName;
                    f.hotel      = hotel;
                    f.popisek    = hotel.nazev;
                    fd.Create(f);
                }
            }

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