Ejemplo n.º 1
0
        public IHttpActionResult UpdateWeaponById([FromUri] int weaponId, WeaponUpdateModel weaponToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateWeaponService();

            service.UpdateWeaponById(weaponId, weaponToUpdate);
            return(Ok());
        }
Ejemplo n.º 2
0
        public void UpdateWeaponById(int weaponId, WeaponUpdateModel weaponToUpdate)
        {
            var entity = _ctx.Weapons.Single(e => e.WeaponId == weaponId);

            if (entity != null)
            {
                if (weaponToUpdate.UpdatedName != null)
                {
                    entity.Name = weaponToUpdate.UpdatedName;
                }
                if (weaponToUpdate.UpdatedType != null)
                {
                    entity.Type = (WeaponType)weaponToUpdate.UpdatedType;
                }
                if (weaponToUpdate.UpdatedRange != null)
                {
                    entity.Range = weaponToUpdate.UpdatedRange;
                }
                if (weaponToUpdate.UpdatedWeaponColor != null)
                {
                    entity.WeaponColor = weaponToUpdate.UpdatedWeaponColor;
                }
                if (weaponToUpdate.UpdatedBladeOrEnergyColor != null)
                {
                    entity.BladeOrEnergyColor = weaponToUpdate.UpdatedBladeOrEnergyColor;
                }
                if (weaponToUpdate.UpdatedDamage != null)
                {
                    entity.Damage = weaponToUpdate.UpdatedDamage;
                }
                if (weaponToUpdate.UpdatedPrice != null)
                {
                    entity.Price = (int)weaponToUpdate.UpdatedPrice;
                }
                _ctx.SaveChanges();
            }
        }