示例#1
0
        public ActionResult AddOrRemoveButtons()
        {
            String json = Request["data"];
            var rows = (ArrayList)MiniJSON.Decode(json);
            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    string functionIdStr = row["FunctionId"] == null ? null : row["FunctionId"].ToString();
                    Guid? functionId = string.IsNullOrEmpty(functionIdStr) ? null : new Guid?(new Guid(functionIdStr));
                    if (functionId.HasValue)
                    {
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new ValidationException("意外的托管功能标识" + functionId.Value);
                        }
                    }
                    var inputModel = new UiViewButton
                    {
                        Id = new Guid(row["Id"].ToString()),
                        IsEnabled = int.Parse(row["IsEnabled"].ToString()),
                        ButtonId = new Guid(row["ButtonId"].ToString()),
                        UiViewId = new Guid(row["UiViewId"].ToString()),
                        FunctionId = functionId
                    };

                    if (bool.Parse(row["IsAssigned"].ToString()))
                    {
                        if (AcDomain.RetrieveRequiredService<IRepository<UiViewButton>>().AsQueryable().Any(a => a.Id == inputModel.Id))
                        {
                            var updateModel = new UiViewButtonUpdateInput()
                            {
                                Id = inputModel.Id,
                                IsEnabled = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId
                            };
                            AcDomain.Handle(updateModel.ToCommand(AcSession));
                        }
                        else
                        {
                            var input = new UiViewButtonCreateInput()
                            {
                                Id = inputModel.Id,
                                ButtonId = inputModel.ButtonId,
                                IsEnabled = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId,
                                UiViewId = inputModel.UiViewId
                            };
                            AcDomain.Handle(input.ToCommand(AcSession));
                        }
                    }
                    else
                    {
                        AcDomain.Handle(new RemoveUiViewButtonCommand(AcSession, inputModel.Id));
                    }
                    if (functionId.HasValue)
                    {
                        int functionIsEnabled = int.Parse(row["FunctionIsEnabled"].ToString());
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new AnycmdException("意外的功能标识" + functionId.Value);
                        }
                        var input = new FunctionUpdateInput
                        {
                            Id = function.Id,
                            Code = function.Code,
                            SortCode = function.SortCode,
                            IsManaged = function.IsManaged,
                            IsEnabled = function.IsEnabled,
                            DeveloperId = function.DeveloperId,
                            Description = function.Description
                        };
                        input.IsEnabled = functionIsEnabled;
                        AcDomain.Handle(input.ToCommand(AcSession));
                    }
                }
            }

            return this.JsonResult(new ResponseData { success = true });
        }
示例#2
0
        public ActionResult AddOrRemoveButtons()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    string functionIdStr = row["FunctionId"] == null ? null : row["FunctionId"].ToString();
                    Guid?  functionId    = string.IsNullOrEmpty(functionIdStr) ? null : new Guid?(new Guid(functionIdStr));
                    if (functionId.HasValue)
                    {
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new ValidationException("意外的托管功能标识" + functionId.Value);
                        }
                    }
                    var inputModel = new UiViewButton(new Guid(row["Id"].ToString()))
                    {
                        IsEnabled  = int.Parse(row["IsEnabled"].ToString()),
                        ButtonId   = new Guid(row["ButtonId"].ToString()),
                        UiViewId   = new Guid(row["UiViewId"].ToString()),
                        FunctionId = functionId
                    };

                    if (bool.Parse(row["IsAssigned"].ToString()))
                    {
                        if (AcDomain.RetrieveRequiredService <IRepository <UiViewButton, Guid> >().AsQueryable().Any(a => a.Id == inputModel.Id))
                        {
                            var updateModel = new UiViewButtonUpdateInput()
                            {
                                Id         = inputModel.Id,
                                IsEnabled  = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId
                            };
                            AcDomain.Handle(updateModel.ToCommand(AcSession));
                        }
                        else
                        {
                            var input = new UiViewButtonCreateInput()
                            {
                                Id         = inputModel.Id,
                                ButtonId   = inputModel.ButtonId,
                                IsEnabled  = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId,
                                UiViewId   = inputModel.UiViewId
                            };
                            AcDomain.Handle(input.ToCommand(AcSession));
                        }
                    }
                    else
                    {
                        AcDomain.Handle(new RemoveUiViewButtonCommand(AcSession, inputModel.Id));
                    }
                    if (functionId.HasValue)
                    {
                        int           functionIsEnabled = int.Parse(row["FunctionIsEnabled"].ToString());
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new GeneralException("意外的功能标识" + functionId.Value);
                        }
                        var input = new FunctionUpdateInput
                        {
                            Id          = function.Id,
                            Code        = function.Code,
                            SortCode    = function.SortCode,
                            IsManaged   = function.IsManaged,
                            IsEnabled   = function.IsEnabled,
                            DeveloperId = function.DeveloperId,
                            Description = function.Description
                        };
                        input.IsEnabled = functionIsEnabled;
                        AcDomain.Handle(input.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }