コード例 #1
0
        public ActionResult SaveRoomReservation(string hotelReservationObj)
        {
            try
            {
                JavaScriptSerializer serializer        = new JavaScriptSerializer();
                ReservationVm        roomReservationVm = serializer.Deserialize <ReservationVm>(hotelReservationObj);

                Roomregister roomRegister = new Roomregister();
                roomRegister.Checkindate  = roomReservationVm.CheckinDate;
                roomRegister.Checkoutdate = roomReservationVm.CheckoutDate;
                roomRegister.Noofadult    = roomReservationVm.NoOfAdult;
                roomRegister.Noofchild    = roomReservationVm.NoOfChild;
                roomRegister.Status       = Roomregister.EntityStatus.Reserved;

                Roomregisterdetail roomRegisterDetail = new Roomregisterdetail();
                roomRegisterDetail.Advanceamount = roomReservationVm.AdvanceAmount;
                roomRegisterDetail.Billingtype   = roomReservationVm.BillingType;
                roomRegisterDetail.Contactno     = roomReservationVm.ContactNumber;
                roomRegisterDetail.Creditcardno  = roomReservationVm.CreditCardNo;
                roomRegisterDetail.Email         = roomReservationVm.Email;
                roomRegisterDetail.Firstname     = roomReservationVm.FirstName;
                roomRegisterDetail.Lastname      = roomReservationVm.LastName;
                roomRegisterDetail.Noofnight     =
                    roomReservationVm.CheckoutDate.Subtract(roomReservationVm.CheckinDate).Days;
                roomRegisterDetail.Status = Roomregisterdetail.EntityStatus.Reserved;
                roomRegister.Roomregisterdetails.Add(roomRegisterDetail);
                roomRegisterDetail.Roomregister = roomRegister;

                Customer customer = new Customer();
                customer.Firstname     = roomReservationVm.FirstName;
                customer.Lastname      = roomReservationVm.LastName;
                customer.Dob           = roomReservationVm.Dob;
                customer.Contactnumber = roomReservationVm.ContactNumber;
                customer.Email         = roomReservationVm.Email;
                customer.Address       = roomReservationVm.Address;
                customer.Nationality   = roomReservationVm.Nationality;
                customer.Nid           = roomReservationVm.Nid;
                customer.Passport      = roomReservationVm.Passport;
                customer.Remarks       = roomReservationVm.Remarks;

                IList <Roomhistory> roomHistories = new List <Roomhistory>();
                foreach (var roomId in roomReservationVm.RoomIds)
                {
                    Room room = _hotelReservationService.GetRoomById(Convert.ToInt64(roomId));
                    roomRegister.Rooms.Add(room);
                    Roomhistory roomHistory = new Roomhistory();
                    roomHistory.Arrivaldate  = roomRegister.Checkindate;
                    roomHistory.Leavedate    = roomRegister.Checkoutdate;
                    roomHistory.Roomregister = roomRegister;
                    roomHistory.Room         = room;
                    roomHistories.Add(roomHistory);
                }

                _hotelReservationService.SaveReservation(roomRegister, roomRegisterDetail, roomHistories, customer);
                return(RedirectToAction("Reservation", new { message = "Room Reserved Successfully", type = 1 }));
            }
            catch (Exception)
            {
                throw;
            }
            return(View());
        }