Пример #1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);

            if (!contextProvider.UserIsAuthenticated)
            {
                context.Result = new JsonResult(ModelToClient.ErrorResponse("User not authenticated"));
            }
        }
Пример #2
0
        public async Task <JsonResult> Post([FromBody] ModelFromClient fromClient)
        {
            fromClient.Sanitize();

            try
            {
                if (fromClient.action == "init")
                {
                    ModelToClient toClient = new ModelToClient
                    {
                        formToken = Guid.NewGuid().ToString(),
                        sequence  = 1,
                        action    = "init"
                    };

                    return(new JsonResult(toClient));
                }
                else if (fromClient.action == "changed" || fromClient.action == "load" ||
                         fromClient.action == "ok" || fromClient.action == "clear" ||
                         fromClient.action == "new" || fromClient.action == "delete")
                {
                    if (fromClient.action == "new")
                    {
                        fromClient.root.key = "0";
                    }

                    return(new JsonResult(await(await contextProvider.BusinessProvider.RetreiveObject(contextProvider, fromClient.objectName,
                                                                                                      fromClient.root.key)).PerformActionAndCreateResponse(HttpContext, fromClient)));
                }

                return(new JsonResult(ModelToClient.ErrorResponse("Action " + fromClient.action + " not supported.")));
            }
            catch (Exception exp)
            {
                return(new JsonResult(ModelToClient.ErrorResponse(exp.Message)));
            }
        }