Пример #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();
             }
         }
     }
 }