Ejemplo n.º 1
0
        public ActionResult Add(Models.Reservation.AddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.CustomerSelectList = GetCustomerSelectList();
                return(View(model));
            }
            var reservation = _reservationService.GetRoomByRoomIdWithDetail(model.RoomId);

            if (reservation.IsEmpty == false)
            {
                return(View("_ErrorNotExist"));
            }

            Reservation record = new Reservation();

            record.CustomerId      = model.CustomerId;
            record.RoomId          = reservation.RoomId;
            record.CreatedDateTime = DateTime.Now;
            record.EntryDate       = DateTime.Now;
            var result = _reservationService.Add(record);

            if (result > 0)
            {
                return(RedirectToAction(nameof(ReservationController.List)));
            }
            else
            {
                ViewBag.ErrorMessage     = "Not Saved";
                model.CustomerSelectList = GetCustomerSelectList();
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Models.Reservation.AddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.CustomerSelectList = GetCustomerSelectList();
                return(View(model));
            }

            var reservation = _reservationService.GetById(model.Id);

            if (reservation.ReleaseDate != null)
            {
                return(View("_ErrorNotExist"));
            }

            reservation.ReleaseDate = DateTime.Now;
            reservation.TotalDebt   = (Convert.ToInt32((DateTime.Now - reservation.EntryDate.Value).TotalDays));
            if (reservation.TotalDebt == 0)
            {
                reservation.TotalDebt = model.TotalDebt;
            }

            var result = _reservationService.Update(reservation);

            if (result <= 0)
            {
                ViewBag.ErrorMessage     = "Not Edited";
                model.CustomerSelectList = GetCustomerSelectList();

                return(View(model));
            }
            return(RedirectToAction(nameof(ReservationController.List)));
        }