예제 #1
0
        private ResponseObject post_matches_resource(string bodyData)
        {
            var condition  = true;
            var validation = new ValidationErrors(HttpStatusCode.OK, new Errors());

            if (!condition)
            {
                validation = new ValidationErrors(HttpStatusCode.Conflict, new Errors()
                {
                    ResponseMsgs.BuildError("409-11")
                });
            }
            if (!condition)
            {
                validation = new ValidationErrors(HttpStatusCode.InternalServerError, new Errors()
                {
                    ResponseMsgs.BuildError("500-10")
                });
            }

            if (validation.Item2.Count == 0)
            {
                var response = dal_post_matches_resource();
                return(Response.BuildMessage(HttpStatusCode.Created, response: response));
            }
            else
            {
                return(Response.BuildMessage(validation.Item1, errors: validation.Item2));
            }
        }
예제 #2
0
        private ResponseGET get_matches_instance(string instance_matches)
        {
            var condition  = true;
            var validation = new ValidationErrors(HttpStatusCode.OK, new Errors());

            if (!condition)
            {
                validation = new ValidationErrors(HttpStatusCode.NotFound, new Errors()
                {
                    ResponseMsgs.BuildError("404-11")
                });
            }
            if (!condition)
            {
                validation = new ValidationErrors(HttpStatusCode.InternalServerError, new Errors()
                {
                    ResponseMsgs.BuildError("500-10")
                });
            }

            if (validation.Item2.Count == 0)
            {
                var response = dal_get_matches_instance();
                return(Response.BuildGETMessage(HttpStatusCode.OK, response: response));
            }
            else
            {
                return(Response.BuildGETMessage(validation.Item1, errors: validation.Item2));
            }
        }
예제 #3
0
        public ResponseGET Get_Instance(string instance_matches)
        {
            Dictionary <string, Validator.StatusCode> objInstances  = new Dictionary <string, Validator.StatusCode>(),
                                                      objParameters = new Dictionary <string, Validator.StatusCode>(),
                                                      objUpdater    = new Dictionary <string, Validator.StatusCode>();

            #region validación de instancias
            objInstances["matches"] = Validator.StatusCode.Success;
            if (string.IsNullOrWhiteSpace(instance_matches))
            {
                objInstances["matches"] = Validator.StatusCode.MissingField;
            }
            #endregion

            var valInstances  = Validator.GroupFieldsByStatus(objInstances);
            var valParameters = Validator.GroupFieldsByStatus(objParameters);
            var valUpdater    = Validator.GroupFieldsByStatus(objUpdater);
            if (valInstances.Any(error => error["statuscode"].ToString() != "1") || valParameters.Any(error => error["statuscode"].ToString() != "1") || valUpdater.Any(error => error["statuscode"].ToString() != "1"))
            {
                var validation = new Dictionary <string, object> {
                    { "instances", valInstances }, { "parameters", valParameters }, { "updater", valUpdater }
                };
                return(Response.BuildGETMessage(HttpStatusCode.BadRequest, ResponseMsgs.BuildError(Response.CodeTypes.BadParameters, validation)));
            }
            else
            {
                return(get_matches_instance(instance_matches));
            }
        }
예제 #4
0
        public ResponseObject Put_Instance(string instance_matches, string bodyData)
        {
            Dictionary <string, Validator.StatusCode> objInstances  = new Dictionary <string, Validator.StatusCode>(),
                                                      objParameters = new Dictionary <string, Validator.StatusCode>(),
                                                      objUpdater    = new Dictionary <string, Validator.StatusCode>();

            #region validación de instancias
            objInstances["matches"] = Validator.StatusCode.Success;
            if (string.IsNullOrWhiteSpace(instance_matches))
            {
                objInstances["matches"] = Validator.StatusCode.MissingField;
            }
            #endregion

            #region validación de campos del updater
            var json_fields = new List <string> {
                { "title" }
            };
            var json_updater = ServiceBase.DeserializeUpdater(bodyData, json_fields, true);
            if (json_updater.Count == 0)
            {
                objUpdater["*"] = Validator.StatusCode.InvalidFormat;
            }
            else
            {
                foreach (var field in json_fields)
                {
                    objUpdater[field] = Validator.StatusCode.Success;
                }
            }
            #endregion

            var valInstances  = Validator.GroupFieldsByStatus(objInstances);
            var valParameters = Validator.GroupFieldsByStatus(objParameters);
            var valUpdater    = Validator.GroupFieldsByStatus(objUpdater);
            if (valInstances.Any(error => error["statuscode"].ToString() != "1") || valParameters.Any(error => error["statuscode"].ToString() != "1") || valUpdater.Any(error => error["statuscode"].ToString() != "1"))
            {
                var validation = new Dictionary <string, object> {
                    { "instances", valInstances }, { "parameters", valParameters }, { "updater", valUpdater }
                };
                return(Response.BuildMessage(HttpStatusCode.BadRequest, ResponseMsgs.BuildError(Response.CodeTypes.BadParameters, validation)));
            }
            else
            {
                return(put_matches_instance(instance_matches, bodyData));
            }
        }
예제 #5
0
        public ResponseGET Get_Resource()
        {
            Dictionary <string, Validator.StatusCode> objInstances  = new Dictionary <string, Validator.StatusCode>(),
                                                      objParameters = new Dictionary <string, Validator.StatusCode>(),
                                                      objUpdater    = new Dictionary <string, Validator.StatusCode>();

            var valInstances  = Validator.GroupFieldsByStatus(objInstances);
            var valParameters = Validator.GroupFieldsByStatus(objParameters);
            var valUpdater    = Validator.GroupFieldsByStatus(objUpdater);

            if (valInstances.Any(error => error["statuscode"].ToString() != "1") || valParameters.Any(error => error["statuscode"].ToString() != "1") || valUpdater.Any(error => error["statuscode"].ToString() != "1"))
            {
                var validation = new Dictionary <string, object> {
                    { "instances", valInstances }, { "parameters", valParameters }, { "updater", valUpdater }
                };
                return(Response.BuildGETMessage(HttpStatusCode.BadRequest, ResponseMsgs.BuildError(Response.CodeTypes.BadParameters, validation)));
            }
            else
            {
                return(get_matches_resource());
            }
        }