private Task UpdatePowers(HeroesDbContext context, IHeroService heroService)
        {
            var powers = context.HeroPowers.Include(hp => hp.Power).Where(hp => hp.LastTrainingTime != null || hp.LastChangeTime != null).ToList();

            foreach (var heroPower in powers)
            {
                var timePassed  = DateTime.Now.Subtract(heroPower.LastChangeTime.GetValueOrDefault()).TotalHours;
                var timeChanged = Convert.ToInt32(Math.Floor(timePassed));

                if (timeChanged < Constants.HERO_POWER_MIN_CHANGE_TIME)
                {
                    continue;
                }

                var percentage  = Math.Pow(0.8, timeChanged);
                var newStrength = Convert.ToInt32(Convert.ToDouble(heroPower.Strength) * percentage);

                heroPower.Strength       = newStrength;
                heroPower.LastChangeTime = DateTime.Now;

                context.HeroPowers.Update(heroPower);
                context.SaveChanges();
                heroService.ChangeOverallStrength(heroPower.HeroId);
            }
            return(Task.CompletedTask);
        }
 public AuthenticationService(HeroesDbContext context, IHashingManager hashingManager, IOptions <AppSettings> appSettings, IJWTService jwtService)
 {
     _context        = context;
     _hashingManager = hashingManager;
     _appSettings    = appSettings.Value;
     _jwtService     = jwtService;
 }
 public UserService(HeroesDbContext context, IHashingManager hashingManager, IEmailSenderService emailSenderService, IJWTService jwtService)
 {
     _context            = context;
     _hashingManager     = hashingManager;
     _emailSenderService = emailSenderService;
     _jwtService         = jwtService;
 }
        public HeroesController(HeroesDbContext heroes)
        {
            _dbContext = heroes;

            if (!_dbContext.Heroes.Any())
            {
                //create a new hero if collection is empty
                //which means you cant delete all heroes
                _dbContext.Heroes.Add(new Hero {
                    Name = "Hero11"
                });
                _dbContext.Heroes.Add(new Hero {
                    Name = "Hero12"
                });
                _dbContext.Heroes.Add(new Hero {
                    Name = "Hero13"
                });
                _dbContext.Heroes.Add(new Hero {
                    Name = "Hero14"
                });
                _dbContext.Heroes.Add(new Hero {
                    Name = "Hero15"
                });
                _dbContext.SaveChanges();
            }
        }
Beispiel #5
0
 public TeamType(HeroesDbContext dbContext, IDataLoaderContextAccessor accessor)
 {
     Field(t => t.Id);
     Field(t => t.Name);
     Field(t => t.Description);
     Field <HeroType, Hero>()
     .Name("leader")
     .ResolveAsync(ctx =>
     {
         var dataLoader = accessor.Context.GetOrAddBatchLoader <int, Hero>("GetHeroById", async(ids) =>
         {
             return(await dbContext.Heroes.AsNoTracking().Where(h => ids.Contains(h.Id)).ToDictionaryAsync(x => x.Id));
         });
         return(dataLoader.LoadAsync(ctx.Source.LeaderId));
     });
     Field <MovieType, Movie>()
     .Name("movie")
     .ResolveAsync(ctx =>
     {
         var dataLoader = accessor.Context.GetOrAddBatchLoader <int, Movie>("GetMovieById", async(ids) =>
         {
             return(await dbContext.Movies.AsNoTracking().Where(m => ids.Contains(m.Id)).ToDictionaryAsync(x => x.Id));
         });
         return(dataLoader.LoadAsync(ctx.Source.MovieId));
     });
 }
Beispiel #6
0
 public VillainService(HeroesDbContext context, IPowerService powerService, IOptions <AppSettings> appSettings, IUserService userService)
 {
     _context      = context;
     _powerService = powerService;
     _appSettings  = appSettings.Value;
     _userService  = userService;
 }
Beispiel #7
0
        static List <SuperHero> GetSuperHeroes()
        {
            // This will create a session between DB and the .Net app
            HeroesDbContext context     = new HeroesDbContext();
            var             superHeroes = context.SuperHeroes.ToList();

            return(superHeroes);
        }
Beispiel #8
0
 public BattleService(HeroesDbContext context, IRewardService hashingManager, IHeroService heroService, IVillainService villainService, IOptions <AppSettings> appSettings)
 {
     _context        = context;
     _rewardService  = hashingManager;
     _heroService    = heroService;
     _villainService = villainService;
     _appSettings    = appSettings.Value;
 }
 public HeroService(HeroesDbContext context, IPowerService powerService, IHeroTypeService heroTypeService, IUserService userService, IOptions <AppSettings> appSettings, IRewardService rewardService)
 {
     _context         = context;
     _powerService    = powerService;
     _heroTypeService = heroTypeService;
     _userService     = userService;
     _appSettings     = appSettings.Value;
     _rewardService   = rewardService;
 }
Beispiel #10
0
        private Task UpdateBadges(HeroesDbContext context, IRewardService rewardService)
        {
            var heroes = rewardService.GetAllHeroesWithBadges();

            foreach (var hero in heroes)
            {
                rewardService.UpdateHeroBadges(hero);
            }

            return(Task.CompletedTask);
        }
 public HeroPowerService(HeroesDbContext context, IOptions <AppSettings> appSettings, IHeroService heroService)
 {
     _context     = context;
     _appSettings = appSettings.Value;
     _heroService = heroService;
 }
Beispiel #12
0
 public PowerService(HeroesDbContext context, IElementService elementService)
 {
     _context        = context;
     _elementService = elementService;
 }
 public HeroTypeService(HeroesDbContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public HeroesRepository(HeroesDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public RewardService(HeroesDbContext context)
 {
     _context = context;
 }
Beispiel #16
0
 public ElementService(HeroesDbContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public Handler(HeroesDbContext db, BpmnService bpmnService)
 {
     this.db          = db;
     this.bpmnService = bpmnService;
 }
Beispiel #18
0
        public HeroesQuery(HeroesDbContext dbContext)
        {
            FieldAsync <HeroType>(
                "hero",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await dbContext.Heroes.AsNoTracking().Include(h => h.SecretIdentity).FirstAsync(h => h.Id == id));
            }
                );

            FieldAsync <ListGraphType <HeroType> >(
                "heroes",
                resolve: async context =>
            {
                //if(context.SubFields.Any(f=>f.Key))
                //Find out what the fields are and dynamically build up the query
                return(await dbContext.Heroes.AsNoTracking().Include(h => h.SecretIdentity).ToListAsync());
            }
                );

            FieldAsync <AbilityType>(
                "ability",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await dbContext.Set <Ability>().AsNoTracking().FirstAsync(h => h.Id == id));
            }
                );

            FieldAsync <ListGraphType <AbilityType> >(
                "abilities",
                resolve: async context =>
            {
                return(await dbContext.Set <Ability>().AsNoTracking().ToListAsync());
            }
                );

            FieldAsync <MovieType>(
                "movie",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await dbContext.Movies.AsNoTracking().FirstAsync(h => h.Id == id));
            }
                );

            FieldAsync <ListGraphType <MovieType> >(
                "movies",
                resolve: async context =>
            {
                return(await dbContext.Movies.AsNoTracking().ToListAsync());
            }
                );

            FieldAsync <TeamType>(
                "team",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await dbContext.Teams.AsNoTracking().FirstAsync(h => h.Id == id));
            }
                );

            FieldAsync <ListGraphType <TeamType> >(
                "teams",
                resolve: async context =>
            {
                return(await dbContext.Teams.AsNoTracking().ToListAsync());
            }
                );

            FieldAsync <WeaponType>(
                "weapon",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                return(await dbContext.Set <Weapon>().AsNoTracking().FirstAsync(h => h.Id == id));
            }
                );

            FieldAsync <ListGraphType <WeaponType> >(
                "weapons",
                resolve: async context =>
            {
                return(await dbContext.Set <Weapon>().AsNoTracking().ToListAsync());
            }
                );
        }
 public Handler(BpmnService bpmnService, HeroesDbContext db)
 {
     this.bpmnService = bpmnService;
     this.db          = db;
 }
 public ChartService(HeroesDbContext context)
 {
     _context = context;
 }
Beispiel #21
0
 public Handler(HeroesDbContext db)
 {
     this.db = db;
 }
 public DbSeed(HeroesDbContext db)
 {
     this.db = db;
 }