public static void CalculateFinalPrice(ProductModel product, StateOfAmericaModel state, int numberOfProducts) { var tax = GetTax(product, state, numberOfProducts); product.FinalPrice = (Math.Round(product.PreferredPrice - (product.PreferredPrice * (tax / 100)), 2)) * numberOfProducts; }
public void Setup() { _stateRepository = Substitute.For <IStateDatabaseAccess>(); _productRepository = Substitute.For <IProductDatabaseAccess>(); _categoryRepository = Substitute.For <ICategoryDatabaseAccess>(); _expectedCategory = new CategoryModel { Id = CategoryId, Name = CategoryName }; _expectedProduct = Product().OfCategory(_expectedCategory).WithCategoryId(CategoryId) .OfName(ProductName).WithId(ProductId).WithPurchasePrice(PurchasePrice).Build(); _expectedTax = Tax().OfTaxRate(TaxRate).OfMinValue(MinMoney).OfMaxValue(MaxMoney) .OfCategoryId(CategoryId).OfStateId(StateId).OfId(TaxId).Build(); _expectedState = State().OfName(StateName).OfId(StateId) .OfBaseSalesTax(TaxRate).AppendTax(_expectedTax).Build(); _preparedStates = new List <StateOfAmericaModel> { _expectedState }; _preparedCategories = new List <CategoryModel> { _expectedCategory }; _preparedProducts = new List <ProductModel> { _expectedProduct }; }
public int InsertState(StateOfAmericaModel state) { _provider.ConnectToDb(); if (!_provider.Connected) { throw new AccessToNotConnectedDatabaseException(); } var db = _provider.DatabaseContext; using (var transaction = db.GetTransaction()) { if (db.FirstOrDefault <StateOfAmericaModel>("WHERE Name = @0", state.Name) != null) { throw new ItemAlreadyExistsException(); } db.Insert(state); transaction.Complete(); } _provider.DisconnectFromDb(); return(state.Id); }
public void Setup() { _state = State().AddTax().OfCategoryId((int)ProductCategoryEnum.Clothing).ConfirmTax().Build(); _product = Product().WithCategoryId((int)ProductCategoryEnum.Clothing).Build(); _invalidProduct = Product().WithCategoryId(InvalidId).Build(); }
public int InsertState(string name, double?baseSalesTax = null) { var state = new StateOfAmericaModel { BaseSalesTax = baseSalesTax ?? 0, Name = name }; return(InsertState(state)); }
public void UpdateState(int stateId, string name = "", double?baseSalesTax = null) { var state = new StateOfAmericaModel { BaseSalesTax = baseSalesTax ?? 0, Name = name }; UpdateState(state); }
public StateOfAmericaModel MapStateAndTax(StateOfAmericaModel nextState, TaxModel tax) { if (nextState == null) { return(_currentState); } if (_currentState != null && _currentState.Id == nextState.Id) { _currentState.TaxRates.Add(tax); return(null); } var previousState = _currentState; _currentState = nextState; _currentState.TaxRates = new List <TaxModel> { tax }; return(previousState); }
public void UpdateState(StateOfAmericaModel state) { _provider.ConnectToDb(); if (!_provider.Connected) { throw new AccessToNotConnectedDatabaseException(); } var db = _provider.DatabaseContext; using (var transaction = db.GetTransaction()) { if (db.FirstOrDefault <StateOfAmericaModel>("WHERE Id = @0", state.Id) == null) { throw new ItemNotFoundException(); } db.Update(state); transaction.Complete(); } _provider.DisconnectFromDb(); }
public static double GetTax(ProductModel product, StateOfAmericaModel state, int count) { return(state.TaxRates.Where(tax => tax.CategoryId == product.CategoryId) .FirstOrDefault(model => model.IsMoneyInRange(product.PreferredPrice * count))?.TaxRate ?? throw new ArgumentOutOfRangeException()); }
public ICollection <TaxModel> GetTaxesByState(StateOfAmericaModel state) => GetTaxesByCategory(state.Id);