Пример #1
0
 public string Load()
 {
     try {
         db.BuisinessUnit();
         string         sql = "SELECT * FROM BuisinessUnit";
         List <NewUnit> xx  = new List <NewUnit>();
         NewUnit        all = new NewUnit();
         all.code  = null;
         all.id    = null;
         all.title = g.allUnitsTitle;
         xx.Add(all);
         using (SqlConnection connection = new SqlConnection(g.connectionString)) {
             connection.Open();
             using (SqlCommand command = new SqlCommand(sql, connection)) {
                 using (SqlDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         NewUnit x = ReadData(reader);
                         xx.Add(x);
                     }
                 }
             }
             connection.Close();
         }
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     }catch (Exception e) {
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Пример #2
0
 public string Save(NewUnit x)
 {
     try {
         db.BuisinessUnit();
         string sql = string.Format(@"BEGIN TRAN
                                         IF EXISTS (SELECT * from BuisinessUnit WITH (updlock,serializable) WHERE id = '{0}')
                                             BEGIN
                                                UPDATE BuisinessUnit SET code = '{1}', title = '{2}' WHERE id = '{0}'
                                             END
                                         ELSE
                                             BEGIN
                                                INSERT INTO BuisinessUnit (id, code, title)
                                                VALUES ('{0}', '{1}', '{2}')
                                             END
                                     COMMIT TRAN", x.id, x.code, x.title);
         using (SqlConnection connection = new SqlConnection(g.connectionString)) {
             connection.Open();
             using (SqlCommand command = new SqlCommand(sql, connection)) {
                 command.ExecuteNonQuery();
             }
             connection.Close();
         }
         return(JsonConvert.SerializeObject("Spremljeno", Formatting.None));
     } catch (Exception e) {
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Пример #3
0
    public NewUnit Get(string code)
    {
        NewUnit x = new NewUnit();

        try {
            db.BuisinessUnit();
            string sql = string.Format("SELECT * FROM BuisinessUnit WHERE code = '{0}'", code);
            using (SqlConnection connection = new SqlConnection(g.connectionString)) {
                connection.Open();
                using (SqlCommand command = new SqlCommand(sql, connection)) {
                    using (SqlDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            x = ReadData(reader);
                        }
                    }
                }
                connection.Close();
            }
            if (string.IsNullOrEmpty(code))
            {
                x.code  = null;
                x.id    = null;
                x.title = g.allUnitsTitle;
            }
            return(x);
        } catch (Exception e) {
            return(x);
        }
    }
Пример #4
0
        public void CommissionedUnitCubicFeetShouldNotExceedIntMaxValue()
        {
            var unitStoreMock    = new UnitStoreMock();
            var tenancyStoreMock = new TenancyStoreMock();
            var facade           = new Facade(unitStoreMock, new CustomerStoreDummy(), tenancyStoreMock, new DateServiceDummy());

            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "1A",
                Length              = 10,
                Width               = 10,
                Height              = 10,
                IsClimateControlled = true,
                IsVehicleAccessible = true,
                PricePerMonth       = 90
            });
            facade.CommissionNewUnit(new NewUnit()
            {
                UnitNumber          = "2B",
                IsClimateControlled = true,
                IsVehicleAccessible = true,
                PricePerMonth       = 90
            });


            var failUnit1 = new NewUnit()
            {
                UnitNumber          = "3C",
                Length              = int.MaxValue / 2,
                Width               = int.MaxValue / 2,
                Height              = 2,
                IsClimateControlled = false,
                IsVehicleAccessible = false,
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => facade.CommissionNewUnit(failUnit1));

            var failUnit2 = new NewUnit()
            {
                UnitNumber          = "4B",
                Length              = 1,
                IsClimateControlled = false,
                IsVehicleAccessible = false,
            };

            Assert.Throws <ArgumentException>(() => facade.CommissionNewUnit(failUnit2));

            var failUnit3 = new NewUnit()
            {
                UnitNumber          = "4B",
                Length              = 1,
                Width               = 5,
                Height              = 0,
                IsClimateControlled = false,
                IsVehicleAccessible = false,
            };

            Assert.Throws <ArgumentException>(() => facade.CommissionNewUnit(failUnit3));
        }
Пример #5
0
    public string Init()
    {
        NewUnit x = new NewUnit();

        x.id    = Guid.NewGuid().ToString();
        x.code  = null;
        x.title = null;
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }
Пример #6
0
    NewUnit ReadData(SqlDataReader reader)
    {
        NewUnit x = new NewUnit();

        x.id    = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
        x.code  = reader.GetValue(1) == DBNull.Value ? null : reader.GetString(1);
        x.title = reader.GetValue(2) == DBNull.Value ? null : reader.GetString(2);
        return(x);
    }
Пример #7
0
 public void BuildUnit(int index)
 {
     //Index wird via Button Event übergeben, welcher eine liste an möglichen baubaren units enthält
     if (mg.Resource > building.SpawnUnit[index].cost && GG.Supply < GG.MaxSupply)
     {
         GameObject NewUnit;
         Debug.Log("Building a unit");
         NewUnit = (GameObject)Instantiate(building.SpawnUnit[index].original, transform.position, transform.rotation);
         NewUnit.GetComponent <NavMeshAgent>().speed        = building.SpawnUnit[index].speed;
         NewUnit.GetComponent <NavMeshAgent>().acceleration = 1000f;
         mg.Resource -= building.SpawnUnit[index].cost;
     }
 }
Пример #8
0
        public void Create(NewUnitModel newUnit)
        {
            var unit = new NewUnit()
            {
                UnitNumber          = newUnit.UnitNumber,
                Length              = newUnit.Length,
                Width               = newUnit.Width,
                Height              = newUnit.Height,
                IsClimateControlled = newUnit.IsClimateControlled,
                IsVehicleAccessible = newUnit.IsVehicleAccessible,
                PricePerMonth       = newUnit.PricePerMonth
            };

            facade.CommissionNewUnit(unit);
        }
 public void Create(NewUnit newUnit) => Units.Add(mapper.Map <NewUnit, Unit>(newUnit));
Пример #10
0
 public void Create(NewUnit newUnit) => throw new NotSupportedException();