Example #1
0
        public static Container CreateSuccessResponse(Encoder encoder)
        {
            var root   = encoder.CreateRoot();
            var result = encoder.AddContainer(root, "Result");

            encoder.AddBoolean(result, "Success", true);
            return(root);
        }
Example #2
0
        public static Container CreateSuccessResponseWithPaging(Encoder encoder, Container paging_request, int total_elements)
        {
            var root   = encoder.CreateRoot();
            var result = encoder.AddContainer(root, "Result");

            encoder.AddBoolean(result, "Success", true);
            var paging = encoder.AddContainer(root, "Paging");

            encoder.AddNumber(paging, "PageNumber", IntValue(paging_request.Get("PageNumber")));
            encoder.AddNumber(paging, "ElementsPerPage", IntValue(paging_request.Get("ElementsPerPage")));

            if (total_elements >= 0)
            {
                encoder.AddNumber(paging, "TotalPages", (int)Math.Ceiling((double)total_elements / FloatValue(paging_request.Get("ElementsPerPage"))));
                encoder.AddNumber(paging, "TotalElements", total_elements);
            }

            return(root);
        }
Example #3
0
        public static async Task DieOnErrorAsync(HttpResponse res, TextWriter output, Encoder encoder, string error, string message)
        {
            var root   = encoder.CreateRoot();
            var result = encoder.AddContainer(root, "Result");

            encoder.AddBoolean(result, "Success", false);
            Appixia.Engine.Mediums.Array details = encoder.AddArray(result, "Detail");
            var detail = encoder.AddContainerToArray(details);

            encoder.AddString(detail, "Error", error);
            encoder.AddString(detail, "Message", message);
            await encoder.RenderAsync(res, output, root);

            await output.FlushAsync();

            throw new DieException();
        }