예제 #1
0
        public ActionResult Rezervace(int?z)
        {
            if (!z.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            ZajezdDao zd     = new ZajezdDao();
            Zajezd    zajzed = zd.GetById(z.Value);
            Rezervace r      = new Rezervace();

            r.zajezd = zajzed;
            return(View(r));
        }
예제 #2
0
        public ActionResult VlozZajezd(Zajezd zajezd, int h, int DId)
        {
            MoznostiDopravyDao dd = new MoznostiDopravyDao();
            MoznostiDopravy    md = dd.GetById(DId);
            HotelDao           hd = new HotelDao();
            Hotel     hotel       = hd.GetById(h);
            ZajezdDao zajezdDao   = new ZajezdDao();

            zajezd.hotel   = hotel;
            zajezd.doprava = md;
            zajezdDao.Create(zajezd);

            TempData["x"] = "Zájezd vytvořen";
            return(View("Detail", hotel));
        }
예제 #3
0
        public ActionResult Search(string phrase)
        {
            HotelDao      hd        = new HotelDao();
            IList <Hotel> hotels    = hd.searchHotel(phrase);
            ZajezdDao     zajezdDao = new ZajezdDao();

            foreach (Hotel hotel in hotels)
            {
                hotel.nejlevnejsiZajezd = zajezdDao.GetNejlevnejsiZajezd(hotel.Id);
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("Index", hotels));
            }
            return(View("Index", hotels));
        }
예제 #4
0
        public ActionResult Delete(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index", "Zajezdy"));
            }

            HotelDao       hd = new HotelDao();
            Hotel          h  = hd.GetById(id.Value);
            ZajezdDao      zd = new ZajezdDao();
            RezervaceDao   rd = new RezervaceDao();
            IList <Zajezd> z  = zd.GetByHotel(h.Id);

            if (z.Count() > 0)
            {
                foreach (Zajezd r in z)
                {
                    IList <Rezervace> rezervace = rd.GetByZajezd(r.Id);
                    if (rezervace.Count() > 0)
                    {
                        foreach (Rezervace rez in rezervace)
                        {
                            rd.Delete(rez);
                        }
                    }
                    zd.Delete(r);
                }
            }
            if (h.fotky.Count > 0)
            {
                FotografieDao fd = new FotografieDao();
                foreach (Fotografie f in h.fotky)
                {
                    System.IO.File.Delete(Server.MapPath(f.fotografie));
                    System.IO.File.Delete(Server.MapPath(f.nahled));
                    fd.Delete(f);
                }
            }

            hd.Delete(h);


            TempData["x"] = "Hotel úspěšně smazán";


            return(RedirectToAction("Index", "Zajezdy"));
        }
예제 #5
0
        public ActionResult Destinace(int id)
        {
            if (id == 0)
            {
                return(View("Index", new HotelDao().GetAll()));
            }
            IList <Hotel> hotels = new HotelDao().GetHotelsInDestination(id);

            ViewBag.Destinace = new DestinaceDao().GetDestinationByState(id);
            ViewBag.Staty     = new StatDao().GetAll();
            ZajezdDao zajezdDao = new ZajezdDao();

            foreach (Hotel hotel in hotels)
            {
                hotel.nejlevnejsiZajezd = zajezdDao.GetNejlevnejsiZajezd(hotel.Id);
            }
            return(View("Index", hotels));
        }
예제 #6
0
        private IList <Hotel> GetHotelsWithZajezdDao(int itemsOnPage, int pg, DateTime?datumOd, DateTime?datumDo)
        {
            ZajezdDao zd = new ZajezdDao();

            if (datumOd.HasValue && datumDo.HasValue)
            {
                return(zd.GetZajezdyWithDateFromAndTo(itemsOnPage, pg, datumOd.Value, datumDo.Value));
            }
            if (datumOd.HasValue)
            {
                return(zd.GetZajezdyWithDateFrom(itemsOnPage, pg, datumOd.Value));
            }
            if (datumDo.HasValue)
            {
                return(zd.GetZajezdyWithDateTo(itemsOnPage, pg, datumDo.Value));
            }
            return(zd.GetHotelsIdPaged(itemsOnPage, pg));
        }
예제 #7
0
        private int GetCountWithZajezdDao(DateTime?datumOd, DateTime?datumDo)
        {
            ZajezdDao zd = new ZajezdDao();

            if (datumOd.HasValue && datumDo.HasValue)
            {
                return(zd.GetCountWithDateFromAndTo(datumOd.Value, datumDo.Value));
            }
            if (datumOd.HasValue)
            {
                return(zd.GetCountWithDateFrom(datumOd.Value));
            }
            if (datumDo.HasValue)
            {
                return(zd.GetCountWithDateTo(datumDo.Value));
            }
            return(zd.GetCountOfAllHotels());
        }
예제 #8
0
        public ActionResult Rezervovat(Rezervace r, int?zi)
        {
            if (!zi.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            ZajezdDao zj = new ZajezdDao();
            Zajezd    z  = zj.GetById(zi.Value);

            r.zajezd = z;
            RezervaceDao rd    = new RezervaceDao();
            int          pocet = r.pocetDeti + r.pocetDeti;

            if (pocet > r.zajezd.kapacita)
            {
                TempData["Rezervace"] = "Omlouváme se, ale nepodařilo se vytvořit rezervaci z důvodu nedostatečné kapacity";
                return(RedirectToAction("Detail", "Zajezdy", z.hotel.Id));
            }
            UzivatelDao ud       = new UzivatelDao();
            Uzivatel    uzivatel = ud.GetByLogin(User.Identity.Name);
            int         kap      = r.zajezd.kapacita - pocet;

            z.kapacita = kap;
            r.uzivatel = uzivatel;
            rd.Create(r);
            zj.Update(r.zajezd);
            IList <Uzivatel> uzivatele = new UzivatelDao().GetUsersNotInRole(new UzivatelskaPravaDao().GetById(2));

            foreach (Uzivatel u in uzivatele)
            {
                MailClient.sendMail(u.login, "Vytvořená nová rezervace", "Vážený zaměstnanče, byla vytvořena nová rezervace od uživatele" + r.uzivatel.jmeno + " " + r.uzivatel.prijmeni + ".");
            }

            TempData["Rezervace"] = "Rezervace proběhla úspěšně";
            return(RedirectToAction("Index", "Zajezdy"));
        }
예제 #9
0
        public ActionResult Smaz(int?z)
        {
            if (!z.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            RezervaceDao      rd        = new RezervaceDao();
            ZajezdDao         zd        = new ZajezdDao();
            Zajezd            zaj       = zd.GetById(z.Value);
            Hotel             hotel     = zaj.hotel;
            IList <Rezervace> rezervace = rd.GetByZajezd(zaj.Id);

            if (rezervace.Count() > 0)
            {
                foreach (Rezervace r in rezervace)
                {
                    rd.Delete(r);
                }
            }
            zd.Delete(zaj);
            TempData["x"] = "Zájezd smazán";
            return(View("Detail", hotel));
        }
예제 #10
0
        // GET: Zajezdy
        public ActionResult Index(int?page, int?view, DateTime?datumOd, DateTime?datumDo)
        {
            int           totalPages;
            int           totalHotels;
            int           pg          = 1;
            int           itemsOnPage = 5;
            IList <Hotel> hotels;

            if (page.HasValue)
            {
                pg = page.Value;
            }
            pg = (pg <= 0) ? 1 : pg;

            totalHotels = GetHotelCount(view, datumOd, datumDo);
            totalPages  = totalHotels / itemsOnPage;

            if (totalPages == 0)
            {
                totalPages = 1;
            }
            if (pg > totalPages)
            {
                pg = totalPages;
            }

            hotels = GetHotels(itemsOnPage, pg, view, datumOd, datumDo);

            ViewBag.Pages = (int)Math.Ceiling((double)totalHotels / (double)itemsOnPage);

            if (view.HasValue)
            {
                ViewBag.ViewMode = view.Value;
            }
            if (datumOd.HasValue)
            {
                ViewBag.DatumOd = datumOd.Value;
            }
            if (datumDo.HasValue)
            {
                ViewBag.DatumDo = datumDo.Value;
            }

            ViewBag.CurrentPage = pg;

            if (pg < 3)
            {
                ViewBag.FirstPage = 1;
                ViewBag.LastPage  = 5;
            }
            else
            {
                ViewBag.FirstPage = pg - 2;
                ViewBag.LastPage  = pg + 2;
            }

            if (ViewBag.LastPage > totalPages)
            {
                ViewBag.LastPage = totalPages;
            }

            ViewBag.Staty = new StatDao().GetAll();
            ZajezdDao zajezdDao = new ZajezdDao();

            foreach (Hotel hotel in hotels)
            {
                hotel.nejlevnejsiZajezd = zajezdDao.GetNejlevnejsiZajezd(hotel.Id);
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(hotels));
            }

            return(View(hotels));
        }