private void btnDeleteShipper_Click(object sender, EventArgs e) { try { int temp; if (int.TryParse(tboShipperID.Text, out temp)) { var data = new Shipper() { ShipperID = temp }; var mgr = new NorthwindManager(); mgr.DeleteShipper(data); //feedback to user PopulateShippersComboBox(); //clear the form textboxes tboShipperID.Text = ""; tboCompanyName.Text = ""; tboPhone.Text = ""; } else { MessageBox.Show("Please lookup a shipper before trying to delete."); } } catch (Exception ex) { //TODO: Log the exception Program.LogMessage(ex.Message); MessageBox.Show(ex.Message); } }
private void btnDelete_Click(object sender, EventArgs e) { try { int shipperId; if (int.TryParse(lblShipperID.Text, out shipperId)) { //do the delete... var info = new Shipper() { ShipperID = shipperId }; NorthwindManager mgr = new NorthwindManager(); mgr.DeleteShipper(info); PopulateShippersComboBox(); cboShippers.SelectedItem = 0; } else { MessageBox.Show("Please select a shipper before clicking [Lookup Shipper]"); } } catch (Exception ex) { //TODO: Log the exception MessageBox.Show("Error: " + ex.Message); } }
private void btnAddShipper_Click(object sender, EventArgs e) { try { Shipper item = new Shipper() { CompanyName = tboCompanyName.Text, Phone = tboPhone.Text }; var mgr = new NorthwindManager(); item.ShipperID = mgr.AddShipper(item); //Give some feedback to the user... // - Update my combo-box PopulateShippersComboBox(); // - My combo-box has the right shipper selected cboShippers.SelectedValue = item.ShipperID; // - Display the id fo the addd shipper tboShipperID.Text = item.ShipperID.ToString(); } catch (Exception ex) { //TODO: Log the exception MessageBox.Show(ex.Message); } }
public int AddShipper(Shipper info) { using (var context = new NWContext()) { context.Shippers.Add(info); context.SaveChanges(); return info.ShipperID; } }
public void DeleteShipper(Shipper info) { using (var context = new NWContext()) { var found = context.Shippers.Find(info.ShipperID); if (found != null) { context.Shippers.Remove(found); context.SaveChanges(); } } }
public void DeleteShipper(Shipper shipper) { using (var context = new NWContext()) { //BEST practice. find shipper first, then delete var found = context.Shippers.Find(shipper.ShipperID); if (found != null) { context.Shippers.Remove(found); context.SaveChanges(); } } }
public void Should_Add_Shipper() { //Arrange var sut = new NorthwindManager(); // sut is short for "Situation Under Test" var expected = new Shipper() { CompanyName = "Tin Hoang's Transporter Service", Phone = "780.231.3123" }; //Act var actualId = sut.AddShipper(expected); //Assert Assert.True(actualId > 0); Shipper actual = sut.GetShipper(actualId); Assert.Equal(expected.CompanyName, actual.CompanyName); Assert.Equal(expected.Phone,actual.Phone); Assert.Equal(actualId,actual.ShipperID); }
public void Should_Add_Shipper() { //Arrange var sut = new NorthwindManager(); //sut is short for 'Scenario Under Test' var expected = new Shipper() { CompanyName = "Montgomery Scott's Transporter Service", Phone = "780.555.1212" }; //Act var actualId = sut.AddShipper(expected); //Assert Assert.True(actualId > 0); Shipper actual = sut.GetShipper(actualId); Assert.Equal(expected.CompanyName, actual.CompanyName); Assert.Equal(expected.Phone, actual.Phone); Assert.Equal(actualId, actual.ShipperID); }
public void UpdateShipper(Shipper info) { //NOTE: See question and commentary on // http://stackoverflow.com/questions/15336248/entity-framework-5-updating-a-record using (var context = new NWContext()) { context.Shippers.Attach(info); context.Entry(info).State = EntityState.Modified; context.SaveChanges(); } }
public void Should_Delete_Shipper() { //Arrange var sut = new NorthwindManager(); // sut is short for "Situation Under Test" var expected = new Shipper() { CompanyName = "Tin Hoang's Transporter Service", Phone = "780.231.3123" }; expected.ShipperID = sut.AddShipper(expected); //Act sut.DeleteShipper(expected); //Assert Shipper actual = sut.GetShipper(expected.ShipperID); Assert.Null(actual); }
public void Should_Update_Shippers(Shipper existing) { //Arrange existing.Phone = "780.999.9998"; var sut = new NorthwindManager(); //Act sut.UpdateShipper(existing); //Assert var actual = sut.GetShipper(existing.ShipperID); Assert.NotNull(actual); Assert.Equal(existing.Phone, actual.Phone); Assert.Equal(existing.CompanyName, actual.CompanyName); }
private void btnUpdateShipper_Click(object sender, EventArgs e) { try { int shipperId; if (int.TryParse(tboShipperID.Text, out shipperId)) { //Do the update var info = new Shipper() { ShipperID = shipperId, CompanyName = tboCompanyName.Text, Phone = tboPhone.Text }; var mgr = new NorthwindManager(); mgr.UpdateShipper(info); PopulateShippersComboBox(); cboShippers.SelectedValue = info.ShipperID; } else { MessageBox.Show("Please lookup a shipper before trying to update."); } } catch (Exception ex) { //TODO: Log the exception MessageBox.Show(ex.Message); } }
public void Should_Delete_Shipper() { //Arrange var sut = new NorthwindManager(); //sut is short for 'Scenario Under Test' var expected = new Shipper() { CompanyName = "Montgomery Scott's Transporter Service", Phone = "780.555.1212" }; expected.ShipperID = sut.AddShipper(expected); //Act sut.DeleteShipper(expected); //Assert Shipper actual = sut.GetShipper(expected.ShipperID); Assert.Null(actual); }
public void Should_Update_Shipper(Shipper existing) { //Arrange existing.Phone = "780.999.999"; var sut = new NorthwindManager(); //sut is short for 'Scenario Under Test' existing.Phone = "780.555.1212"; //Act sut.UpdateShipper(existing); //Assert var actual = sut.GetShipper(existing.ShipperID); Assert.NotNull(actual); Assert.Equal(existing.CompanyName, actual.CompanyName); Assert.Equal(existing.Phone, actual.Phone); }