Ejemplo n.º 1
0
        CustomerDefaultModel createCustomerDefault(CompanyModel company)
        {
            if (countryList == null)
            {
                countryList = LookupService.FindCountriesListModel();
            }
            var rnd = RandomInt(0, countryList.Items.Count() - 1);

            var currency = LookupService.FindCurrencyModel(company.DefaultCurrencyID.Value, false);

            var model = new CustomerDefaultModel {
                CompanyId        = company.Id,
                CountryId        = countryList.Items[rnd].Id,
                CountryNameText  = countryList.Items[rnd].CountryName,
                CurrencyId       = currency.Id,
                CurrencyCodeText = currency.CurrencyCode
            };
            var error = CustomerService.InsertOrUpdateCustomerDefault(model);

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

            countryList.Items.RemoveAt(rnd);    // So we don't use the same country again

            return(model);
        }
Ejemplo n.º 2
0
        public Error InsertOrUpdateCustomerDefault(CustomerDefaultModel defaults, string lockGuid = "")
        {
            var error = validateCustomerDefaultModel(defaults);

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

                    mapToEntity(defaults, temp);
                    if (temp.CountryId == 0)
                    {
                        temp.CountryId = null;
                    }
                    if (temp.PriceLevelId == 0)
                    {
                        temp.PriceLevelId = null;
                    }
                    if (temp.SalespersonId == 0)
                    {
                        temp.SalespersonId = null;
                    }
                    if (temp.CustomerTypeId == 0)
                    {
                        temp.CustomerTypeId = null;
                    }
                    if (temp.TaxCodeId == 0)
                    {
                        temp.TaxCodeId = null;
                    }
                    if (temp.TaxCodeWithoutTaxId == 0)
                    {
                        temp.TaxCodeWithoutTaxId = null;
                    }

                    db.InsertOrUpdateCustomerDefault(temp);
                    defaults.Id = temp.Id;
                }
            }
            return(error);
        }
Ejemplo n.º 3
0
        public CustomerDefaultModel FindCustomerDefaultModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true)
        {
            CustomerDefaultModel model = null;

            var c = db.FindCustomerDefault(id);

            if (c == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new CustomerDefaultModel {
                        CompanyId = company.Id
                    }
                }
                ;
            }
            else
            {
                model = mapToModel(c);
            }

            return(model);
        }
Ejemplo n.º 4
0
 private void mapToEntity(CustomerDefaultModel model, CustomerDefault entity)
 {
     Mapper.Map <CustomerDefaultModel, CustomerDefault>(model, entity);
 }
Ejemplo n.º 5
0
        private Error validateCustomerDefaultModel(CustomerDefaultModel model)
        {
            var error = isValidNonRequiredString(getFieldValue(model.Postcode), 20, "Postcode", EvolutionResources.errTextDataRequiredInField);

            return(error);
        }
Ejemplo n.º 6
0
 public string LockCustomerDefault(CustomerDefaultModel model)
 {
     return(db.LockRecord(typeof(CustomerDefault).ToString(), model.Id));
 }