Example #1
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"));
        }
Example #2
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));
        }