public JsonResult GetAttributeList(DataTableRequest <AttributeFilter> model) { int page = model.start; int rowsPerPage = model.length; ServiceResultModel <List <AttributeVM> > serviceResult = _attributeService.GetAllAttributeList(model.FilterRequest); var gridRecords = serviceResult.Data.Skip(page).Take(rowsPerPage).ToList(); DataTablesResponse tableResult = new DataTablesResponse(model.draw, gridRecords, serviceResult.Data.Count, serviceResult.Data.Count); return(Json(tableResult, JsonRequestBehavior.AllowGet)); }
public ActionResult HotelDefinitionAddEdit(int?hotelId) { //HotelDefinitionVM hotelDefinition = new HotelDefinitionVM(); //if (hotelId.HasValue) // hotelDefinition = _hotelDefinitionService.GetHotel(hotelId.Value).Data; //var allCitiesData = _definitionService.GetCities().Data; //hotelDefinition.Cities = allCitiesData.Select(p => new BSelectListItem //{ // Disabled = false, // Text = p.Name, // Value = p.Id.ToString(), // Selected = hotelDefinition?.CityId > 0 ? p.Id == hotelDefinition.CityId : false //}); //hotelDefinition.Districts = allCitiesData.SelectMany(p => p.Districts) // .Select(p => new BSelectListItem // { // Text = p.Name, // Value = p.Id.ToString(), // ParentValue = p.CityId.ToString(), // Disabled = false, // Selected = hotelDefinition?.DistrictId > 0 // ? p.Id == hotelDefinition.DistrictId // : false // }); //hotelDefinition.HotelTypes = _hotelTypeService.GetAllHotelTypes(new HotelTypeFilter()).Data; HotelDefinitionVM hotelDefinition = new HotelDefinitionVM(); if (hotelId.HasValue) { hotelDefinition = _hotelService.GetHotel(hotelId.Value).Data; } ICacheManager cache = new MemCacheManager(); var data = cache.GetFromCache <List <CityDefinitionVM> >("Cities", () => _definitionService.GetCities().Data, null); var allCitiesData = _definitionService.GetCities().Data; hotelDefinition.Cities = allCitiesData.Select(p => new BSelectListItem { ParentValue = "0", Value = p.Id.ToString(), Text = p.Name, Selected = hotelId.HasValue ? hotelDefinition.CityId == p.Id : false }).AsEnumerable(); hotelDefinition.Districts = Enumerable.Empty <BSelectListItem>(); if (hotelId.HasValue && hotelDefinition?.CityId > 0 && hotelDefinition?.DistrictId > 0) { hotelDefinition.Districts = allCitiesData.SelectMany(p => p.Districts) .Where(p => p.CityId == hotelDefinition.CityId) .Select(c => new BSelectListItem { ParentValue = c.CityId.ToString(), Value = c.Id.ToString(), Text = c.Name, Selected = hotelId.HasValue ? hotelDefinition.DistrictId == c.Id : false }).AsEnumerable(); } hotelDefinition.HotelTypes = _hotelTypeService.GetAllHotelTypes(new HotelTypeFilter()).Data; List <CheckBoxListTemplate> attributes = _attributeService.GetAllAttributeList(new AttributeFilter { AttributeType = (int)AttributeType.Hotel }).Data .Select(p => new CheckBoxListTemplate { Id = p.Id, Text = p.Name, IsSelected = hotelDefinition.Id > 0 && hotelDefinition.HotelAttributes.Any(c => c.AttributeId == p.Id) }).ToList(); hotelDefinition.Attributes = attributes; return(View(hotelDefinition)); }