Exemplo n.º 1
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();
             }
         }
     }
 }
Exemplo n.º 2
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();
             }
         }
     }
 }