Beispiel #1
0
        public ActionResult MoreDetails(int Id)
        {
            if (Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var ToBeEdited = context.Reservations.Find(Id);


            //Sets reservation into view model
            ExpandedReservationDTO objReservationbDTO = new ExpandedReservationDTO
            {
                Id               = ToBeEdited.Id,
                Arrival          = ToBeEdited.Arrival,
                Departure        = ToBeEdited.Depature,
                UserId           = ToBeEdited.UserId,
                ApplicationUsers = ToBeEdited.ApplicationUsers,
                RoomId           = ToBeEdited.RoomId,
                Room             = ToBeEdited.Room,
                BoardTypeId      = ToBeEdited.BoardTypeId,
                BoardType        = ToBeEdited.BoardType,
                Status           = ToBeEdited.Status,
                Extras           = ToBeEdited.Extras.ToList(),
                Deposit          = ToBeEdited.Deposit,
                LeftToPay        = ToBeEdited.LeftToPay,
                TotalBill        = ToBeEdited.TotalBill
            };

            if (objReservationbDTO == null)
            {
                return(HttpNotFound());
            }
            return(View("MoreDetails", objReservationbDTO));
        }
Beispiel #2
0
        public ActionResult EditReservation([Bind(Include = "Id,Depature,Arrival,UserId,BoardTypeId,RoomId")] ExpandedReservationDTO objReservationbDTO)
        {
            try
            {
                if (objReservationbDTO == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var change = context.Reservations.Find(objReservationbDTO.Id);
                if (change == null)
                {
                    return(HttpNotFound());
                }

                //Updates details
                change.Arrival     = objReservationbDTO.Arrival;
                change.BoardType   = objReservationbDTO.BoardType;
                change.BoardTypeId = objReservationbDTO.BoardTypeId;
                change.Depature    = objReservationbDTO.Departure;
                change.RoomId      = objReservationbDTO.RoomId;
                change.Room        = objReservationbDTO.Room;

                if (OccupiedRoom(change)) //Throws error if new room booked
                {
                    throw new Exception("error");
                }
                else
                {
                    context.SaveChanges();
                }

                return(MoreDetails(objReservationbDTO.Id));
            }
            catch (Exception ex)
            {
                this.AddNotification("", NotificationType.ERROR);
                ViewBag.Error = ("Error: " + Convert.ToString(ex));
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
Beispiel #3
0
        // public ActionResult Create()
        public ActionResult CreateView()
        {
            ExpandedReservationDTO reservationDTO = new ExpandedReservationDTO {
                Arrival = DateTime.Today, Departure = DateTime.Today
            };

            //Sets viewbags for selectlists of board, users and rooms

            int max = 4;
            List <SelectListItem> NoOfGuests = new List <SelectListItem>();

            for (int a = 1; a <= max; a++)
            {
                NoOfGuests.Add(new SelectListItem {
                    Value = a.ToString(), Text = a.ToString()
                });
            }
            ViewBag.NoOfGuests = new SelectList(NoOfGuests, "Value", "Text");


            //Gets only the Extras that are allowed at booking
            reservationDTO.AllExtras = context.Extras.Where(x => x.Bookable == true).ToList();

            ViewBag.BoardTypeId = new SelectList(context.BoardTypes, "Id", "Board_Type");

            ViewBag.UserId = new SelectList(context.Users, "Id", "FirstName");

            ViewBag.RoomId =
                from u in context.Rooms
                select new SelectListItem
            {
                Value = u.Id.ToString(),
                Text  = u.RoomType.Room_Type + " - No. " + u.RoomNumber
            };

            return(View("CreateView", reservationDTO));
        }
Beispiel #4
0
        //public ActionResult Index(string searchString)
        public ActionResult Index(string searchString, string currentFilter, int?page)
        {
            try
            {
                int intPage           = 1;
                int intPageSize       = 5;
                int intTotalPageCount = 0;

                if (searchString != null) //if no search params
                {
                    intPage = 1;
                }
                else
                {
                    if (currentFilter != null) //if no current filters on search
                    {
                        searchString = currentFilter;
                        intPage      = page ?? 1;
                    }
                    else
                    {
                        searchString = "";
                        intPage      = page ?? 1;
                    }
                }

                ViewBag.CurrentFilter = searchString;


                List <ExpandedReservationDTO> col_ReservationDTO = new List <ExpandedReservationDTO>();
                int intSkip = (intPage - 1) * intPageSize;

                intTotalPageCount = context.Reservations
                                    .Where(x => x.ApplicationUsers.UserName.Contains(searchString))
                                    .Count();

                var result = context.Reservations //gets results of the search params
                             .Where(x => x.ApplicationUsers.UserName.Contains(searchString))
                             .OrderBy(x => x.ApplicationUsers.UserName)
                             .Skip(intSkip)
                             .Take(intPageSize)
                             .ToList();



                foreach (var item in result)
                {
                    ExpandedReservationDTO objReservationDTO = new ExpandedReservationDTO();

                    objReservationDTO.Arrival          = item.Arrival;
                    objReservationDTO.Id               = item.Id;
                    objReservationDTO.Departure        = item.Depature;
                    objReservationDTO.BoardType        = item.BoardType;
                    objReservationDTO.ApplicationUsers = UserManager.FindById(item.UserId);
                    objReservationDTO.Room             = item.Room;
                    objReservationDTO.TotalBill        = item.TotalBill;
                    objReservationDTO.LeftToPay        = item.LeftToPay;
                    objReservationDTO.Deposit          = item.Deposit;

                    col_ReservationDTO.Add(objReservationDTO);
                }

                // Set the number of pages
                var _UserDTOAsIPagedList =
                    new StaticPagedList <ExpandedReservationDTO>
                    (
                        col_ReservationDTO, intPage, intPageSize, intTotalPageCount
                    );

                return(View("Index", _UserDTOAsIPagedList));
            }
            catch (Exception ex)
            {
                this.AddNotification("", NotificationType.ERROR);
                ViewBag.Error = ("Error: " + Convert.ToString(ex));
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
Beispiel #5
0
        public ActionResult CreateView(ExpandedReservationDTO reservationDTO, bool paid)
        {
            try
            {
                if (reservationDTO == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                if (reservationDTO.NoOfGuests > context.RoomTypes.Find(context.Rooms.Find(reservationDTO.RoomId).RoomTypeId).Capacity)
                {
                    this.AddNotification("The Number of guests must be less than the capacity of the room!", NotificationType.ERROR);
                    ViewBag.Error = "The Number of guests must be less than the capacity of the room!";
                    return(Redirect("CreateView"));
                }

                var e = new Reservation //Sets reservcation
                {
                    Arrival          = reservationDTO.Arrival,
                    Depature         = reservationDTO.Departure,
                    UserId           = reservationDTO.UserId,
                    ApplicationUsers = context.Users.Find(reservationDTO.UserId),
                    BoardTypeId      = reservationDTO.BoardTypeId,
                    BoardType        = context.BoardTypes.Find(reservationDTO.BoardTypeId),
                    RoomId           = reservationDTO.RoomId,
                    Room             = context.Rooms.Find(reservationDTO.RoomId),
                    NoOfGuests       = reservationDTO.NoOfGuests,
                };

                if (paid == true)
                {
                    e.TotalBill = e.CalculateBookingBill((e.Depature - e.Arrival).Days);
                    e.Deposit   = e.CalculateDepositAmount((e.Depature - e.Arrival).Days);
                    e.LeftToPay = e.TotalBill - e.Deposit;
                }
                else
                {
                    e.TotalBill = e.CalculateBookingBill((e.Depature - e.Arrival).Days);
                    e.Deposit   = e.CalculateDepositAmount((e.Depature - e.Arrival).Days);
                    e.LeftToPay = e.TotalBill;
                }



                if (reservationDTO.SelectedExtra != null)
                {
                    foreach (int id in reservationDTO.SelectedExtra)
                    {
                        e.Extras.Add(context.Extras.Where(x => x.Id == id).FirstOrDefault());
                    }
                }

                if (OccupiedRoom(e) == true) //checks if occupied
                {
                    this.AddNotification("That room is already occupied on that date!", NotificationType.ERROR);
                    ViewBag.Error = "That room is already occupied on that date!";
                    return(Redirect("CreateView"));
                }
                else
                {
                    context.Reservations.Add(e);
                    context.SaveChanges();
                    return(Redirect("Index"));
                }
            }
            catch (Exception ex)
            {
                this.AddNotification("", NotificationType.ERROR);
                ViewBag.Error = ("Error: " + Convert.ToString(ex));
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }