public void SetUp() { using (StructureMap.IContainer cont = NestedContainer) { ProductLookupList.Clear(); var def = new ProductLookup {Name = "--Select Returnable Product--", ProductId = Guid.Empty}; ProductLookupList.Add(def); Using<IProductRepository>(cont).GetAll().OfType<ReturnableProduct>() .OrderBy(o => o.Description).ToList() .ForEach(n => ProductLookupList.Add(new ProductLookup {Name = n.Description, ProductId = n.Id})); ProductLookups = def; Quantity = 0; IsEditable = true; } }
public void AddLineItems(ProductLookup product, int quantity, bool isNew) { using (StructureMap.IContainer c = NestedContainer) { ProductPricingTier tier = null; var outlet = Using<ICostCentreRepository>(c).GetAll().FirstOrDefault(s => s.Id == OutletLookups.OutletId) as Outlet; if (outlet != null) tier = Using<IProductPricingTierRepository>(c).GetById(outlet.OutletProductPricingTier.Id); try { Returnable returnablez; if (ReturnableItems.Any(a => a.ProductId == product.ProductId)) { returnablez = ReturnableItems.First(a => a.ProductId == product.ProductId); if (isNew) { returnablez.Quantity += quantity; returnablez.Value = (returnablez.Quantity*returnablez.UnitPrice); } else { returnablez.Quantity = quantity; returnablez.Value = (returnablez.Quantity*returnablez.UnitPrice); } } else { Product prod = Using<IProductRepository>(c).GetById(product.ProductId); decimal unitPrice = 0; try { if (tier != null) unitPrice = prod.ProductPrice(tier); } catch { unitPrice = 0; } ReturnableItems.Add(new Returnable { UnitPrice = unitPrice, Name = product.Name, ProductId = product.ProductId, Quantity = quantity, Value = (unitPrice*quantity) }); } if (IsOutletEnabled == true) IsOutletEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }