Beispiel #1
0
        /// <summary>
        /// 保存操作
        /// </summary>
        /// <param name="sourceStr"></param>
        /// <returns></returns>
        //public Result SaveOperation(string sourceStr, Guid moduleID)
        //{
        //    Result result = new Result { IsSucess = true };
        //    var opsOriginal = operationBll.GetModuleOperation(moduleID);//原有op
        //    var opsCurrent = JsonConvert.DeserializeObject<List<Operation_Readonly_Model>>(sourceStr);//目前op

        //    try
        //    {
        //        var opsToAdd = (from o in opsCurrent
        //                        where string.IsNullOrEmpty(o.ID)
        //                        select o).ToList();

        //        var opsToDel = (from o in opsOriginal
        //                        where !(from checkedOp in opsCurrent select checkedOp.ID).Contains(o.ID.ToString())
        //                        select o).ToList();

        //        var opsToUpdate = (from o in opsCurrent
        //                           where !string.IsNullOrEmpty(o.ID)
        //                           select o).ToList();


        //        if (opsToAdd.Count != 0)
        //        {
        //            int index = opsOriginal.Count == 0 ? 1 : opsOriginal.OrderByDescending(o => o.OrderNum).FirstOrDefault().OrderNum;
        //            opsToAdd.ToList().ForEach(o =>
        //            {
        //                var newid = Guid.NewGuid();
        //                o.ID = newid.ToString();
        //                operationBll.Add(o.ToEntity(index++));

        //                //与管理员角色关联
        //                string[] defaultRoleNames = System.Configuration.ConfigurationManager.AppSettings["DefaultRole"].Split(';');

        //                foreach (string name in defaultRoleNames)
        //                {
        //                    var curRole = new DZAFCPortal.Authorization.DAL.RoleService().FirstOrDefault(r => r.Name == name);
        //                    if (curRole == null)
        //                        continue;

        //                    RoleOperation rel = new RoleOperation
        //                    {
        //                        OperationID = newid,
        //                        RoleID = curRole.ID

        //                    };

        //                    roleOperationBll.Add(rel);
        //                }

        //            });
        //        }

        //        if (opsToDel.Count != 0)
        //        {
        //            opsToDel.ToList().ForEach(o =>
        //            {
        //                operationBll.Remove(o);
        //                roleOperationBll.RemoveRelationWithOpID(o.ID);// 关联Role关系删除
        //                urlBll.RemoveAll(o.ID); //关联url删除
        //            });
        //        }

        //        if (opsToUpdate.Count != 0)
        //        {
        //            int index = opsOriginal.OrderByDescending(o => o.OrderNum).FirstOrDefault().OrderNum;
        //            opsToUpdate.ToList().ForEach(o =>
        //            {
        //                var entity = operationBll.GetByOpeationID(new Guid(o.ID));
        //                entity.Name = o.Name;
        //                operationBll.Update(entity);
        //            });
        //        }


        //        result.Message = "操作修改保存成功!";
        //    }
        //    catch (Exception ex)
        //    {
        //        result.IsSucess = false;
        //        result.Message = "保存异常,详细信息为" + ex.Message;
        //    }
        //    return result;

        //}

        public Result SaveOperation(string sourceStr, string moduleID)
        {
            var    op     = JsonConvert.DeserializeObject <Operation_Readonly_Model>(sourceStr);
            Result result = new Result {
                IsSucess = true
            };

            try
            {
                if (string.IsNullOrEmpty(op.ID))
                {
                    var newid = Guid.NewGuid().ToString();
                    op.ID = newid;
                    operationBll.Add(op.ToEntity());

                    //与管理员角色关联
                    var defaultRoleNames = DZAFCPortal.Config.AppSettings.DefaultRoles;

                    foreach (string name in defaultRoleNames)
                    {
                        var curRole = new DZAFCPortal.Authorization.DAL.RoleService().GenericService.FirstOrDefault(r => r.Name == name);
                        if (curRole == null)
                        {
                            continue;
                        }

                        RoleOperation rel = new RoleOperation
                        {
                            OperationID = newid,
                            RoleID      = curRole.ID
                        };

                        roleOperationBll.Add(rel);
                    }
                }
                else
                {
                    //update
                    var operationEntity = operationBll.GetByOpeationID(op.ID);
                    operationEntity.Name      = op.Name;
                    operationEntity.Code      = op.Code;
                    operationEntity.OrderNum  = op.OrderNum;
                    operationEntity.IsEnable  = op.IsEnable;
                    operationEntity.IsDelete  = op.IsDelete;
                    operationEntity.ControlID = op.Code;
                    operationBll.Update(operationEntity);
                }
                result.Message = "Success!";
            }
            catch (Exception ex)
            {
                result.IsSucess = false;
                result.Message  = "保存异常,详细信息为" + ex.Message;
            }
            return(result);
        }
        /// <summary>
        /// 加载所有角色
        /// </summary>
        private void InitLoadRoles(CheckBoxList cbl)
        {
            var roles = new DZAFCPortal.Authorization.DAL.RoleService().GenericService.GetAll(p => p.IsEnable).OrderBy(p => p.OrderNum);

            cbl.DataTextField  = "Name";
            cbl.DataValueField = "ID";

            cbl.DataSource = roles.ToList();
            cbl.DataBind();
        }