Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyDTO
- {
- public string IncludeProperties {get; set;}
- public Dictionary<string,string[]> Predicate {get; set;}
- }
- [HttpGet]
- [Route("FindAll")]
- public IEnumerable <Hotel> FindAll([FromUri] MyDTO predicateDTO) {
- return DataStore.FindAll <Hotel> (predicateDTO.IncludeProperties, PredicateHelper.ConvertStringToLambda <Hotel> (predicateDTO.Predicate));
- }
- var uri = '/api/Hotel/FindAll';
- var predicate = {
- "HotelName": ["HOtel", "==", ""],
- "PaymentStatus": ["True", "==", "AND"]
- }
- var data = {
- IncludeProperties: ["HotelDetails", "HotelDetails.HotelMainPhotos"],
- Predicate: predicate
- }
- busyIndicatorVisibility(true);
- $('#ModalOtel .modal-body').find(".media").remove();
- $.getJSON(uri, {
- predicateDTO: data
- }).done( //TODO something)
- public class Predicate
- {
- public string[] HotelName { get; set; } // In javascript can hold: ["HOtel", "==", ""]
- public string[] PaymentStatus { get; set; }
- }
- public class MyDTO
- {
- public string[] IncludeProperties { get; set; }
- public Predicate predicate { get; set; }
- }
- var predicate = {
- "HotelName": ["HOtel", "==", ""],
- "PaymentStatus": ["True", "==", "AND"]
- };
- var data = {
- IncludeProperties: ["HotelDetails", "HotelDetails.HotelMainPhotos"],
- Predicate: predicate
- };
- $.ajax(
- {
- url: uri,
- type: "POST",
- data: JSON.stringify(data), // To convert javascript objects in json strings.
- dataType: "json",
- contentType: "application/json; charset=utf-8", // To send json objects to the web api controller.
- beforeSend: function ()
- {
- console.log("Wait a minute...");
- },
- success: function (response)
- {
- console.log(response);
- }
- });
- {
- "IncludeProperties": [
- "HotelDetails",
- "HotelDetails.HotelMainPhotos"
- ],
- "Predicate": {
- "HotelName": [
- "HOtel",
- "==",
- ""
- ],
- "PaymentStatus": [
- "True",
- "==",
- "AND"
- ]
- }
- }
- public string FindAll(MyDTO predicateDTO) // This contains all model with submodels.
- {
- string result = "";
- // You can have access to predicateDTO instance with the current data;
- // predicateDTO.predicate.HotelName...
- return result;
- }
- [HttpGet]
- [Route("FindAll")]
- public IEnumerable<Hotel> FindAll(string[] IncludeProperties, string Predicate)
- {
- Dictionary<string,string[]> predicateAsDictionary = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(predicateString)
- return DataStore.FindAll<Hotel>(IncludeProperties, predicateAsDictionary);
- }
Add Comment
Please, Sign In to add comment