Esempio n. 1
0
        public static void CapacityCheck(Room r)
        {
            TermDao        tDao   = new TermDao();
            ReservationDao resDao = new ReservationDao();
            IList <Term>   terms  = tDao.GetTermsByRoom(r);

            foreach (Term t in terms)
            {
                //pokud je u nektereho terminu nastavena vetsi kapacita nez je nova maximalni kapacita mistnosti, zmen kapacitu terminu na max.kapacitu mistnosti
                if (r.MaxCapacity < t.Capacity && t.EndTerm > DateTime.Now)
                {
                    int uCount = r.MaxCapacity - (t.Capacity - tDao.GetActualCapacity(t));
                    //pokud je prihlaseno vice lidi nez nova max.kapacita mistnosti, odstran rezervace poslednich prihlasenych
                    if (uCount > 0)
                    {
                        IList <Reservation> reservations = resDao.GetLastReservationByTerm(t, uCount);
                        foreach (Reservation res in reservations)
                        {
                            resDao.Delete(res);
                        }
                    }
                    t.Capacity = r.MaxCapacity;
                    tDao.Update(t);
                }
            }
        }
Esempio n. 2
0
        public ActionResult Delete(int id)
        {
            try
            {
                TermDao tDao = new TermDao();
                Term    t    = tDao.GetById(id);

                //je treba smazat i vsechny rezervace daneho terminu
                ReservationDao      resDao       = new ReservationDao();
                IList <Reservation> reservations = resDao.GetAllReservationsByTerm(t);
                foreach (Reservation res in reservations)
                {
                    resDao.Delete(res);
                }

                tDao.Delete(t);
                TempData["succes"] = "Termín i jeho rezervace jsou úspěšně smazány.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            try
            {
                TourDao tourDao = new TourDao();
                Tour    tour    = tourDao.GetById(id);

                //System.IO.File.Delete(Server.MapPath("~/uploads/book/" + tour.ImageName));

                /*******POTREBA SMAZAT REZERVACE******/
                ReservationDao      reservationDao = new  ReservationDao();
                IList <Reservation> reservations   = reservationDao.GetAll();

                foreach (Reservation reservation in reservations)
                {
                    if (reservation.Tour.Id == id)
                    {
                        reservationDao.Delete(reservation);
                    }
                }

                tourDao.Delete(tour);

                TempData["message-success"] = "Zajezd " + tour.Name + " byl smazan";
            }
            catch (Exception e)
            {
                throw;
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        //pridat upozorneni pro vypsane teminy
        public ActionResult Delete(int id)
        {
            try
            {
                RoomDao rDao = new RoomDao();
                Room    r    = rDao.GetById(id);

                //je zapotřebí smazat nejdrive vsechny terminy v teto mistnosti, a take rezervace na tyto terminy
                TermDao        tDao   = new TermDao();
                ReservationDao resDao = new ReservationDao();
                IList <Term>   terms  = tDao.GetTermsByRoom(r);
                foreach (Term t in terms)
                {
                    IList <Reservation> reservations = resDao.GetAllReservationsByTerm(t);
                    foreach (Reservation res in reservations)
                    {
                        resDao.Delete(res);
                    }
                    tDao.Delete(t);
                }

                rDao.Delete(r);
                TempData["succes"] = "Místnost " + r.Name +
                                     " byla odstraněna, stejně tak i všechny termíny v této místnosti.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }
        // GET: Admin/Reservation
        public ActionResult Index(int?page, int?item)
        {
            int itemsOnPage = item ?? 5;
            int pg          = page ?? 1;

            UserDao             uDao = new UserDao();
            FitnessUser         u    = uDao.GetByLogin(User.Identity.Name);
            ReservationDao      rDao = new ReservationDao();
            IList <Reservation> res  = null;

            if (u.Role.Name == "Zákazník")
            {
                res = rDao.GetReservationPageByUser(itemsOnPage, pg, u);
            }
            else
            {
                res = rDao.GetReservationPage(itemsOnPage, pg);
            }

            ViewBag.Pages       = (int)Math.Ceiling((double)rDao.GetAll().Count / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;
            ViewBag.Items       = itemsOnPage;
            ViewBag.Mark        = "Reservation";

            if (Request.IsAjaxRequest())
            {
                return(PartialView(res));
            }
            return(View(res));
        }
        //rezervace se bude zadavat v planu terminu
        //[HttpPost]
        public ActionResult Add(int termId)
        {
            try
            {
                Reservation    r    = new Reservation();
                ReservationDao rDao = new ReservationDao();
                TermDao        tDao = new TermDao();
                UserDao        uDao = new UserDao();

                r.Term            = tDao.GetById(termId);
                r.User            = uDao.GetByLogin(User.Identity.Name);
                r.ReservationTime = DateTime.Now;

                if (tDao.GetActualCapacity(r.Term) > 0 && rDao.ReservationExist(r.Term, r.User) == false)
                {
                    rDao.Create(r);
                    TempData["succes"] = "Termín úspěšně rezervován.";
                }
                else if (tDao.GetActualCapacity(r.Term) <= 0)
                {
                    TempData["warning"] = "Termín je již plně obsazen.";
                }
                else if (rDao.ReservationExist(r.Term, r.User) != false)
                {
                    TempData["warning"] = "Termín již máte rezervovaný.";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(RedirectToAction("Index", "Term"));
        }
Esempio n. 7
0
        public ActionResult Delete(int id)
        {
            try
            {
                UserDao     uDao        = new UserDao();
                AddressDao  aDao        = new AddressDao();
                FitnessUser fitnessUser = uDao.GetById(id);
                Address     address     = new Address();
                address = fitnessUser.Address;

                //pokud se jedná o trenéra, je třeba smazat jeho termíny, které vede
                if (fitnessUser.Role.Name == "Trenér")
                {
                    TermDao      tDao  = new TermDao();
                    IList <Term> terms = tDao.GetTermsByTrainer(fitnessUser);

                    foreach (Term t in terms)
                    {
                        tDao.Delete(t);
                    }
                }//pokud se jedna o zakaznika, je treba smazat rezervace, na ktere je zapsan
                else if (fitnessUser.Role.Name == "Zákazník")
                {
                    ReservationDao      rDao         = new ReservationDao();
                    IList <Reservation> reservations = rDao.GetAllReservationsByUser(fitnessUser);

                    foreach (Reservation r in reservations)
                    {
                        rDao.Delete(r);
                    }
                }

                if (fitnessUser.SmallImageName != null)
                {
                    System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.SmallImageName));
                }
                if (fitnessUser.BigImageName != null)
                {
                    System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.BigImageName));
                }

                uDao.Delete(fitnessUser);
                aDao.Delete(address);


                TempData["succes"] = "Uživatelský účet byl odstraněn.";

                if (fitnessUser.Login == User.Identity.Name)
                {
                    return(RedirectToAction("Logout", "Home"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Esempio n. 8
0
        public ActionResult Reserve(int id)
        {
            // Získání instance vybrané lekce.
            LessonDao lessonDao = new LessonDao();
            Lesson    lesson    = lessonDao.GetById(id);

            // Získání instance přihlášeného klienta.
            FitnessCentreUserDao fitnessCentreUserDao = new FitnessCentreUserDao();
            FitnessCentreUser    user = fitnessCentreUserDao.GetByLogin(User.Identity.Name);

            // Ověření, zda lekce je aktivní (z důvodu času či aktivity instruktora).
            if (lesson.IsActive)
            {
                // Ověření, zda na lekci je volné místo pro registraci.
                if (lesson.ActualCapacity > 0)
                {
                    // Ověření, zda má klient dostatečný kredit pro rezervaci aktivity.
                    if (user.Credit >= lesson.ActivityType.Price)
                    {
                        // Nastavení parametrů rezervace.
                        Reservation reservation = new Reservation();
                        reservation.ReservationTime = DateTime.Now;
                        reservation.Lesson          = lesson;
                        reservation.Client          = user;

                        // Vložení rezervace do databáze.
                        ReservationDao reservationDao = new ReservationDao();
                        reservationDao.Create(reservation);

                        // Odečtení ceny aktivity z kreditu klienta a odečtení 1 volného místa z kapacity lekce. Update hodnot v databázi.
                        user.Credit -= lesson.ActivityType.Price;
                        fitnessCentreUserDao.Update(user);
                        lesson.ActualCapacity -= 1;
                        lessonDao.Update(lesson);

                        TempData["message-success"] = "Lekce aktivity " + lesson.ActivityType.Name + " v " + lesson.StartTime.ToString("dddd d.M.") +
                                                      " byla zarezervována.";
                        return(RedirectToAction("Index", "Lessons", new { isActive = true }));
                    }
                    else
                    {
                        TempData["message-error"] = "Nemáte dostatek kreditu pro registraci na aktivitu " +
                                                    lesson.ActivityType.Name + ".";
                        return(RedirectToAction("Index", "Lessons", new { isActive = true }));
                    }
                }
                else
                {
                    TempData["message-error"] = "Na lekci není žádné volné místo.";
                    return(RedirectToAction("Index", "Lessons", new { isActive = true }));
                }
            }
            else
            {
                TempData["message-error"] = "Lekce není aktivní.";
                return(RedirectToAction("Index", "Lessons", new { isActive = true }));
            }
        }
        internal static ReservationDao getResrvation()
        {
            if (reservationDao == null)
            {
                reservationDao = new ReservationDao(ConnectionProvider.getProvide());
            }

            return(reservationDao);
        }
Esempio n. 10
0
        public IHttpActionResult GetById(int id)
        {
            ReservationDao reservationDao = reservationManagement.GetById(id);

            if (reservationDao == null)
            {
                return(NotFound());
            }
            return(Ok(reservationDao));
        }
Esempio n. 11
0
        /// <summary>
        /// Obsluga przycisku edycji
        /// </summary>
        /// <param name="sender">Obiekt wywołujący zdarzenie</param>
        /// <param name="e">Obiekt zawierający parametry zdarzenia</param>
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            MainWindow       window = (MainWindow)Application.Current.MainWindow;
            UserControl      uc     = new Forms.Reservations();
            ReservationModel model  = ReservationDao.LoadById((long)(sender as Button).Tag);

            model.Mode     = "update";
            uc.DataContext = model;
            window.GridMain.Children.Clear();
            window.GridMain.Children.Add(uc);
        }
        public ActionResult ReservationSection(int id)
        {
            TourDao      tourDao = new TourDao();
            IList <Tour> tours   = tourDao.GetAll();

            ViewBag.Rezervace = tours;
            ReservationDao reservationDao = new ReservationDao();
            Reservation    reservation    = reservationDao.GetById(id);

            return(View(reservation));
        }
Esempio n. 13
0
        public ActionResult Index(bool?isActive, int?page)
        {
            // Nastavení uskutečněných lekcí jako neaktivních
            LessonDao lessonDao = new LessonDao();

            lessonDao.SetExpiredLessons();

            // Tato proměnná by správně neměla být definována uvnitř controlleru, ale měla by to být konfigurační konstanta.
            const int itemsOnPage = 10;
            int       pg          = page.HasValue ? page.Value : 1;
            int       totalClientsReservations;

            FitnessCentreUser user           = new FitnessCentreUserDao().GetByLogin(User.Identity.Name);
            ReservationDao    reservationDao = new ReservationDao();

            // Větvení pro výběr uplynulých/aktivních či všech rezervací.
            IList <Reservation> listClientsReservationsPerPage;

            if (isActive.HasValue)
            {
                listClientsReservationsPerPage = reservationDao.GetRestrictedClientsReservationsPaged(isActive, user.Id, itemsOnPage, pg, out totalClientsReservations);
            }
            else
            {
                listClientsReservationsPerPage = reservationDao.GetClientsReservationsPaged(user.Id, itemsOnPage, pg, out totalClientsReservations);
            }

            ViewBag.CurrentIsActive = isActive; // Pamatovat si nastavení výběru uplynulých/aktivních lekcí.
            // Výpočet počtu stránek.
            ViewBag.Pages       = (int)Math.Ceiling((double)totalClientsReservations / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;

            // Rezervaci nelze zrušit 6h před zahájením lekce.
            foreach (Reservation reservation in listClientsReservationsPerPage)
            {
                DateTime sixHoursBeforeStart = reservation.Lesson.StartTime.AddHours(-6); // Výpočet času 6h před zahájením lekce.
                reservation.IsCancellable = true;                                         // Pro jistotu předvyplnění vlastnosti. Zabránění null hodnotám.

                // Porovnání CompareTo vrací hodnoty -1, 0, 1. Pokud aktuální čas je v rozmezí 6 hodin před zahájením lekce a více.
                if (DateTime.Now.CompareTo(sixHoursBeforeStart) > 0)
                {
                    reservation.IsCancellable = false;
                }
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(listClientsReservationsPerPage));
            }
            else
            {
                return(View(listClientsReservationsPerPage));
            }
        }
Esempio n. 14
0
        public static void GenerateReport(int id, DateTime from, DateTime until)
        {
            var reservatios = ReservationDao.FindAllSubmittedBy_between(id, from.Ticks, until.Ticks);

            if (reservatios.Count > 0)
            {
                File.WriteAllText("report.txt",
                                  String.Join(Environment.NewLine, reservatios.Select(x => x.ToString())));
                Process.Start("report.txt");
            }
        }
 public List <PreorderTable> GetReservationList()
 {
     try
     {
         return(ReservationDao.GetReservation());
     }
     catch (HCSMSException ex)
     {
         raiseError(ex);
         return(null);
     }
 }
Esempio n. 16
0
        public HotelsController()
        {
            if (_hotelDao == null)
            {
                _hotelDao = new HotelDao();
            }

            if (_reservationDao == null)
            {
                _reservationDao = new ReservationDao();
            }
        }
Esempio n. 17
0
        public ActionResult Rezervace()
        {
            ReservationDao      reservationDao = new ReservationDao();
            IList <Reservation> reservations   = reservationDao.GetAll();
            KnihovnaUser        user           = new KnihovnaUserDao().GetByLogin(User.Identity.Name);

            if (user.Role.Identificator != "admin")
            {
                return(View("RezervaceCtenar", reservations));
            }
            return(View(reservations));
        }
        public static Reservation GetReservation(int id)
        {
            if (id >= 0) //existing user
            {
                return(ReservationDao.Find(id));
            }
            else if (id == -1) //new user or no user
            {
                return(new Reservation());
            }

            return(null);
        }
        public ActionResult ReservationSection(int id)
        {
            TourDao      tDao = new TourDao();
            IList <Tour> t    = new List <Tour>();

            t.Add(tDao.GetById(id));

            ViewBag.Tour = t;

            ReservationDao reservationDao = new ReservationDao();
            Reservation    reservation    = reservationDao.GetById(id);

            return(View(reservation));
        }
        public ActionResult Delete(int id)
        {
            try
            {
                ReservationDao rDao = new ReservationDao();

                rDao.Delete(rDao.GetById(id));
                TempData["succes"] = "Rezervace na termín úspěšně zrušena.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }
 public void ChangeReservation(PreorderTable table)
 {
     try
     {
         //save record to database
         ReservationDao.UpdateCustomerReservaition(table);
     }
     catch (HCSMSException ex)
     {
         raiseError(ex);
         throw new FaultException <HCSMSException>(ex);
     }
     catch (Exception ex)
     {
         raiseError(ex);
     }
 }
 public void CancelReservation(PreorderTable table)
 {
     try
     {
         //save record to database
         ReservationDao.DeleteReservationTable(table.Id);
     }
     catch (HCSMSException ex)
     {
         raiseError(ex);
         throw new FaultException <HCSMSException>(ex);
     }
     catch (Exception ex)
     {
         raiseError(ex);
     }
 }
        public ActionResult AddReservation(Reservation reservation, int tourId)
        {
            ReservationDao reservationDao = new ReservationDao();

            RandomGenerator generator        = new RandomGenerator();
            string          validationNumber = generator.RandomPassword();

            reservation.ValidationNumber = validationNumber;
            reservation.Status           = "nezaplaceno";

            reservation.KnihovnaUser = new KnihovnaUserDao().GetByLogin(User.Identity.Name);

            if (ModelState.IsValid)
            {
                TourDao tourDao = new TourDao();
                Tour    tour    = tourDao.GetById(tourId);

                reservation.Tour = tour;
                int result = DateTime.Compare(DateTime.Now, tour.StartDate);


                if (tour.CurrentCapacity < tour.Capacity && result < 0)
                {
                    reservationDao.Create(reservation);

                    tour.CurrentCapacity++;

                    tourDao.Update(tour);
                    reservationDao.Update(reservation);

                    TempData["message-success"] = "Vase rezervace byla uspesne odeslana, prosim ulozte si nasledujici kod: " + validationNumber;
                }
                else
                {
                    TempData["message-danger"] = "Je nam lito ale neni mozne provest rezervaci";
                }
            }
            else
            {
                return(RedirectToAction("Detail", "Tours", new { id = tourId }));
            }

            return(RedirectToAction("Detail", "Tours", new { id = tourId })); //presmerovani
        }
        public static int SaveReservation(int reservationId, int clientId, int userId, string destination, string hotel, int people, string details, int totalPrice, int paid, DateTime deadline, DateTime date)
        {
            if (reservationId >= 0) //existing reservation
            {
                var r = ReservationDao.Find(reservationId);

                r.ClientId         = clientId;
                r.UserId           = userId;
                r.Destination      = destination;
                r.HotelName        = hotel;
                r.PersonCount      = people;
                r.Details          = details;
                r.TotalPrice       = totalPrice;
                r.PaidAmount       = paid;
                r.FinalPaymentDate = deadline;
                r.ReservationDate  = date;

                ReservationDao.Update(r);

                return(r.Id);
            }
            else if (reservationId == -1) //new reservation
            {
                var r = new Reservation();

                r.ClientId         = clientId;
                r.UserId           = userId;
                r.Destination      = destination;
                r.HotelName        = hotel;
                r.PersonCount      = people;
                r.Details          = details;
                r.TotalPrice       = totalPrice;
                r.PaidAmount       = paid;
                r.FinalPaymentDate = deadline;
                r.ReservationDate  = date;

                r = ReservationDao.InsertReservation(r);

                return(r.Id);
            }

            return(-1);
        }
Esempio n. 25
0
        public ActionResult Delete(int id)
        {
            try
            {
                ActivityDao aDao = new ActivityDao();
                Activity    a    = aDao.GetById(id);

                if (a.SmallImageName != null)
                {
                    System.IO.File.Delete(Server.MapPath("~/Uploads/Activity/" + a.SmallImageName));
                }
                if (a.BigImageName != null)
                {
                    System.IO.File.Delete(Server.MapPath("~/Uploads/Activity/" + a.BigImageName));
                }

                //je zapotřebí smazat nejdrive vsechny terminy na tuto aktivitu, a take rezervace na tyto terminy
                TermDao        tDao   = new TermDao();
                ReservationDao resDao = new ReservationDao();
                IList <Term>   terms  = tDao.GetTermsByActivity(a);
                foreach (Term t in terms)
                {
                    IList <Reservation> reservations = resDao.GetAllReservationsByTerm(t);
                    foreach (Reservation res in reservations)
                    {
                        resDao.Delete(res);
                    }
                    tDao.Delete(t);
                }

                aDao.Delete(a);

                TempData["succes"] = "Aktivita " + a.Name + " úspěšně smazána. Stejně tak i všechny termíny na tuto akci.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 26
0
        public ActionResult Cancel(int id)
        {
            try
            {
                // Získání instance vybrané rezervace pro zrušení.
                ReservationDao reservationDao = new ReservationDao();
                Reservation    reservation    = reservationDao.GetById(id);

                // Píše chybu v dvojité session
                //reservation.Client.Credit += reservation.Lesson.ActivityType.Price;
                //FitnessCentreUserDao fitnessCentreUserDao = new FitnessCentreUserDao();
                //fitnessCentreUserDao.Update(reservation.Client);

                //reservation.Lesson.Capacity += 1;
                //LessonDao lessonDao = new LessonDao();
                //lessonDao.Update(reservation.Lesson);

                // Přičtení ceny aktivity zpět ke kreditu klienta a uvolnění 1 místa v kapacitě lekce. Zápis změn do databáze.
                reservation.Client.Credit += reservation.Lesson.ActivityType.Price;
                FitnessCentreUserDao fitnessCentreUserDao = new FitnessCentreUserDao();
                FitnessCentreUser    client = fitnessCentreUserDao.GetByLogin(reservation.Client.Login);
                fitnessCentreUserDao.Update(client);

                reservation.Lesson.ActualCapacity += 1;
                LessonDao lessonDao = new LessonDao();
                Lesson    lesson    = lessonDao.GetById(reservation.Lesson.Id);
                lessonDao.Update(lesson);

                TempData["message-success"] = "Rezervace aktivity " + reservation.Lesson.ActivityType.Name + " byla úspěšně zrušena.";

                // Smazání rezervace z databáze.
                reservationDao.Delete(reservation);
            }
            catch (Exception)
            {
                // mechanismus zachytávání výjimek doporučuje dobře si nastudovat
                throw;
            }

            return(RedirectToAction("Index", new { isActive = true }));
        }
Esempio n. 27
0
        public void FilterRouteBycationDate()
        {
            #region 서울 -> 정읍
            if (comboArrival.Text == "서울" && comboDeparture.Text == "정읍")
            {
                var result = from reservationtime in ReservationDao.GetAllReservationDate()
                             from route in RouteDao.GetByRouteId()
                             where reservationtime.RouteId == 1 && route.RouteId == 1 && DateTimePicker.Value.Date == reservationtime.ReservationDate
                             select new
                {
                    reservationtime.ArrivalTime,
                    reservationtime.DepartureTime,
                    reservationtime.ReservationDate,
                    route.ArrivalLocation,
                    reservationtime.TravelTime,
                    reservationtime.RouteId
                };

                routeBindingSource.DataSource = result;
            }
            #endregion
            #region 대전 -> 부산
            if (comboArrival.Text == "대전" && comboDeparture.Text == "부산")
            {
                var result = from reservationtime in ReservationDao.GetAllReservationDate()
                             from route in RouteDao.GetByRouteId()
                             where reservationtime.RouteId == 2 && route.RouteId == 2 && DateTimePicker.Value.Date == reservationtime.ReservationDate
                             select new
                {
                    reservationtime.ArrivalTime,
                    reservationtime.DepartureTime,
                    reservationtime.ReservationDate,
                    route.ArrivalLocation,
                    reservationtime.TravelTime,
                    reservationtime.RouteId
                };
                routeBindingSource.DataSource = result;
            }
            #endregion
        }
Esempio n. 28
0
        public Models.Reservation TransformDaoToBusinessLogicReservation(ReservationDao reservationDao)
        {
            using IDbConnection database = new SqlConnection(DatabaseConnectionString);

            const string roomQuery = "SELECT * FROM Hotel.Room WHERE roomNo = @roomNo";
            var          room      = database.QuerySingle <Models.Room>(roomQuery, new { roomNo = reservationDao.RoomNo });

            const string customerQuery = "SELECT * FROM Hotel.Customer WHERE id = @customerId";
            var          customer      = database.QuerySingle <Models.Customer>(customerQuery, new { customerId = reservationDao.CustomerId });

            return(new Models.Reservation()
            {
                Id = reservationDao.Id,
                Customer = customer,
                Room = room,
                Date = reservationDao.Date,
                PlannedArrivalDate = reservationDao.PlannedArrivalDate,
                DaysToStay = reservationDao.DaysToStay,
                CheckInDate = reservationDao.CheckInDate,
                CheckOutDate = reservationDao.CheckOutDate
            });
        }
        public ActionResult DeleteReservation(int id)
        {
            try
            {
                ReservationDao reservationDao = new ReservationDao();
                Reservation    reservation    = reservationDao.GetById(id);

                TourDao tourDao = new TourDao();
                Tour    tour    = tourDao.GetById(reservation.Tour.Id);

                tour.CurrentCapacity--;
                tourDao.Update(tour);

                reservationDao.Delete(reservation);

                TempData["message-success"] = "Rezervace " + reservation.ValidationNumber + " byla uspesne smazana z databazi";
            }
            catch (Exception e)
            {
                throw;
            }
            return(RedirectToAction("Rezervace", "Tours"));
        }
Esempio n. 30
0
        public Models.Reservation CreateReservation(ReservationDao reservation)
        {
            var reservationDao = new ReservationDao()
            {
                CustomerId         = reservation.CustomerId,
                RoomNo             = reservation.RoomNo,
                Date               = DateTime.Now.Date,
                PlannedArrivalDate = reservation.PlannedArrivalDate,
                DaysToStay         = reservation.DaysToStay,
                CheckInDate        = reservation.PlannedArrivalDate,
                CheckOutDate       = null
            };

            if (CheckIfRoomExist(reservationDao.RoomNo) == null || CheckIfCustomerExist(reservationDao.CustomerId) == null)
            {
                return(null);
            }

            using IDbConnection database = new SqlConnection(DatabaseConnectionString);
            const string insertQuery =
                "INSERT INTO Hotel.Reservation VALUES (@customerId, @roomNo, @date, @plannedArrivalDate, @daysToStay, @checkInDate, @checkOutDate); SELECT * FROM Hotel.Reservation WHERE id = SCOPE_IDENTITY()";

            return(TransformDaoToBusinessLogicReservation(database.QueryFirst <ReservationDao>(insertQuery, reservationDao)));
        }