Exemplo n.º 1
0
        public ActionResult GetFunction(Guid Id)
        {
            var function = _roleFunctionService.GetById(Id);
            var rs       = JsonFormaterUtils.Serialize(function);

            return(Content(rs));
        }
Exemplo n.º 2
0
        //TODO 权限部分
        // [AllowAnonymous]
        public ActionResult List(Guid roleId)
        {
            var functions = _roleFunctionService.GetShortMenu(roleId, true);

            var rs = JsonFormaterUtils.Serialize(functions);

            return(Content(rs));
        }
Exemplo n.º 3
0
        public static UploadImageResult Upload(string fileName, NameValueCollection nvc)
        {
            using (FileStream imageStream = File.Open(fileName, FileMode.Open))
            {
                imageStream.Seek(0, SeekOrigin.Begin);
                var imageBytes = new byte[imageStream.Length];
                imageStream.Read(imageBytes, 0, (int)imageStream.Length);

                var formGenerator = new PostFormGenerator();
                // 所有表单数据
                var bytesList = new ArrayList();
                // 普通表单
                foreach (var key in nvc.AllKeys)
                {
                    bytesList.Add(formGenerator.CreateFieldData(key, nvc[key]));
                }

                // 上传表单
                bytesList.Add(formGenerator.CreateFieldData("ImageUpload", fileName, "multipart/form-data", imageBytes));
                // 合成所有表单并生成二进制数组
                byte[] allBytes = formGenerator.JoinBytes(bytesList);

                // 返回的内容
                byte[] responseBytes;

                //上传服务地址
                var serviceUrl = ConfigurationManager.AppSettings["UploadServiceUrl"];
                if (string.IsNullOrWhiteSpace(serviceUrl))
                {
                    Logger.Error("serviceUrl没有配置地址");

                    return(new UploadImageResult
                    {
                        ReturnCode = -1
                    });
                }
                // 上传到指定Url
                bool success = formGenerator.UploadData(serviceUrl, allBytes, out responseBytes);

                if (!success)
                {
                    Logger.Error("Upload image failed! ");
                    var message = "Params: ";
                    foreach (var key in nvc.AllKeys)
                    {
                        message += string.Format("[{0}={1}]  ", key, nvc[key]);
                    }
                    Logger.Error("------" + message);

                    return(new UploadImageResult
                    {
                        ReturnCode = -1
                    });
                }
                return(JsonFormaterUtils.Deserialize <UploadImageResult>(Encoding.UTF8.GetString(responseBytes)));
            }
        }
Exemplo n.º 4
0
 public static BASE_FUNCTIONS ToEntity(this MenuItemContract source)
 {
     if (source == null)
     {
         throw new InvalidOperationException("source is null");
     }
     return(new BASE_FUNCTIONS
     {
         FUNCTIONS_NAME = source.Name,
         FUNCTIONS_ACTION = source.Action,
         FUNCTIONS_ID = source.MenuId,
         FUNCTIONS_PARENTID = source.ParentMenuId,
         FUNCTIONS_ORDERBY = source.OrderBy,
         FUNCTIONS_CATEGORY = source.Category,
         FUNCTIONS_ATTRIBUTES = JsonFormaterUtils.Serialize(source.Attributes)
     });
 }
Exemplo n.º 5
0
 public static MenuItemContract ToContract(this BASE_FUNCTIONS source)
 {
     if (source == null)
     {
         throw new InvalidOperationException("source is null");
     }
     return(new MenuItemContract
     {
         Name = source.FUNCTIONS_NAME,
         Action = source.FUNCTIONS_ACTION,
         MenuId = source.FUNCTIONS_ID,
         ParentMenuId = source.FUNCTIONS_PARENTID,
         //TODO:
         OrderBy = source.FUNCTIONS_ORDERBY.Value,
         Category = source.FUNCTIONS_CATEGORY,
         Attributes = JsonFormaterUtils.Deserialize <MenuItemAttributes>(source.FUNCTIONS_ATTRIBUTES) ?? new MenuItemAttributes()
     });
 }