public TransportBase() { Read = new OperationBase(); Read.Type = "Get"; Update = new OperationBase(); Update.Type = "Put"; Destroy = new OperationBase(); Destroy.Type = "Delete"; Create = new OperationBase(); Create.Type = "Post"; }
protected Dictionary <string, object> SerializeCRUDOperatonValues(OperationBase CrudOpt) { var json = new Dictionary <string, object>(); if (CrudOpt.Url != null) { var urlStr = CrudOpt.Encode(CrudOpt.Url); if (CrudOpt.Type.HasValue()) { // if (CrudOpt.Type.ToLower().Equals("Get".ToLower())) // { //json["cache"] = true; // } if ((CrudOpt.Type.ToLower().Equals("Put".ToLower()) || CrudOpt.Type.ToLower().Equals("Delete".ToLower())) && !string.IsNullOrEmpty(EntityKeyName)) { var retUrl = "function(entity) { return '" + urlStr + "/' + entity." + EntityKeyName + "; }"; json["url"] = new ClientHandlerDescriptor { TemplateDelegate = obj => retUrl }; } if (!string.IsNullOrEmpty(CrudOpt.ReadFunction)) { json["url"] = new ClientHandlerDescriptor { TemplateDelegate = obj => CrudOpt.ReadFunction + "()" }; } else { if (CrudOpt.Type.ToLower().Equals("Get".ToLower()) && CrudOpt.Params.Count > 0) { var qString = string.Empty; foreach (var param in CrudOpt.Params) { qString += param.Key + "=" + param.Value + "&"; } qString = qString.Remove(qString.Length - 1); var retUrl = "function(entity) { return " + urlStr + "/?" + qString + "; }"; json["url"] = new ClientHandlerDescriptor { TemplateDelegate = obj => retUrl }; } else { if (!string.IsNullOrEmpty(CrudOpt.ActionName)) { //var retUrl = "eval('" + ActionName + "'); } "; json["url"] = new ClientHandlerDescriptor { TemplateDelegate = obj => "eval('" + CrudOpt.ActionName + "();');" }; } else { json["url"] = urlStr; } } } } //else //{ // if (!string.IsNullOrEmpty(CrudOpt.ActionName)) // { // json["url"] = new ClientHandlerDescriptor { TemplateDelegate = obj => "function() { return " + "" + CrudOpt.ActionName + "(); }" }; // } //} if (CrudOpt.DataType.HasValue()) { json["dataType"] = CrudOpt.DataType; } if (CrudOpt.Data.HasValue()) { json["data"] = CrudOpt.Data; } if (CrudOpt.Type.HasValue()) { json["type"] = CrudOpt.Type; } } return(json); }