public void LockPurchaseOrderHeaderTempTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); var testPurchase = GetTestPurchaseOrderHeader(testCompany, testUser, 10); var model = PurchasingService.CopyPurchaseOrderToTemp(testCompany, testPurchase, testUser); Assert.IsTrue(model != null, "Error: A NULL value was returned when an object was expected"); // Get the current Lock string lockGuid = PurchasingService.LockPurchaseOrderHeaderTemp(model); Assert.IsTrue(!string.IsNullOrEmpty(lockGuid), "Error: Lock record was not found"); // Simulate another user updating the record var otherUser = GetTestUser(); var error = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(model, otherUser, lockGuid); Assert.IsTrue(!error.IsError, error.Message); // Now get the first user to update the record error = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(model, testUser, lockGuid); Assert.IsTrue(error.IsError, "Error: The lock should have caused an error as it has changed"); // Try to update with the new lock lockGuid = PurchasingService.LockPurchaseOrderHeaderTemp(model); error = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(model, testUser, lockGuid); Assert.IsTrue(!error.IsError, $"Error: {error.Message}"); }
public ActionResult Edit(int id) { // Called when a user clicks to edit an order var model = new EditPurchaseOrderHeaderTempViewModel(); var purchase = PurchasingService.FindPurchaseOrderHeaderModel(id, CurrentCompany, true); // Copy the order into temp tables for editing model.PurchaseTemp = PurchasingService.CopyPurchaseOrderToTemp(CurrentCompany, purchase, CurrentUser); prepareEditModel(model, model.PurchaseTemp.Id); model.LGS = PurchasingService.LockPurchaseOrderHeader(purchase); model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp); return(View("Edit", model)); }
public ActionResult SaveKeyProperties(int pohtId, int locationId, int supplierId, int brandcatgeoryId, string lgst) { var error = new Error(); var poht = PurchasingService.FindPurchaseOrderHeaderTempModel(pohtId, CurrentCompany, false); if (poht != null) { poht.LocationId = locationId; poht.SupplierId = supplierId; poht.BrandCategoryId = brandcatgeoryId; error = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(poht, CurrentUser, lgst); if (!error.IsError) { error.Data = PurchasingService.LockPurchaseOrderHeaderTemp(poht); } } return(Json(error, JsonRequestBehavior.AllowGet)); }
public ActionResult EditDetails(int id) { // Called when a user is on one of the order screens and clicks the order details option var model = new EditPurchaseOrderHeaderTempViewModel(); // Use the data in the temp tables var purchaseTemp = PurchasingService.FindPurchaseOrderHeaderTempModel(id, CurrentCompany, true); purchaseTemp.UserId = CurrentUser.Id; model.PurchaseTemp = purchaseTemp; prepareEditModel(model, id); var purchase = PurchasingService.FindPurchaseOrderHeaderModel(purchaseTemp.OriginalRowId, CurrentCompany, true); model.LGS = PurchasingService.LockPurchaseOrderHeader(purchase); model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp); return(View("Edit", model)); }