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<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; }