Exemplo n.º 1
0
        public ResponseAgreement AddRoutingAgreement(RequestAgreement data, string webrootpath)
        {
            var model  = new Agreement();
            var result = new ResponseAgreement();

            try
            {
                var routesfile = File.AppendText(webrootpath + "/agreements");
                var routeline  = "|" + data.Id + "," + data.Name + "," + data.Url + "," + data.OperationService + "," + data.Type + "," + data.Operation;
                routesfile.Write(routeline);
                routesfile.Close();

                result.Code = 200;
                result.Data = new Agreement()
                {
                    Id               = data.Id,
                    Name             = data.Name,
                    Type             = data.Type,
                    OperationService = data.OperationService,
                    Operation        = data.Operation,
                    Url              = data.Url,
                };


                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
                result.Data    = null;
            }

            return(result);
        }
Exemplo n.º 2
0
        public ResponseAgreement  GetRoutingAgreement(string invoiceid, string webrootpath)
        {
            var model  = new Agreement();
            var result = new ResponseAgreement();

            try
            {
                var routesfile = File.ReadAllText(webrootpath + "/agreements");

                var routes = routesfile.Split('|');

                for (int i = 0; i < routes.Length; i++)
                {
                    bool service   = routes[i].StartsWith(invoiceid.Substring(0, 2));
                    bool operation = routes[i].EndsWith(invoiceid.Substring(2, 2));
                    if (service & operation)
                    {
                        var lstroute = routes[i].Split(',');
                        model.Id               = invoiceid;
                        model.InvoiceId        = Convert.ToInt32(invoiceid.Substring(4, 5));
                        model.Name             = lstroute[1];
                        model.Url              = lstroute[2];
                        model.OperationService = lstroute[3];
                        model.Type             = lstroute[4];
                        model.Operation        = lstroute[5];
                        break;
                    }
                }

                result.Code    = 200;
                result.Data    = model;
                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
                result.Data    = null;
            }

            return(result);
        }
Exemplo n.º 3
0
        public ResponseAgreement AddRoutingAgreement([FromBody] RequestAgreement data)
        {
            var result          = new ResponseAgreement();
            var validateRequest = SchemaEngine.Validate <RequestAgreement>(data, reqAgreementSchema);

            if (validateRequest)
            {
                var serv = new RoutingBusiness(HttpContext);
                result = serv.AddRoutingAgreement(data, webRootPath);

                if (result.Code == 200)
                {
                    var validate = SchemaEngine.Validate <ResponseAgreement>(result, respAgreementSchema);

                    if (!validate)
                    {
                        result.Code    = 500;
                        result.Message = "Invalid result data schema";
                        result.Data    = null;

                        return(result);
                    }
                }
                else
                {
                    return(result);
                }

                return(result);
            }
            else
            {
                result.Code    = 500;
                result.Message = "Invalid params schema";
                result.Data    = null;

                return(result);
            }
        }