Exemplo n.º 1
0
        public HttpResponseMessage PutTunnel(Spartan_Format_Field emp, string user, string password)
        {
            var client = new System.Net.WebClient();

            client.Headers = TokenManager.GetAuthenticationHeader(user, password);
            client.Headers["Content-Type"] = "application/json";
            var dataString = new JavaScriptSerializer().Serialize(emp);

            var result = client.UploadString(new Uri(baseApi + ApiControllerUrl + "/Put?Id=" + emp.FormatFieldId), "PUT"
                                             , dataString);

            return(Request.CreateResponse(HttpStatusCode.OK, result, Configuration.Formatters.JsonFormatter));
        }
Exemplo n.º 2
0
        public ActionResult Post(bool IsNew, Spartan_Format_FieldModel varSpartan_Format_Field)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_tokenManager.GenerateToken())
                    {
                        return(Json(null, JsonRequestBehavior.AllowGet));
                    }
                    _ISpartan_Format_FieldApiConsumer.SetAuthHeader(_tokenManager.Token);



                    var result = "";
                    var Spartan_Format_FieldInfo = new Spartan_Format_Field
                    {
                        FormatFieldId         = varSpartan_Format_Field.FormatFieldId
                        , Format              = varSpartan_Format_Field.Format
                        , Field_Path          = varSpartan_Format_Field.Field_Path
                        , Physical_Field_Name = varSpartan_Format_Field.Physical_Field_Name
                        , Logical_Field_Name  = varSpartan_Format_Field.Logical_Field_Name
                        , Creation_Date       = DateTime.ParseExact(varSpartan_Format_Field.Creation_Date, ConfigurationProperty.DateFormat, CultureInfo.InvariantCulture as IFormatProvider)
                        , Creation_Hour       = varSpartan_Format_Field.Creation_Hour
                        , Creation_User       = varSpartan_Format_Field.Creation_User
                        , Properties          = varSpartan_Format_Field.Properties
                    };

                    result = !IsNew?
                             _ISpartan_Format_FieldApiConsumer.Update(Spartan_Format_FieldInfo, null, null).Resource.ToString() :
                                 _ISpartan_Format_FieldApiConsumer.Insert(Spartan_Format_FieldInfo, null, null).Resource.ToString();

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage Delete(int id)
        {
            Spartan_Format_Field varSpartan_Format_Field = this.service.GetByKey(id, false);
            bool result = false;

            if (varSpartan_Format_Field == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                result = this.service.Delete(id);//, globalData, dataReference);
            }
            catch (ServiceException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 4
0
        public HttpResponseMessage Post(Spartan_Format_Field varSpartan_Format_Field)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varSpartan_Format_Field));
                }
                catch (ServiceException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }
        }