Ejemplo n.º 1
0
        public async Task AddHeroAbilityStat(HeroAbilityStat stat)
        {
            bool success;
            DbUpdateException caughtException = null;

            try
            {
                await dataSource.AddEntity <HeroAbilityStat>(stat);

                success = true;
            }
            catch (DbUpdateException e)
            {
                success         = false;
                caughtException = e;
            }
            if (!success)
            {
                //check if there is already a stat with this id and if so throw error due to duplicate
                var lookupStat = await dataSource.LookupHeroAbilityStat(stat.HeroId, stat.AbilityId);

                if (lookupStat != null)
                {
                    throw new StatUpdaterException("A duplicate stat already exists.", caughtException);
                }
                else
                {
                    throw new StatUpdaterException("An error occurred when adding a stat.", caughtException);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task UpdateHeroAbilityStat(HeroAbilityStat stat)
        {
            bool success;
            DbUpdateConcurrencyException caughtException = null;

            try
            {
                await dataSource.UpdateEntity <HeroAbilityStat>(stat);

                success = true;
            }
            catch (DbUpdateConcurrencyException e)
            {
                success         = false;
                caughtException = e;
            }
            if (!success)
            {
                //check if there exists this stat if there isnt theres a problem or its been deleted etc so throw exception
                var lookupStat = await dataSource.LookupHeroAbilityStat(stat.HeroId, stat.AbilityId);

                if (lookupStat == null)
                {
                    //throw error no stat to update
                    throw new StatUpdaterException("No existing stat was found to update.", caughtException);
                }
                //if it does exist but we cant update for some reason rethrow original exception.
                throw new StatUpdaterException("An exception occurred when trying to update a stat.", caughtException);
            }
        }
Ejemplo n.º 3
0
 public static HeroAbilityStatDataTransferObject CreateHeroAbilityStatDataTransferObject(HeroAbilityStat a)
 {
     return(new HeroAbilityStatDataTransferObject
     {
         HeroId = a.HeroId,
         AbilityId = a.AbilityId,
         Matches = a.Matches,
         Wins = a.Wins
     });
 }