Esempio n. 1
0
        public IEnumerable <Weapon> GetAllEntities()
        {
            var server  = SmoConnection.GetServer();
            var sqlText = "Select * From Weapons";
            var result  = server.ConnectionContext.ExecuteWithResults(sqlText);
            var list    = Cast.ToGenericList <Weapon>(result.Tables[0], false);

            return(list);
        }
Esempio n. 2
0
        public Weapon GetById(int id)
        {
            var server  = SmoConnection.GetServer();
            var sqlText = $"Select Top 1 * from Weapons Where WeaponId = {id}";
            var result  = server.ConnectionContext.ExecuteWithResults(sqlText);
            var list    = Cast.ToGenericList <Weapon>(result.Tables[0], false);

            return(list.Count > 0 ? list[0] : null);
        }
Esempio n. 3
0
        public void DeleteById(int id)
        {
            if (id <= 0)
            {
                throw new ArgumentException("Weapon must have a valid Id.");
            }
            var server = SmoConnection.GetServer();

            var sqlText = $"DELETE From Weapons"
                          + $"Where WeaponId = {id}";

            server.ConnectionContext.ExecuteNonQuery(sqlText);
        }
Esempio n. 4
0
        public void UpdateEntity(Weapon entity)
        {
            if (entity.WeaponId <= 0)
            {
                throw new ArgumentException("Weapon must have a valid Id");
            }
            var server = SmoConnection.GetServer();

            var sqlText = $"Update Weapons" +
                          $"Set WeaponName = {entity.WeaponName}, WeaponType = {entity.WeaponType}" +
                          $"Where WeaponId = {entity.WeaponId}";

            server.ConnectionContext.ExecuteNonQuery(sqlText);
        }
Esempio n. 5
0
        public void AddEntity(Weapon entity)
        {
            if (entity.WeaponId >= 1)
            {
                throw new ArgumentException("Cannot insert a weapon with a preset Id");
            }
            var server = SmoConnection.GetServer();

            var sqlText = $"INSERT INTO Weapons" +
                          $"(WeaponName, WeaponType)" +
                          $"VALUES" +
                          $"('{entity.WeaponName}', '{entity.WeaponType}')";

            server.ConnectionContext.ExecuteNonQuery(sqlText);
        }