public ActionResult AddEditItem(int parentId, int id)
        {
            var model = new EditPurchaseOrderDetailTempViewModel();

            model.PurchaseOrderDetailTemp = PurchasingService.FindPurchaseOrderDetailTempModel(id, CurrentCompany, true);
            model.PurchaseOrderDetailTemp.PurchaseOrderHeaderTempId = parentId;
            prepareEditModel(model, parentId);

            model.LGS = PurchasingService.LockPurchaseOrderDetailTemp(model.PurchaseOrderDetailTemp);

            return(View("AddEditItem", model));
        }
Пример #2
0
        public void LockPurchaseOrderDetailTempTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testPurchase = GetTestPurchaseOrderHeader(testCompany, testUser, 1);

            var pohtModel = PurchasingService.CopyPurchaseOrderToTemp(testCompany, testPurchase, testUser);
            var model     = PurchasingService.FindPurchaseOrderDetailTempsListModel(testCompany.Id, pohtModel.Id, 0, 1, PageSize, "");

            // Create a record
            var newItem = createPurchaseOrderDetailTemp(model);

            var error = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, testUser, "");

            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            // Get the current Lock
            string lockGuid = PurchasingService.LockPurchaseOrderDetailTemp(newItem);

            Assert.IsTrue(!string.IsNullOrEmpty(lockGuid), "Error: Lock record was not found");

            // Simulate another user updating the record
            var otherUser = GetTestUser();

            error = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, otherUser, lockGuid);
            Assert.IsTrue(!error.IsError, error.Message);

            // Now get the first user to update the record
            error = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, 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.LockPurchaseOrderDetailTemp(newItem);
            error    = PurchasingService.InsertOrUpdatePurchaseOrderDetailTemp(newItem, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }