Example #1
0
        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 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 Save(EditPurchaseOrderHeaderTempViewModel model, string command)
        {
            switch (command.ToLower())
            {
            case "save":
                // Save the screen data back to the temp tables, then copy to live tables and exit
                if (ModelState.IsValid)
                {
                    adjustDates(model.PurchaseTemp, model.TZ);

                    var modelError = PurchasingService.InsertOrUpdatePurchaseOrderHeaderTemp(model.PurchaseTemp, CurrentUser, model.LGST);
                    if (modelError.IsError)
                    {
                        model.Error.SetError(modelError.Message,
                                             "Purchase_" + modelError.FieldName);
                    }
                    else
                    {
                        // Copy the temp tables back to the main tables
                        modelError = PurchasingService.CopyTempToPurchaseOrderHeader(model.PurchaseTemp.Id, CurrentUser, model.LGS);
                        if (modelError.IsError)
                        {
                            prepareEditModel(model, model.PurchaseTemp.Id);
                            model.Error.SetError(modelError.Message,
                                                 "Purchase_" + modelError.FieldName);
                        }
                        else
                        {
                            return(RedirectToAction("Purchases"));
                        }
                    }
                }
                prepareEditModel(model, model.PurchaseTemp.Id);
                return(View("Edit", model));

            default:
                return(RedirectToAction("Index", "Purchasing", new { area = "Purchasing" }));
            }
        }