public CustomerDiscount CreateCustomerDiscount(CostCentreRef outletId, ProductRef productId, decimal discountRate,DateTime effectiveDate) { if (effectiveDate > DateTime.Now) throw new ArgumentException("Invalid effective date, must be in the past"); if (productId.ProductId == Guid.Empty) throw new ArgumentException("Invalid product"); if (outletId.Id == Guid.Empty) throw new ArgumentException("Invalid outlet"); CustomerDiscount cDiscount = new CustomerDiscount(Guid.NewGuid()) { Outlet = new CostCentreRef {Id=outletId.Id }, Product= new ProductRef {ProductId=productId.ProductId}, }; cDiscount.CustomerDiscountItems.Add(new CustomerDiscount.CustomerDiscountItem(Guid.NewGuid()) { EffectiveDate=effectiveDate, DiscountRate=discountRate }); return cDiscount; }
CustomerDiscountViewModel Map(CustomerDiscount custDiscount) { return new CustomerDiscountViewModel { discountRate=custDiscount.CurrentDiscount, id=custDiscount.Id, isActive = custDiscount._Status == EntityStatus.Active ? true : false, Outlet=custDiscount.Outlet.Id, effectiveDate=custDiscount.CurrentEffectiveDate, Product=custDiscount.Product.ProductId, ProductName = _productRepository.GetById(custDiscount.Product.ProductId).Description, OutletName = _costCentreRepository.GetById(custDiscount.Outlet.Id).Name }; }
private void AssertCustomerDiscount(CustomerDiscount customerDiscountX, CustomerDiscount customerDiscountY) { var cdX = customerDiscountX.CustomerDiscountItems.FirstOrDefault(); var cdY = customerDiscountY.CustomerDiscountItems.FirstOrDefault(); Assert.IsNotNull(customerDiscountX); Assert.AreEqual(customerDiscountX.Outlet.Id, customerDiscountY.Outlet.Id); Assert.AreEqual(customerDiscountX._Status, customerDiscountY._Status); }