コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: CustomerHandler.cs プロジェクト: lanicon/csharp-res
        public void Delete(ICallRequest req)
        {
            // Send a change event with updated fields
            req.DeleteEvent();

            // Send success response
            req.Ok();
        }
コード例 #3
0
ファイル: MyModelHandler.cs プロジェクト: lanicon/csharp-res
        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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        /// <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();
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
ファイル: CustomerHandler.cs プロジェクト: lanicon/csharp-res
        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();
        }
コード例 #9
0
 public void Bar(ICallRequest r)
 {
 }
コード例 #10
0
 public void Foo(ICallRequest r)
 {
 }
コード例 #11
0
 public void Foo‿Bar(ICallRequest r)
 {
 }
コード例 #12
0
 public void Foo(ICallRequest r)
 {
     Called++;
 }
コード例 #13
0
 public void Call(ICallRequest r)
 {
 }
コード例 #14
0
 public void New(ICallRequest r)
 {
 }
コード例 #15
0
 public void Double(ICallRequest r)
 {
     r.Ok(2 * (double)r.Params["value"]);
 }
コード例 #16
0
 RequestLogic(ICallRequest callRequest, IAdmin admin)
 {
     _callRequest = callRequest;
     _admin       = admin;
 }