Guest User

Untitled

a guest
Nov 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. public class MyDTO
  2. {
  3. public string IncludeProperties {get; set;}
  4. public Dictionary<string,string[]> Predicate {get; set;}
  5. }
  6.  
  7. [HttpGet]
  8. [Route("FindAll")]
  9. public IEnumerable <Hotel> FindAll([FromUri] MyDTO predicateDTO) {
  10. return DataStore.FindAll <Hotel> (predicateDTO.IncludeProperties, PredicateHelper.ConvertStringToLambda <Hotel> (predicateDTO.Predicate));
  11. }
  12.  
  13. var uri = '/api/Hotel/FindAll';
  14. var predicate = {
  15. "HotelName": ["HOtel", "==", ""],
  16. "PaymentStatus": ["True", "==", "AND"]
  17. }
  18. var data = {
  19. IncludeProperties: ["HotelDetails", "HotelDetails.HotelMainPhotos"],
  20. Predicate: predicate
  21. }
  22. busyIndicatorVisibility(true);
  23. $('#ModalOtel .modal-body').find(".media").remove();
  24. $.getJSON(uri, {
  25. predicateDTO: data
  26. }).done( //TODO something)
  27.  
  28. public class Predicate
  29. {
  30. public string[] HotelName { get; set; } // In javascript can hold: ["HOtel", "==", ""]
  31. public string[] PaymentStatus { get; set; }
  32. }
  33. public class MyDTO
  34. {
  35. public string[] IncludeProperties { get; set; }
  36. public Predicate predicate { get; set; }
  37. }
  38.  
  39. var predicate = {
  40. "HotelName": ["HOtel", "==", ""],
  41. "PaymentStatus": ["True", "==", "AND"]
  42. };
  43. var data = {
  44. IncludeProperties: ["HotelDetails", "HotelDetails.HotelMainPhotos"],
  45. Predicate: predicate
  46. };
  47.  
  48. $.ajax(
  49. {
  50. url: uri,
  51. type: "POST",
  52. data: JSON.stringify(data), // To convert javascript objects in json strings.
  53. dataType: "json",
  54. contentType: "application/json; charset=utf-8", // To send json objects to the web api controller.
  55. beforeSend: function ()
  56. {
  57. console.log("Wait a minute...");
  58. },
  59. success: function (response)
  60. {
  61. console.log(response);
  62. }
  63. });
  64.  
  65. {
  66. "IncludeProperties": [
  67. "HotelDetails",
  68. "HotelDetails.HotelMainPhotos"
  69. ],
  70. "Predicate": {
  71. "HotelName": [
  72. "HOtel",
  73. "==",
  74. ""
  75. ],
  76. "PaymentStatus": [
  77. "True",
  78. "==",
  79. "AND"
  80. ]
  81. }
  82. }
  83.  
  84. public string FindAll(MyDTO predicateDTO) // This contains all model with submodels.
  85. {
  86. string result = "";
  87. // You can have access to predicateDTO instance with the current data;
  88. // predicateDTO.predicate.HotelName...
  89. return result;
  90. }
  91.  
  92. [HttpGet]
  93. [Route("FindAll")]
  94. public IEnumerable<Hotel> FindAll(string[] IncludeProperties, string Predicate)
  95. {
  96. Dictionary<string,string[]> predicateAsDictionary = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(predicateString)
  97. return DataStore.FindAll<Hotel>(IncludeProperties, predicateAsDictionary);
  98. }
Add Comment
Please, Sign In to add comment