csharp-sdk-upm/Sample/LeanEngineApp/web/App.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2021-04-29 16:04:25 +08:00
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using LeanCloud.Storage;
using LeanCloud.Engine;
namespace web {
public class App {
// Function
[LCEngineFunction("ping")]
public static string Ping() {
return "pong";
}
[LCEngineFunction("hello")]
public static string Hello([LCEngineFunctionParam("name")] string name) {
string msg = $"hello, {name}";
Console.WriteLine(msg);
return msg;
}
[LCEngineFunction("getObject")]
public static async Task<LCObject> GetObject([LCEngineFunctionParam("className")] string className,
[LCEngineFunctionParam("id")] string id) {
LCQuery<LCObject> query = new LCQuery<LCObject>(className);
return await query.Get(id);
}
[LCEngineFunction("getObjects")]
public static async Task<ReadOnlyCollection<LCObject>> GetObjects() {
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
query.WhereGreaterThan("balance", 100);
return await query.Find();
}
[LCEngineFunction("getObjectMap")]
public static async Task<Dictionary<string, LCObject>> GetObjectMap() {
LCQuery<LCObject> query = new LCQuery<LCObject>("Todo");
ReadOnlyCollection<LCObject> todos = await query.Find();
return todos.ToDictionary(t => t.ObjectId);
}
}
}