Example #1
0
 public int CreateRole(MyRoles role, int[] function)
 {
     using (var scope = EFContextFactory.GetCurrentDbContext().Database.BeginTransaction())
     {
         try
         {
             foreach (var item in function)
             {
                 DataRepository.Add <RoleFunction>(new RoleFunction()
                 {
                     RoleID     = role.Id,
                     FunctionID = item,
                 });
             }
             DataRepository.Add <MyRoles>(role);
             scope.Commit();
             LogHelper.WriteLog("添加角色及权限", "1" + role.ObjectToJson());
             return(1);
         }
         catch (Exception ex)
         {
             ErrorLogHelper.WriteLog(ex);
             scope.Rollback();
             return(0);
         }
     }
 }
Example #2
0
 public int EditRole(MyRoles role, int[] function)
 {
     using (var scope = EFContextFactory.GetCurrentDbContext().Database.BeginTransaction())
     {
         try
         {
             DataRepository.DB.Database.ExecuteSqlCommand("delete from rolefunction where roleid='" + role.Id + "'");
             foreach (var item in function)
             {
                 DataRepository.DB.Set <RoleFunction>().Add(new RoleFunction
                 {
                     RoleID     = role.Id,
                     FunctionID = item,
                 });
             }
             List <string> fields = new List <string>();
             fields.Add("Description");
             fields.Add("Name");
             DataRepository.UpdateSetEntityFields <MyRoles>(role, fields);
             DataRepository.DB.SaveChanges();
             scope.Commit();
             LogHelper.WriteLog("修改角色及权限", "1", function + role.ObjectToJson());
             return(1);
         }
         catch (Exception ex)
         {
             ErrorLogHelper.WriteLog(ex);
             scope.Rollback();
             return(0);
         }
     }
 }
        /// <summary>
        /// 获取所有的分组,功能
        /// </summary>
        /// <returns></returns>
        public FunctionGroupDataViewModel GetFunctionGroupList()
        {
            FunctionGroupDataViewModel Data = new FunctionGroupDataViewModel();
            var functionGroupData           = EFContextFactory.GetCurrentDbContext().Set <FunctionGroup>().Where(a => a.State == 1);
            var functionData = EFContextFactory.GetCurrentDbContext().Set <Function>().Where(a => a.Status == 1);

            Data.FunctionGroup = functionGroupData.ToList();
            Data.Function      = functionData.ToList();
            return(Data);
        }
Example #4
0
 /// <summary>
 /// 代表当前应用程序跟数据库的回话内所有的实体变化,更新会数据库
 /// </summary>
 /// <returns></returns>
 public int SaveChanges()  //UintWork单元工作模式
 {
     //调用EF上下文的SaveChanges的方法
     try
     {
         return(EFContextFactory.GetCurrentDbContext().SaveChanges());
     }
     catch (Exception ex)
     {
         Log4NetHelper.Error(this, "DbContext SaveChanges", ex);
         return(-1);
     }
 }
Example #5
0
 /// <summary>
 /// 执行一个sql脚本的方法
 /// </summary>
 /// <param name="strSql">sql语句</param>
 /// <param name="parameters">参数</param>
 /// <returns></returns>
 public int ExcuteSql(string strSql, System.Data.Common.DbParameter[] parameters)
 {
     return(EFContextFactory.GetCurrentDbContext().Database.ExecuteSqlCommand(strSql, parameters));
 }
Example #6
0
 /// <summary>
 /// 代表:当前应用程序跟数据库的绘画内所有的实体的变化,更新数据库
 /// </summary>
 /// <returns></returns>
 public int SaveChanges() //目标是实现单元工作模式(UintWork)
 {
     //调用EF上下文的SaveChanges方法
     return(EFContextFactory.GetCurrentDbContext().SaveChanges());
 }