public IHttpActionResult PutRoomReservation_Facilities(int id, RoomReservation_Facilities roomreservation_Facilities)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != roomreservation_Facilities.Id)
            {
                return BadRequest();
            }


            try
            {
                _RoomReservation_FacilitiesService.Update(roomreservation_Facilities);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomReservation_FacilitiesExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostRoomReservation_Facilities(RoomReservation_Facilities roomreservation_Facilities)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _RoomReservation_FacilitiesService.Create(roomreservation_Facilities);

            return CreatedAtRoute("DefaultApi", new { id = roomreservation_Facilities.Id }, roomreservation_Facilities);
        }
            public object BindModel(
                ControllerContext controllerContext,
                ModelBindingContext bindingContext,
                MemberDescriptor memberDescriptor)
            {
                List<RoomReservation_FacilitiesViewModel> res = new List<RoomReservation_FacilitiesViewModel>();
                var form = controllerContext.HttpContext.Request.Form;
                int i = 0;
                while (!string.IsNullOrEmpty(form["RoomReservation_FacilitiesViewModel[" + i + "].IsSelected"]))
                {
                    var model = new RoomReservation_FacilitiesViewModel();
                    var facility = new Facility();
                    var RoomReservation_Facilities = new RoomReservation_Facilities();
                    RoomReservation_Facilities.RoomReservation_Id = int.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.RoomReservation_Id"]);
                    RoomReservation_Facilities.FacilitiesId = int.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.FacilitiesId"]);
                    facility.IsFree = bool.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].Facility.IsFree"]);
                    facility.IsGST = bool.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].Facility.IsGST"]);
                    facility.Name = form["RoomReservation_FacilitiesViewModel[" + i + "].Facility.Name"];

                    RoomReservation_Facilities.Rate = decimal.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.Rate"]);

                    RoomReservation_Facilities.Total = decimal.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.Total"]);
                    RoomReservation_Facilities.Notes = form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.Notes"];

                    RoomReservation_Facilities.GST_Rate = decimal.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.GST_Rate"]);

                    RoomReservation_Facilities.GST_Charges = decimal.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].RoomReservation_Facilities.GST_Charges"]);




                    model.Facility = facility;
                    model.RoomReservation_Facilities = RoomReservation_Facilities;
                    model.IsSelected = bool.Parse(form["RoomReservation_FacilitiesViewModel[" + i + "].IsSelected"].Split(',')[0]) ;
                    res.Add(model);
                    i++;
                }

                return res;
             
        }
        public async  Task<RoomReservation_Facilities>  getCalculate_Facilities_Total(int facilityid,decimal toalroom_amount, DateTime checkin_datetime, DateTime checkout_datetime)
        {

            Facility facility =await _FacilityRepository.GetByIdWithChildren(facilityid);
            RoomReservation_Facilities room_facilties = new RoomReservation_Facilities();

            room_facilties.Rate= decimal.Parse (facility.Rate.ToString ()) ;
            room_facilties.Total =await  _RateTypeRepository.GetCalulated_RateType(facility.RateType.Id, room_facilties.Rate.Value ,toalroom_amount,  checkout_datetime.Subtract (checkin_datetime).Days );
            //things to do : 1. if gst applies  Get gst rate and gst total
            

            return room_facilties;
        
        }
      public async Task<JsonResult> getCalculate_Facilities_Total(int facilityid, decimal toalroom_amount, DateTime checkin_date, DateTime checkout_date, DateTime checkin_datetime, DateTime checkout_datetime)
    {

        Facility facility =await _FacilityRepository.GetByIdWithChildren(facilityid);
        RoomReservation_Facilities room_facilties = new RoomReservation_Facilities();

        room_facilties.Rate = decimal.Parse(facility.Rate.ToString());
        room_facilties.Total = await _RateTypeRepository.GetCalulated_RateType(facility.RateType.Id, room_facilties.Rate.Value, toalroom_amount, checkout_date.Subtract(checkin_date).Days);
        //things to do : 1. if gst applies  Get gst rate and gst total
        IEnumerable<Billing_Rules> billingrules = await _Billing_RulesRepository.GetBilling_Rules(checkin_datetime.ToString(datetimeformat), checkout_datetime.ToString(datetimeformat));
        decimal extraamount = 0;
        if (billingrules != null)
        {
            foreach (var rule in billingrules)
            {
                extraamount += rule.Charges * room_facilties.Rate.Value;

            }
        }
        room_facilties.Total = extraamount + room_facilties.Total;

        return Json(room_facilties);

    }
          public async Task<List<RoomReservation_FacilitiesViewModel>>  FillFacilties(List<RoomReservation_Facilities> dbroom_facilities=null)
        {
            var facilities = await _FacilityRepository.GetAllEnabled();
              var roomreservation_facilitieslistviewmodel = new List<RoomReservation_FacilitiesViewModel>();

             


                  foreach (var facility in facilities .OrderByDescending(z => z.IsFree))
                  {
                      

                      RoomReservation_Facilities roomreservation_facilities = (dbroom_facilities != null) ? dbroom_facilities.Where(rf => rf.FacilitiesId == facility.Id).FirstOrDefault() : new RoomReservation_Facilities();
                      if (roomreservation_facilities == null)
                          roomreservation_facilities = new RoomReservation_Facilities();

                      var roomreservation_facilitiesviewmodel = new RoomReservation_FacilitiesViewModel();
                      roomreservation_facilitiesviewmodel.Facility = facility;
                      roomreservation_facilities.FacilitiesId = facility.Id;
                      roomreservation_facilitiesviewmodel.IsSelected = facility.IsFree || roomreservation_facilities!= null;
                      roomreservation_facilitiesviewmodel.RoomReservation_Facilities = roomreservation_facilities;

                      roomreservation_facilitieslistviewmodel.Add(roomreservation_facilitiesviewmodel);

                  }


              
              

              


              return roomreservation_facilitieslistviewmodel;
        }