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)
     {
          RoomReservation_SponsorViewModel  res = new RoomReservation_SponsorViewModel  ();
         var form = controllerContext.HttpContext.Request.Form;
                     
                 res.TypeId = int.Parse ( form["RoomReservation_SponsorViewModel.TypeId"] );
                 res.Name =   form["RoomReservation_SponsorViewModel.Name"]  ;
                 res.CreditLimit = form["RoomReservation_SponsorViewModel.CreditLimit"];
                 res.Id = form["RoomReservation_SponsorViewModel.Id"];
         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 }   );
              }

              
          }