Exemplo n.º 1
0
 /// <summary>
 /// Add Or Update(save)
 /// </summary>
 public void Save()
 {
     try
     {
         using (ProxyBE p = new ProxyBE())
         {
             Privilege pl = p.Client.GetPrivilege(SenderUser, parm.PrivilegeID);
             if (pl == null)
             {
                 pl = new Privilege();
             }
             pl.PrivilegeID   = parm.PrivilegeID;
             pl.PageURL       = parm.PageURL;
             pl.IconClass     = parm.IconClass;
             pl.PrivilegeName = parm.PrivilegeName;
             pl.PrivilegeCode = parm.PrivilegeCode;
             pl.Description   = parm.Description;
             pl.IsDisabled    = parm.IsDisabled;
             pl.CategoryID    = parm.CategoryID;
             pl.Sequence      = parm.Sequence;
             bool flag = p.Client.PrivilegeCodeIsDuplicated(SenderUser, pl);
             if (flag)
             {
                 throw new Exception("已经存在该编码,请重新填写!");
             }
             SavePrivilegeArgs args = new SavePrivilegeArgs();
             args.Privilege      = pl;
             args.PrivilegeItems = new List <PrivilegeItem>();
             string   PriviegeItems = Request["PriviegeItems"].ToString();
             JsonData sj            = JsonMapper.ToObject(PriviegeItems);
             if (sj.Count > 0)
             {
                 //遍历对象元素,保存
                 foreach (JsonData item in sj)
                 {
                     PrivilegeItem pi = new PrivilegeItem();
                     pi.PrivilegeItemID   = Guid.NewGuid();
                     pi.PrivilegeID       = pl.PrivilegeID;
                     pi.PrivilegeItemCode = item["Code"].ToString();
                     pi.PrivilegeItemName = item["Name"].ToString();
                     pi.IsDisabled        = false;
                     pi.Description       = "";
                     args.PrivilegeItems.Add(pi);
                 }
             }
             p.Client.SavePrivilege(SenderUser, args);
             WriteSuccess();
         }
     }
     catch (Exception ex)
     {
         WriteError(ex.Message, ex);
     }
 }
Exemplo n.º 2
0
        public void SavePrivilege(Sender sender, SavePrivilegeArgs args)
        {
            try
            {
                if (string.IsNullOrEmpty(args.Privilege.PrivilegeName))
                {
                    throw new CException("权限名称:{0}命名无效,可能存在特殊字符。", args.Privilege.PrivilegeName);
                }
                if (PrivilegeCodeIsDuplicated(sender, args.Privilege))
                {
                    throw new CException("权限编号:{0}已存在,请重新输入。", args.Privilege.PrivilegeCode);
                }

                //if (PrivilegeNameIsDuplicated(sender, args.Privilege))
                //{
                //    throw new CException("权限名称:{0}已存在,请重新输入。", args.Privilege.PrivilegeName);
                //}
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    Privilege p = new Privilege();
                    p.PrivilegeID = args.Privilege.PrivilegeID;
                    if (op.LoadPrivilegeByPrivilegeID(p) == 0)
                    {
                        args.Privilege.Created    = DateTime.Now;
                        args.Privilege.CreatedBy  = sender.UserCode + "." + sender.UserName;
                        args.Privilege.Modified   = DateTime.Now;
                        args.Privilege.ModifiedBy = sender.UserCode + "." + sender.UserName;
                        op.InsertPrivilege(args.Privilege);
                    }
                    else
                    {
                        args.Privilege.Modified   = DateTime.Now;
                        args.Privilege.ModifiedBy = sender.UserCode + "." + sender.UserName;
                        op.UpdatePrivilegeByPrivilegeID(args.Privilege);
                    }

                    if (args.PrivilegeItems != null)
                    {
                        //先把所有的功能项置为禁用
                        op.UpdatePrivilegeItemsByPrivilegeID(args.Privilege.PrivilegeID);
                        foreach (PrivilegeItem item in args.PrivilegeItems)
                        {
                            PrivilegeItem pi = new PrivilegeItem();
                            pi.PrivilegeID       = item.PrivilegeID;
                            pi.PrivilegeItemCode = item.PrivilegeItemCode;
                            if (op.LoadPrivilegeItemByPrivilegeID_PrivilegeItemCode(pi) == 0)
                            {
                                item.Created    = DateTime.Now;
                                item.CreatedBy  = sender.UserCode + "." + sender.UserName;
                                item.Modified   = DateTime.Now;
                                item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                op.InsertPrivilegeItem(item);
                            }
                            else
                            {
                                pi.IsDisabled = false;
                                pi.Modified   = DateTime.Now;
                                pi.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                op.UpdatePrivilegeItemByPrivilegeID_PrivilegeItemCode(pi);
                            }
                        }
                        //删除禁用的功能操作
                        op.DeletePrivilegeItemsByPrivilegeID_Disabled(args.Privilege.PrivilegeID);
                    }
                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }