Example #1
0
        public async Task <HttpResponseMessage> Rename()
        {
            var            user          = GetSessionUser(Request.Headers.GetCookies().FirstOrDefault());
            List <NodeDto> successEntity = new List <NodeDto>(); //成功处理的Entity信息
            JDBCEntity     currentEntity = null;                 //当前处理的Entity信息

            try
            {
                var dict = ParseToQueryDictionary(Request.RequestUri);
                NameValueCollection form = Request.Content.ReadAsFormDataAsync().Result;
                var newname = GetValueFromForm(form, "name");
                currentEntity = await MyCoreApi.FindNodeByIdAsync(new Guid(GetValueFromForm(form, "node")));

                if (!await MyCoreApi.Authorization(currentEntity.Id, user, "1"))
                {
                    throw new Exception("Not authorization!");
                }
                var newNode = await MyCoreApi.ReNameNodeAsync(currentEntity.Id, newname);

                successEntity.Add(Mapper.Map <NodeDto>(newNode));//保存处理结果
                return(new HttpResponseMessage {
                    Content = new StringContent(SerializeObjectToString(successEntity), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                });
            }
            catch (Exception e)
            {
                if (currentEntity == null)
                {
                    return(new HttpResponseMessage {
                        StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(e.InnerException != null ? e.InnerException.Message : e.Message)
                    });
                }
                var response = new ResponseEntityMessage
                {
                    Fail = new
                    {
                        Description = e.InnerException != null ? e.InnerException.Message : e.Message,
                        Id          = currentEntity.Id,
                        Path        = currentEntity.Path
                    },
                    Success = successEntity
                };
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(SerializeObjectToString(response), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                });
            }
        }
Example #2
0
        public async Task <HttpResponseMessage> ModifyPermission([FromBody] PermissionModel model)
        {
            var user = GetSessionUser(Request.Headers.GetCookies().FirstOrDefault());

            try
            {
                Guid NodeId        = Guid.Empty;
                var  currentEntity = await MyCoreApi.FindNodeByIdAsync(model.nodeid);

                if (currentEntity != null)
                {
                    NodeId = currentEntity.Id;
                }
                if (!await MyCoreApi.Authorization(NodeId, user, "1"))
                {
                    throw new Exception("Not authorization!");
                }
                currentEntity.SetUser(model.user);
                currentEntity.QueryToParentPermission = model.inherit;
                currentEntity.OthersPermission        = model.others;
                currentEntity.GroupPermission.Clear();
                foreach (var item in model.groups)
                {
                    var index = item.IndexOf(":::");
                    if (index < 0)
                    {
                        return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                    }
                    var key   = item.Substring(0, index);
                    var value = item.Substring(index + 3);
                    if (key.Equals("") || value.Equals(""))
                    {
                        return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                    }
                    currentEntity.GroupPermission.Add(key, value);
                }
                await MyCoreApi.CoreService.SaveAsync(currentEntity);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            } catch (Exception e)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(e.Message)
                });
            }
        }
Example #3
0
        public async Task <HttpResponseMessage> Extra()
        {
            var            user          = GetSessionUser(Request.Headers.GetCookies().FirstOrDefault());
            List <NodeDto> successEntity = new List <NodeDto>(); //成功处理的Entity信息
            JDBCEntity     currentEntity = null;                 //当前处理的Entity信息

            try
            {
                var dict = ParseToQueryDictionary(Request.RequestUri);
                NameValueCollection form = Request.Content.ReadAsFormDataAsync().Result;
                var id = new Guid(GetValueFromForm(form, "node"));
                currentEntity = await MyCoreApi.FindNodeByIdAsync(id);//获取源entity

                if (!await MyCoreApi.Authorization(currentEntity.Id, user, "1"))
                {
                    throw new Exception("Not authorization!");
                }
                var extras = GetValuesFromForm(form, "extra[]", true);
                if (extras != null)
                {
                    currentEntity.ExtraInformation.Clear();
                    foreach (var extra in extras)
                    {
                        var index = extra.IndexOf(":::");
                        if (index < 0)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                        }
                        var key   = extra.Substring(0, index);
                        var value = extra.Substring(index + 3);
                        if (key.Equals("") || value.Equals(""))
                        {
                            return(new HttpResponseMessage(HttpStatusCode.Forbidden));
                        }
                        currentEntity.AddExtraInformation(key, value);
                    }
                    await MyCoreApi.CoreService.SaveAsync(currentEntity);
                }
                successEntity.Add(Mapper.Map <NodeDto>(currentEntity));
                return(new HttpResponseMessage {
                    Content = new StringContent(SerializeObjectToString(successEntity), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                });
            }
            catch (Exception e)
            {
                if (currentEntity == null)
                {
                    return(new HttpResponseMessage {
                        StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(e.InnerException != null ? e.InnerException.Message : e.Message)
                    });
                }
                var response = new ResponseEntityMessage
                {
                    Fail = new
                    {
                        Description = e.InnerException != null ? e.InnerException.Message : e.Message,
                        Id          = currentEntity.Id,
                        Path        = currentEntity.Path
                    },
                    Success = successEntity
                };
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(SerializeObjectToString(response), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                });
            }
        }