コード例 #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);
                }
            }
        }