Пример #1
0
        public static async System.Threading.Tasks.Task insertToFieldPermission(int userID, List <long> fieldIDlist)
        {
            using (var context = new AccModelEntities(Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
            {
                context.Database.CommandTimeout = 0;
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        List <UserFieldPermission> details = (from item in fieldIDlist
                                                              select new UserFieldPermission()
                        {
                            FieldID = (int)item,
                            UserID = userID
                        }).ToList();
                        context.UserFieldPermissions.AddRange(details);
                        await context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.ToString());
                        transaction.Rollback();
                    }
                }
            }
        }
Пример #2
0
 public static async System.Threading.Tasks.Task DeleteFieldPermission(int userID, List <long> fieldIDlist)
 {
     using (var context = new AccModelEntities(Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
     {
         context.Database.CommandTimeout = 0;
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 var dct = (from read in context.UserFieldPermissions where fieldIDlist.Any(i => read.FieldID == i) && read.UserID == userID select read);
                 if (dct != null && dct.Count() > 0)
                 {
                     context.UserFieldPermissions.RemoveRange(dct);
                     await context.SaveChangesAsync();
                 }
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 System.Windows.Forms.MessageBox.Show(ex.Message);
                 transaction.Rollback();
             }
         }
     }
 }
Пример #3
0
 public static void DeleteModulePermission(int userID)
 {
     using (var context = new AccModelEntities(Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
     {
         context.Database.CommandTimeout = 0;
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 context.SubSystemPermissions.RemoveRange(context.SubSystemPermissions.Where(a => a.UserID == userID));
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 System.Windows.Forms.MessageBox.Show(ex.Message);
                 transaction.Rollback();
             }
         }
     }
 }
Пример #4
0
 public static void insertToModulePermission(int userID, List <int> moduleIDlist, List <int> moduleIDlistOrginal)
 {
     using (var context = new AccModelEntities(Connections.AtiranAccModel.ConnectionInfo.BuildConnectionString()))
     {
         context.Database.CommandTimeout = 0;
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 foreach (var item in moduleIDlist)
                 {
                     Atiran.Connections.AtiranAccModel.SubSystemPermission mod = new SubSystemPermission
                     {
                         UserID      = userID,
                         SubSystemID = item
                     };
                     context.SubSystemPermissions.Add(mod);
                     context.SaveChanges();
                 }
                 List <int> DeleteFormPermisions = moduleIDlistOrginal.Except(moduleIDlist).ToList();
                 foreach (var item in DeleteFormPermisions)
                 {
                     List <int> formIDlist = (from read in context.Menus where read.SubSystemID == item && read.FormID > 0 select read.FormID.Value).Distinct().ToList();
                     var        dct        = (from read in context.UserFormPermissions where formIDlist.Any(i => read.FormID == i) && read.UserID == userID select read);
                     if (dct != null && dct.Count() > 0)
                     {
                         context.UserFormPermissions.RemoveRange(dct);
                         context.SaveChanges();
                     }
                 }
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 System.Windows.Forms.MessageBox.Show(ex.ToString());
                 transaction.Rollback();
             }
         }
     }
 }