Exemplo n.º 1
0
        public JsonResult processPermissions(List <Spartan_Format_Permissions> list)
        {
            string respuesta = "";
            bool   token     = _tokenManager.GenerateToken();

            if (!token)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            else
            {
                _ISpartan_Format_PermissionsApiConsumer.SetAuthHeader(_tokenManager.Token);
                foreach (Spartan_Format_Permissions s in list)
                {
                    if (s.Apply == true)
                    {
                        if (s.PermissionId > 0)
                        {
                            respuesta = JsonConvert.SerializeObject(_ISpartan_Format_PermissionsApiConsumer.Update(s, null, null));
                        }
                        else
                        {
                            respuesta = JsonConvert.SerializeObject(_ISpartan_Format_PermissionsApiConsumer.Insert(s, null, null));
                        }
                    }
                    else
                    {
                        respuesta = JsonConvert.SerializeObject(_ISpartan_Format_PermissionsApiConsumer.Delete(s.PermissionId, null, null));
                    }


                    //return Json(_ISpartan_Format_PermissionsApiConsumer.Insert(s, null, null), JsonRequestBehavior.AllowGet);
                }

                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
        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));
            }
        }