Ejemplo n.º 1
0
        public void DeletePriceLevelTest()
        {
            // Get a test user
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            // Create a price level
            PriceLevelModel model = createPriceLevel(testCompany);

            var error = LookupService.InsertOrUpdatePriceLevel(model, testUser, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindPriceLevel(model.Id);
            var test   = LookupService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            LookupService.DeletePriceLevel(model.Id);

            // And check that is was deleted
            result = db.FindPriceLevel(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
Ejemplo n.º 2
0
        public Error InsertOrUpdatePriceLevel(PriceLevelModel priceLevel, UserModel user, string lockGuid)
        {
            var error = validateModel(priceLevel);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(PriceLevel).ToString(), priceLevel.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "Mneumonic");
                }
                else
                {
                    PriceLevel temp = null;
                    if (priceLevel.Id != 0)
                    {
                        temp = db.FindPriceLevel(priceLevel.Id);
                    }
                    if (temp == null)
                    {
                        temp = new PriceLevel();
                    }

                    Mapper.Map <PriceLevelModel, PriceLevel>(priceLevel, temp);

                    db.InsertOrUpdatePriceLevel(temp);
                    priceLevel.Id = temp.Id;
                }
            }
            return(error);
        }
Ejemplo n.º 3
0
        private Error validateModel(PriceLevelModel model)
        {
            var error = isValidRequiredString(getFieldValue(model.Mneumonic), 3, "Mneumonic", EvolutionResources.errMneumonicRequired);

            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.Description), 30, "Description", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ImportPriceLevel), 1, "ImportPriceLevel", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ImportSalesTaxCalcMethod), 1, "ImportSaleTaxCalcMethod", EvolutionResources.errTextDataRequiredInField);
            }

            if (!error.IsError)
            {
                // Check if a record with the same name already exists
                var priceLevel = db.FindPriceLevel(model.CompanyId, model.Mneumonic);
                if (priceLevel != null &&                 // Record was found
                    ((priceLevel.Id == 0 ||               // when creating new or
                      priceLevel.Id != model.Id)))        // when updating existing
                {
                    error.SetError(EvolutionResources.errItemAlreadyExists, "Mneumonic");
                }
            }

            return(error);
        }
Ejemplo n.º 4
0
        PriceLevelModel createPriceLevel(CompanyModel company)
        {
            PriceLevelModel model = new PriceLevelModel {
                CompanyId                = company.Id,
                Mneumonic                = RandomString().Left(3),
                Description              = RandomString().Left(30),
                ImportPriceLevel         = RandomString().Left(1),
                ImportSalesTaxCalcMethod = RandomString().Left(1),
                Enabled = true
            };

            return(model);
        }
Ejemplo n.º 5
0
        public PriceLevelModel FindPriceLevelModel(int id, bool bCreateEmptyIfNotfound = true)
        {
            PriceLevelModel model = null;

            var pl = db.FindPriceLevel(id);

            if (pl == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new PriceLevelModel();
                }
            }
            else
            {
                model = MapToModel(pl);
            }

            return(model);
        }
Ejemplo n.º 6
0
        public PriceLevelModel Clone(PriceLevelModel item)
        {
            var newItem = Mapper.Map <PriceLevelModel, PriceLevelModel>(item);

            return(newItem);
        }
Ejemplo n.º 7
0
 public string LockPriceLevel(PriceLevelModel model)
 {
     return(db.LockRecord(typeof(PriceLevel).ToString(), model.Id));
 }