コード例 #1
0
        /// <summary>
        /// Creates a new character in the database
        /// </summary>
        /// <param name="character">Character information for creation</param>
        /// <returns>Successful result of character creation</returns>
        public async Task <CharacterDTO> Create(CharacterDTO characterDTO)
        {
            Enum.TryParse(characterDTO.Species, out Species species);
            Enum.TryParse(characterDTO.Class, out Class userClass);

            Character character = new Character()
            {
                Name       = characterDTO.Name,
                Class      = userClass,
                Species    = species,
                WeaponId   = characterDTO.WeaponId,
                LocationId = characterDTO.LocationId,
                UserName   = characterDTO.UserName
            };

            _context.Entry(character).State = EntityState.Added;
            await _context.SaveChangesAsync();

            characterDTO.Id     = character.Id;
            characterDTO.Weapon = await _weapon.GetWeapon(characterDTO.WeaponId);

            characterDTO.CurrentLocation = await _location.GetLocation(characterDTO.LocationId);

            characterDTO.Inventory = new List <InventoryDTO>();
            characterDTO.StatSheet = new List <CharacterStatDTO>();
            return(characterDTO);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new weapon in the database
        /// </summary>
        /// <param name="weapon">Weapon information for creation</param>
        /// <returns>Successful result of weapon creation</returns>
        public async Task <Weapon> Create(Weapon weapon)
        {
            _context.Entry(weapon).State = EntityState.Added;
            await _context.SaveChangesAsync();

            return(weapon);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new stat in the database
        /// </summary>
        /// <param name="stat">Stat information for creation</param>
        /// <returns>Successful result of stat creation</returns>
        public async Task <StatDTO> Create(StatDTO stat)
        {
            Stat newStat = new Stat()
            {
                Name = stat.Name,
            };

            _context.Entry(newStat).State = EntityState.Added;
            await _context.SaveChangesAsync();

            stat.Id = newStat.Id;
            return(stat);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new item in the database
        /// </summary>
        /// <param name="item">Item information for creation</param>
        /// <returns>Successful result of item creation</returns>
        public async Task <ItemDTO> Create(ItemDTO itemDTO)
        {
            Item item = new Item()
            {
                Name  = itemDTO.Name,
                Value = itemDTO.Value
            };

            _context.Entry(item).State = EntityState.Added;
            await _context.SaveChangesAsync();

            itemDTO.Id = item.Id;
            return(itemDTO);
        }
コード例 #5
0
        /// <summary>
        /// Creates a new location in the database
        /// </summary>
        /// <param name="location">Location information for creation</param>
        /// <returns>Successful result of location creation</returns>
        public async Task <LocationDTO> Create(LocationDTO location)
        {
            Location entity = new Location()
            {
                Name        = location.Name,
                Description = location.Description
            };

            _context.Entry(entity).State = EntityState.Added;
            await _context.SaveChangesAsync();

            location.Id = entity.Id;
            return(location);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new characterStat in the database
        /// </summary>
        /// <param name="characterStat">CharacterStatDTO information for creation</param>
        /// <returns>Successful result of characterStat creation</returns>
        public async Task <CharacterStatDTO> Create(CharacterStatDTO characterStatDTO)
        {
            CharacterStat characterStat = new CharacterStat()
            {
                CharacterId = characterStatDTO.CharacterId,
                StatId      = characterStatDTO.StatId,
                Level       = characterStatDTO.Level
            };

            _context.Entry(characterStat).State = EntityState.Added;
            await _context.SaveChangesAsync();

            characterStatDTO.Stat = await _stat.GetStat(characterStatDTO.StatId);

            return(characterStatDTO);
        }
コード例 #7
0
        /// <summary>
        /// Create a new log
        /// </summary>
        /// <param name="context">Http context for current action</param>
        /// <returns>Successful result of log data</returns>
        public async Task <LogData> CreateLog(HttpContext context, string userName)
        {
            // Get message from context
            HttpRequestMessageFeature hreqmf = new HttpRequestMessageFeature(context);
            HttpRequestMessage        req    = hreqmf.HttpRequestMessage;
            DateTime dt  = DateTime.Now;
            LogData  log = new LogData()
            {
                Message = $"{req.Method.Method} call made by {userName} to {req.RequestUri.ToString()} on {String.Format("{0:ddd, MMM d, yyyy}", dt)} at {String.Format("{0:t}", dt)}."
            };

            _context.Entry(log).State = EntityState.Added;
            await _context.SaveChangesAsync();

            return(log);
        }
コード例 #8
0
        /// <summary>
        /// Creates a new enemy in the database
        /// </summary>
        /// <param name="enemyDTO">enemy information for creation</param>
        /// <returns>Successful result of enemy creation</returns>
        public async Task <EnemyDTO> Create(EnemyDTO enemyDTO)
        {
            Enum.TryParse(enemyDTO.Species, out Species species);
            Enemy enemy = new Enemy()
            {
                Abilities = enemyDTO.Abilities,
                Type      = enemyDTO.Type,
                Species   = species
            };

            _context.Entry(enemy).State = EntityState.Added;
            await _context.SaveChangesAsync();

            enemyDTO.Id   = enemy.Id;
            enemyDTO.Loot = new List <EnemyLootDTO>();
            return(enemyDTO);
        }
コード例 #9
0
 /// <summary>
 /// Handle the data seeding
 /// </summary>
 /// <param name="deserialized">Data from API</param>
 /// <param name="context">DB Context</param>
 public static void SeedData(Root deserialized, CryptsDbContext context)
 {
     if (deserialized.weapon_category == "" || deserialized.weapon_category == null)
     {
         Item newItem = new Item
         {
             Name  = deserialized.name,
             Value = $"{deserialized.cost.quantity} {deserialized.cost.unit}",
         };
         context.Entry(newItem).State = EntityState.Added;
         context.SaveChanges();
     }
     else
     {
         Weapon newWeapon = new Weapon
         {
             BaseDamage = deserialized.damage != null ? deserialized.damage.damage_dice : "1d6",
             Name       = deserialized.name,
             Type       = deserialized.weapon_category
         };
         context.Entry(newWeapon).State = EntityState.Added;
         context.SaveChanges();
     }
 }