示例#1
0
        public async Task <WeaponResource> Create(WeaponResource entity)
        {
            var weapon = _mapper.Map <Weapon>(entity);

            // Ensure WeaponType is supplied
            if (weapon.WeaponType == null)
            {
                throw new InvalidModelException("weapon.WeaponType", "Null");
            }

            var weaponType = await _weaponTypeRepository.GetByWeaponType(weapon.WeaponType.Color, weapon.WeaponType.Arm);

            weapon.WeaponTypeID = weaponType.ID;
            weapon.WeaponType   = null;

            // Ensure WeaponCost is supplied
            if (weapon.WeaponCost == null)
            {
                throw new InvalidModelException("weapon.WeaponCost", "Null");
            }

            // Insert and save
            await _weaponRepository.Insert(weapon);

            await _weaponRepository.SaveChanges();

            return(_mapper.Map <WeaponResource>(weapon));
        }