public HttpResponseMessage PutTunnel(Spartan_Format_Permissions 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.PermissionId), "PUT"
                                             , dataString);

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

            if (varSpartan_Format_Permissions == 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_Format_Permissions varSpartan_Format_Permissions)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varSpartan_Format_Permissions));
                }
                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));
            }
        }
        public ActionResult Post(bool IsNew, Spartan_Format_PermissionsModel varSpartan_Format_Permissions)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_tokenManager.GenerateToken())
                    {
                        return(Json(null, JsonRequestBehavior.AllowGet));
                    }
                    _ISpartan_Format_PermissionsApiConsumer.SetAuthHeader(_tokenManager.Token);



                    var result = "";
                    var Spartan_Format_PermissionsInfo = new Spartan_Format_Permissions
                    {
                        PermissionId        = varSpartan_Format_Permissions.PermissionId
                        , Format            = varSpartan_Format_Permissions.Format
                        , Permission_Type   = varSpartan_Format_Permissions.Permission_Type
                        , Apply             = varSpartan_Format_Permissions.Apply
                        , Spartan_User_Role = varSpartan_Format_Permissions.Spartan_User_Role
                    };

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

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }