public IList <OrderRelativeInfoDto> CalculateOrderDiscount(int orderId) { IList <OrderRelativeInfoDto> orderRelativeInfoDtos = new List <OrderRelativeInfoDto>(); LoadOrderDetailById(orderId); DataRow[] orderDetailRows = this[orderId]; foreach (DataRow orderDetailRow in orderDetailRows) { int productId = (int)orderDetailRow["ProductID"]; ProductTM productTM = new ProductTM(this.Holder); productTM.LoadProductById(productId); DataRow[] productRows = productTM[productId]; int categoryId = (int)productRows[0]["CategoryID"]; CategoryTM categoryTM = new CategoryTM(this.Holder); categoryTM.LoadCategoryById(categoryId); DataRow[] categoryRows = categoryTM[categoryId]; OrderRelativeInfoDto orderRelativeInfoDto = new OrderRelativeInfoDto(); orderRelativeInfoDto.OrderID = orderId; orderRelativeInfoDto.ProductName = (string)productRows[0]["ProductName"]; orderRelativeInfoDto.Quantity = (short)orderDetailRow["Quantity"]; orderRelativeInfoDto.CategoryID = (int)categoryRows[0]["CategoryID"]; orderRelativeInfoDto.CategoryName = (string)categoryRows[0]["CategoryName"]; DoDiscountCalculation(orderRelativeInfoDto); orderRelativeInfoDtos.Add(orderRelativeInfoDto); } return(orderRelativeInfoDtos); }
public IList <OrderRelativeInfoDto> CalculateOrderDiscount1(int orderId) { IList <OrderRelativeInfoDto> orderRelativeInfoDtos = new List <OrderRelativeInfoDto>(); IList <OrderDetailDto> orderDetailDtos = NorthwindTDG.FindOrderDetailById(orderId).ToList(); foreach (OrderDetailDto orderDetailDto in orderDetailDtos) { ProductDto productDto = NorthwindTDG.FindProductById(orderDetailDto.ProductID).SingleOrDefault(); CategoryDto categoryDto = NorthwindTDG.FindCategoryById(productDto.CategoryID).SingleOrDefault(); OrderRelativeInfoDto orderRelativeInfoDto = new OrderRelativeInfoDto(); orderRelativeInfoDto.OrderID = orderId; orderRelativeInfoDto.ProductName = productDto.ProductName; orderRelativeInfoDto.Quantity = orderDetailDto.Quantity; orderRelativeInfoDto.CategoryID = productDto.CategoryID; orderRelativeInfoDto.CategoryName = categoryDto.CategoryName; DoDiscountCalculation(orderRelativeInfoDto); orderRelativeInfoDtos.Add(orderRelativeInfoDto); } return(orderRelativeInfoDtos); }
private static OrderRelativeInfoDto CreateOrderRelativeInfoDto(IDataRecord dataRecord) { OrderRelativeInfoDto orderRelativeInfoDto = new OrderRelativeInfoDto(); orderRelativeInfoDto.OrderID = dataRecord.GetInt32("OrderID"); orderRelativeInfoDto.ProductName = dataRecord.GetStringOrNull("ProductName"); orderRelativeInfoDto.Quantity = dataRecord.GetInt16("Quantity"); orderRelativeInfoDto.CategoryID = dataRecord.GetInt32OrNull("CategoryID"); orderRelativeInfoDto.CategoryName = dataRecord.GetStringOrNull("CategoryName"); return(orderRelativeInfoDto); }
private OrderRelativeInfoDto CreateOrderRelativeInfoDto(IDataRecord dataRecord) { OrderRelativeInfoDto orderRelativeInfoDto = new OrderRelativeInfoDto(); orderRelativeInfoDto.OrderID = dataRecord.GetInt32("OrderID"); orderRelativeInfoDto.ProductName = dataRecord.GetString("ProductName"); orderRelativeInfoDto.CategoryID = dataRecord.GetInt32("CategoryID"); orderRelativeInfoDto.CategoryName = dataRecord.GetString("CategoryName"); orderRelativeInfoDto.Quantity = dataRecord.GetInt16("Quantity"); orderRelativeInfoDto.Discount = dataRecord.GetFloat("Discount"); return(orderRelativeInfoDto); }
private static void DoDiscountCalculation(OrderRelativeInfoDto orderRelativeInfo) { if (!orderRelativeInfo.CategoryID.HasValue) { return; } orderRelativeInfo.Discount = 0.00f; if (orderRelativeInfo.CategoryID.Value == DairyProductsCategory) { if (orderRelativeInfo.Quantity < 10) { orderRelativeInfo.Discount = 0.00f; } else if (orderRelativeInfo.Quantity < 20) { orderRelativeInfo.Discount = 0.05f; } else if (orderRelativeInfo.Quantity < 30) { orderRelativeInfo.Discount = 0.10f; } else if (orderRelativeInfo.Quantity < 40) { orderRelativeInfo.Discount = 0.15f; } else if (orderRelativeInfo.Quantity < 50) { orderRelativeInfo.Discount = 0.20f; } else if (orderRelativeInfo.Quantity >= 50) { orderRelativeInfo.Discount = 0.25f; } } if (orderRelativeInfo.CategoryID.Value == MeatCategory) { if (orderRelativeInfo.Quantity <= 20) { orderRelativeInfo.Discount = 0.00f; } else if (orderRelativeInfo.Quantity <= 40) { orderRelativeInfo.Discount = 0.10f; } else if (orderRelativeInfo.Quantity <= 60) { orderRelativeInfo.Discount = 0.20f; } else if (orderRelativeInfo.Quantity > 60) { orderRelativeInfo.Discount = 0.30f; } } if (orderRelativeInfo.CategoryID.Value == SeafoodCategory) { if (orderRelativeInfo.Quantity >= 10) { orderRelativeInfo.Discount = 0.15f; } } }