public ActionResult DropContent(int index, int id) { // Called when a user clicks to drop a purchase order from the shipment content list var model = new ShipmentListModel(); model.GridIndex = index; try { ShipmentService.DeleteShipmentContent(id, false); } catch (Exception e1) { this.WriteLog(e1); model.Error.SetError(e1); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(int index, int?sci, int?si) { var model = new ShipmentListModel(); model.GridIndex = index; try { if (sci != null) { // Got a shipping content id to delete ShipmentService.DeleteShipmentContent(sci.Value, true); } else if (si != null) { // No shipping content id, but got a shipping id to delete ShipmentService.DeleteShipment(si.Value); } } catch (Exception e1) { this.WriteLog(e1); model.Error.SetError(e1); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public void FindShipmentContentListModelTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); var testShipment = GetTestShipment(testCompany, testUser, 10); var model = ShipmentService.FindShipmentContentListModel(testCompany, testShipment.Id, 0); var dbData = db.FindShipmentContents(testCompany.Id, testShipment.Id); int expected = dbData.Count(), actual = model.Items.Count(); Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected"); // Check that all the items match foreach (var item in model.Items) { var dbItem = dbData.Where(m => m.Id == item.Id).FirstOrDefault(); Assert.IsTrue(dbItem != null, "Error: Model item not found in db item list"); var temp = ShipmentService.MapToModel(dbItem); AreEqual(item, temp); } // Add another item a make sure it is found var newPoh = GetTestPurchaseOrderHeader(testCompany, testUser, RandomInt(10, 20)); var newItem = ShipmentService.AddPurchaseOrder(testCompany, testUser, testShipment, newPoh); model = ShipmentService.FindShipmentContentListModel(testCompany, testShipment.Id, 0); var testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault(); Assert.IsTrue(testItem != null, "Error: A NULL value was returned when a non-NULL value was expected"); // Delete it and make sure it disappears ShipmentService.DeleteShipmentContent(newItem.Id, true); model = ShipmentService.FindShipmentContentListModel(testCompany, testShipment.Id, 0); testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault(); Assert.IsTrue(testItem == null, "Error: A non-NULL value was returned when a NULL value was expected"); }