public void NewCustomer(ICallRequest req) { Customer customer = req.ParseParams <Customer>(); // Preprocess call params customer.TrimAll(); // Set default values for missing values customer.Name = customer.Name ?? ""; customer.Email = customer.Email ?? ""; customer.Country = customer.Country ?? ""; // Validate call params if (customer.HasError(out string errorMsg)) { req.InvalidParams(errorMsg); return; } // Create a new Customer ID customer.CustomerId = ObjectId.NewObjectId(); var rid = "search.customer." + customer.Id; req.Service.With(rid, r => { // Send a create event. The ApplyCreate will store it in LiteDB. r.CreateEvent(customer); }); // Send success response with new resource ID req.Resource(rid); }
public void Delete(ICallRequest req) { // Send a change event with updated fields req.DeleteEvent(); // Send success response req.Ok(); }
public void Set(ICallRequest request) { var modelParams = request.ParseParams <MyModel>(); // Check if the Message property was changed if (modelParams.Message != null && modelParams.Message != myModel.Message) { // Update the model myModel.Message = modelParams.Message; // Send a change event with updated fields request.ChangeEvent(new Dictionary <string, object> { { "message", myModel.Message } }); } request.Ok(); }
public void Delete(ICallRequest request) { // Unmarshal book ID params to a Book model to easily extract the resource ID. Book deleteParams = request.ParseParams <Book>(); int idx = BookStore.DeleteBook(deleteParams.ResourceID); if (idx > -1) { request.RemoveEvent(idx); } // Send success response. It is up to the service to define if a delete // should be idempotent or not. In this case we send success regardless // if the book existed or not, making it idempotent. request.Ok(); }
/// <summary> /// Method called on a call request. /// </summary> /// <param name="request">Call request context.</param> private async Task handleCall(ICallRequest request) { if (callMethods != null) { if (callMethods.TryGetValue(request.Method, out Func <ICallRequest, Task> handler)) { await handler(request); return; } } if (callHandler != null) { await callHandler.Invoke(request); } else { request.MethodNotFound(); } }
public void New(ICallRequest request) { Book newParams = request.ParseParams <Book>(); // Validate that we received both title and author if (String.IsNullOrEmpty(newParams.Title) || String.IsNullOrEmpty(newParams.Author)) { request.InvalidParams("Must provide both title and author"); return; } // Add a new book to the store var add = BookStore.AddBook(newParams.Title, newParams.Author); // Send add event request.AddEvent(add.Ref, add.Idx); // Respond with a resource reference to the newly created book model request.Resource(add.Ref.ResourceID); }
public void Set(ICallRequest request) { Book bookParams = request.ParseParams <Book>(); var changed = new Dictionary <string, object>(2); // Check if the title property was provided if (bookParams.Title != null) { changed["title"] = bookParams.Title.Trim(); } // Check if the author property was provided if (bookParams.Author != null) { changed["author"] = bookParams.Author.Trim(); } // Send a change event with updated fields request.ChangeEvent(changed); // Send success response request.Ok(); }
public void Set(ICallRequest req) { Customer customerParams = req.ParseParams <Customer>(); // Preprocess call params customerParams.TrimAll(); // Validate call params if (customerParams.HasError(out string errorMsg)) { req.InvalidParams(errorMsg); return; } // Populate dictionary with updated fields var changed = new Dictionary <string, object>(3); if (customerParams.Name != null) { changed["name"] = customerParams.Name; } if (customerParams.Email != null) { changed["email"] = customerParams.Email; } if (customerParams.Country != null) { changed["country"] = customerParams.Country; } // Send a change event with updated fields req.ChangeEvent(changed); // Send success response req.Ok(); }
public void Bar(ICallRequest r) { }
public void Foo(ICallRequest r) { }
public void Foo‿Bar(ICallRequest r) { }
public void Foo(ICallRequest r) { Called++; }
public void Call(ICallRequest r) { }
public void New(ICallRequest r) { }
public void Double(ICallRequest r) { r.Ok(2 * (double)r.Params["value"]); }
RequestLogic(ICallRequest callRequest, IAdmin admin) { _callRequest = callRequest; _admin = admin; }