public RoomReservationViewModel()
        { RoomReservation_SponsorViewModel = new RoomReservation_SponsorViewModel();
        //default 1 RoomReservation_RoomDetailsViewDetail;
        RoomReservation_RoomDetailsViewDetailList = new List<RoomReservation_RoomDetailsViewDetail>();
        RoomReservation_RoomDetailsViewDetail room_detailviewmodel= new RoomReservation_RoomDetailsViewDetail();
        RoomReservation_RoomDetailsViewDetailList.Add(room_detailviewmodel);
        Guest = new Guest();
        Guest_DocumentsViewModel = new Guest_DocumentsViewModel();

        RoomReservation_Payment = new RoomReservation_Payment();
        Reservation_Total_OtherCurrency = 0; 
        }
            public object BindModel(
                ControllerContext controllerContext,
                ModelBindingContext bindingContext,
                MemberDescriptor memberDescriptor)
            {
                List<RoomReservation_RoomDetailsViewDetail> res = new List<RoomReservation_RoomDetailsViewDetail>();
                var form = controllerContext.HttpContext.Request.Form;
                int i = 0;
                while (!string.IsNullOrEmpty(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.RoomTypeId"]))
                {
                    var model = new RoomReservation_RoomDetailsViewDetail();
                    var Wing = new Wing();
                    
                    var RoomReservation_RoomDetails = new RoomReservation_RoomDetails();
                    if (! string.IsNullOrEmpty (form["RoomReservation_RoomDetailsViewModel["+i+"].RoomReservation_RoomDetails.Id"]))
                        RoomReservation_RoomDetails.Id = long.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.Id"]);

                    RoomReservation_RoomDetails.RoomTypeId = int.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.RoomTypeId"]);
                    RoomReservation_RoomDetails.RoomAllocationId = int.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.RoomAllocationId"]);
                    RoomReservation_RoomDetails.Rate = decimal.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.Rate"]);
                    RoomReservation_RoomDetails.Total = decimal.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.Total"]);
                    RoomReservation_RoomDetails.GST_Rate = decimal.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.GST_Rate"]);
                    RoomReservation_RoomDetails.GST_Charges = decimal.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.GST_Charges"]);
                    if (! string.IsNullOrEmpty (form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.RoomReservation_Id"]))
                        RoomReservation_RoomDetails.RoomReservation_Id = long.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].RoomReservation_RoomDetails.RoomReservation_Id"]);
                    Wing.Id = int.Parse(form["RoomReservation_RoomDetailsViewModel[" + i + "].Wing.WingId"]);


                    model.Wing = Wing;
                    model.RoomReservation_RoomDetails = RoomReservation_RoomDetails;
                    
                    res.Add(model);
                    i++;
                }

                return res;
             
        }
          public async Task<ActionResult> manage(int? id)
          {
              if ( id!=null)
              {
                  RoomReservationViewModel model = new RoomReservationViewModel();
                  model.Id = id;
                  //Get room reservations with all children
                  var roomreservationwithdetail =await _RoomReservationRepository.GetByIdwithChildren (id.Value.ToString());
                  var roomreservation  =await _RoomReservationRepository.GetById (id.Value.ToString ());
                  model.RoomReservation = roomreservation;

                  model.RoomReservation_RoomDetailsViewDetailList =new List<RoomReservation_RoomDetailsViewDetail> ();

                  foreach(var roomdetail in roomreservationwithdetail.RoomReservation_RoomDetails )
                      
                  {   var roomdetailview= new RoomReservation_RoomDetailsViewDetail();
                      roomdetailview.RoomReservation_RoomDetails= roomdetail;
                      roomdetail.RoomAllocation =await _RoomAllocationRepository.GetById(roomdetail.RoomAllocationId.Value.ToString ());
                      roomdetailview.Wing = await _WingRepository.GetById(roomdetail.RoomAllocation.WingId.ToString()); 

                      model.RoomReservation_RoomDetailsViewDetailList.Add(roomdetailview); }
                      
                  model.RoomReservation_Payment = roomreservationwithdetail.RoomReservation_Payment.LastOrDefault();
                  model.RoomReservation_FacilitiesViewModelList = await FillFacilties(roomreservationwithdetail.RoomReservation_Facilities.ToList());
                  model.RoomReservation_StatusViewModelList = await FillStatus(roomreservationwithdetail.RoomReservation_Status.LastOrDefault());

                  if (roomreservation.BookingForId ==(int) BookingFor.Guest )
                  {
                     var RoomReservation_SponsorViewModel = new RoomReservation_SponsorViewModel();

                      if (model.RoomReservation.SponsorTypeId ==(int) SponsorType.Club)
                  {
                     
                    var sponsor_club= await _ClubRepository.GetById(model.RoomReservation.Sponsor_ClubId.ToString());

                    RoomReservation_SponsorViewModel.CreditLimit = sponsor_club.CreditLimit.ToString ();
                    RoomReservation_SponsorViewModel.Name = sponsor_club.Name;


                  
                  }
                  else
                      {
                          var sponsor_member = await _MemberRepository.GetById(model.RoomReservation.Sponsor_MemberId.ToString());

                          RoomReservation_SponsorViewModel.CreditLimit = "";
                          RoomReservation_SponsorViewModel.Name = sponsor_member.FirstName + (string.IsNullOrEmpty (sponsor_member.Middle)? (" "+ sponsor_member.Middle) :"") +" " + sponsor_member.LastName; 
                      }


                      model.RoomReservation_SponsorViewModel = RoomReservation_SponsorViewModel;
                  }
                  await GetTypes(model);
                  


                  return View(model );
              }
                  else
                  {
                      await GetTypes();
              ModelState.Clear();
              
              RoomReservation_Payment roompayment = new RoomReservation_Payment();
            var paymentbyguest= await _PaymentByRepository.GetByName(RoomReservationSystem.Model.Enums.ePaymentBy.Guest.ToString ());
            roompayment.PaymentById = paymentbyguest.Id;
            var billtime_now =await _BillTimeRepository.GetByName(RoomReservationSystem.Model.Enums.BillTime.Now.ToString());
            roompayment.BillTimeId = billtime_now.Id;
              return View(new RoomReservationViewModel(){ RoomReservation =new RoomReservation ( ), RoomReservation_FacilitiesViewModelList= await FillFacilties (null), RoomReservation_StatusViewModelList=await FillStatus (), RoomReservation_Payment=roompayment }   );
              }

              
          }