Exemple #1
0
        public ActionResult Post(Spartan_BR_Action_ClassificationModel varSpartan_BR_Action_Classification)
        {
            try
            {
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _ISpartan_BR_Action_ClassificationApiConsumer.SetAuthHeader(_tokenManager.Token);



                var result = "0";
                var Spartan_BR_Action_ClassificationInfo = new Spartan_BR_Action_Classification
                {
                    ClassificationId = varSpartan_BR_Action_Classification.ClassificationId
                    , Description    = varSpartan_BR_Action_Classification.Description
                };

                result = varSpartan_BR_Action_Classification.ClassificationId.ToString() != "0" ?
                         _ISpartan_BR_Action_ClassificationApiConsumer.Update(Spartan_BR_Action_ClassificationInfo, null, null).Resource.ToString() :
                         _ISpartan_BR_Action_ClassificationApiConsumer.Insert(Spartan_BR_Action_ClassificationInfo, null, null).Resource.ToString();

                if (varSpartan_BR_Action_Classification.ClassificationId.ToString() != "0")
                {
                    result = varSpartan_BR_Action_Classification.ClassificationId.ToString();
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public HttpResponseMessage PutTunnel(Spartan_BR_Action_Classification 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.ClassificationId), "PUT"
                                             , dataString);

            return(Request.CreateResponse(HttpStatusCode.OK, result, Configuration.Formatters.JsonFormatter));
        }
        public HttpResponseMessage Delete(short id)
        {
            Spartan_BR_Action_Classification varSpartan_BR_Action_Classification = this.service.GetByKey(id, false);
            bool result = false;

            if (varSpartan_BR_Action_Classification == 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));
        }
        public HttpResponseMessage Post(Spartan_BR_Action_Classification varSpartan_BR_Action_Classification)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varSpartan_BR_Action_Classification));
                }
                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));
            }
        }