コード例 #1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                MessageBox.Show("You have to fill every field in order to continue.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    Warehouse warehouse = new Warehouse();
                    warehouse.Id         = Convert.ToInt32(textBoxId.Text);
                    warehouse.Name       = textBoxName.Text;
                    warehouse.LocationId = locationRepositoryBus.GetLocationIdByName(comboBoxLocation.SelectedItem.ToString());
                    warehouseRepositoryBus.UpdateWarehouse(warehouse);

                    AutoClosingMessageBox.Show("You have successfully updated your Warehouse!", "Congratulations!", 1700);
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("You have to fill every field in order to continue.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
        public void UpdateWarehouseInDatabase()
        {
            using (TransactionScope scope = new TransactionScope()) //auto roll back
            {
                int       brojac    = 0;
                Warehouse warehouse = new Warehouse();

                warehouse.Name       = "Random name";
                warehouse.LocationId = 1024;

                warehouseRepositoryBus.InsertWarehouse(warehouse);

                foreach (Warehouse categ in warehouseRepositoryBus.GetAllWarehouses())
                {
                    if (categ.Name == warehouse.Name && categ.LocationId == warehouse.LocationId)
                    {
                        brojac++;
                        warehouse = categ;
                    }
                }
                Assert.AreEqual(1, brojac);
                warehouse.Name = "Updated name";
                warehouseRepositoryBus.UpdateWarehouse(warehouse);

                foreach (Warehouse categ in warehouseRepositoryBus.GetAllWarehouses())
                {
                    if (categ.Name == warehouse.Name && categ.LocationId == warehouse.LocationId)
                    {
                        brojac++;
                    }
                }
                Assert.AreEqual(2, brojac);
            }
        }