예제 #1
0
        public Task Execute(IJobExecutionContext context)
        {
            DbFunctions dfunc = null;
            var         users = dbContext.Users
                                .Include(x => x.Token)
                                .Where(x => SqlServerDbFunctionsExtensions.DateDiffDay(dfunc, x.Token.CreateAt, DateTime.Now) > 1)
                                .ToList();

            if (users.Any())
            {
                var transation = dbContext.Database.BeginTransaction();
                try
                {
                    foreach (var user in users)
                    {
                        if (!user.IsEmailConfirmed)
                        {
                            dbContext.Users.Remove(user);
                        }
                    }
                    dbContext.SaveChanges();
                    transation.Commit();
                }
                catch
                {
                    transation.Rollback();
                }
                finally
                {
                    transation.Dispose();
                    dbContext.Dispose();
                }
            }
            return(Task.FromResult(0));
        }
예제 #2
0
 private static void SeedData(EiMTDbContext context)
 {
     if (context.Users.FirstOrDefault(x => x.Email == "*****@*****.**") == null)
     {
         var admin    = new Role("Admin");
         var menager  = new Role("Menager");
         var employee = new Role("Employee");
         context.Roles.Add(admin);
         context.Roles.Add(menager);
         context.Roles.Add(employee);
         List <User> admins = new List <User>
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password")
         };
         List <User> menagers = new List <User>()
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
         };
         List <User> regular = new List <User>()
         {
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
             new User("*****@*****.**", "password"),
         };
         List <Sector> ssectors = new List <Sector>();
         var           sectors  = new List <string>
         {
             "IT", "Marketing", "Menagment", "Business"
         };
         int menId = 0;
         foreach (var user in admins)
         {
             admin.AddUser(user);
             user.IsEmailConfirmed = true;
         }
         foreach (var user in menagers)
         {
             menager.AddUser(user);
             var s = new Sector(sectors[menId], user);
             context.Sectors.Add(s);
             ssectors.Add(s);
             menId++;
             user.IsEmailConfirmed = true;
         }
         menId = menagers.Count - 1;
         foreach (var user in regular)
         {
             menId = menId % menagers.Count;
             employee.AddUser(user);
             user.IsEmailConfirmed = true;
             ssectors[menId].Employees.Add(user);
             menId++;
         }
         context.Users.AddRange(admins);
         context.Users.AddRange(menagers);
         context.Users.AddRange(regular);
         context.SaveChanges();
         menId = 0;
         foreach (var sec in ssectors)
         {
             sec.Employees.Add(menagers[menId]);
             menId++;
         }
         context.SaveChanges();
     }
 }
예제 #3
0
 public int Commit()
 {
     return(_context.SaveChanges());
 }