public Task <IOrderCost> CalculateTotalCost() { IOrderCost totalcost = new OrderCost(); try { var booklist = GetBookOrderList().Result; if (booklist != null) { foreach (var item in booklist) { IBookSale booksale = GetBookOnSale(item).Result; if (Math.Abs(booksale.DiscountedPrice()) > 0) { totalcost.Subtotal += booksale.DiscountedPrice(); } else { totalcost.Subtotal += booksale.BookDetail.Cost; } } totalcost.Subtotal = Math.Round(totalcost.Subtotal, 2); totalcost.Totaltax = Math.Round(totalcost.Subtotal * (Constant.ORDER_TAX_TOTAL), 2); totalcost.TotalCost = Math.Round((totalcost.Subtotal + totalcost.Totaltax), 2); } } catch (Exception e) { Console.WriteLine(e); } return(Task.FromResult <IOrderCost>(totalcost)); }
public string DisplayOrder() { StringBuilder displaydata = new StringBuilder(); try { var booklist = _dbBookManager.GetBookOrderList().Result; if (booklist != null) { foreach (var item in booklist) { IBookSale booksale = _dbBookManager.GetBookOnSale(item).Result; string ordername = booksale.BookDetail.Name.PadRight(30) + booksale.CategoryDetail.Name.PadRight(20); if (Math.Abs(booksale.DiscountedPrice()) > 0) { string discountorder = booksale.PromoDetail.Description.PadRight(25) + booksale.BookDetail.Cost; displaydata.AppendLine(ordername + booksale.DiscountedPrice()); displaydata.AppendLine(discountorder); } else { displaydata.AppendLine(ordername + booksale.BookDetail.Cost); } } IOrderCost totalorder = _dbBookManager.CalculateTotalCost().Result; displaydata.AppendLine(); displaydata.AppendLine("============================"); displaydata.AppendLine("Sub Total :" + totalorder.Subtotal); displaydata.AppendLine("Total Tax :" + totalorder.Totaltax); displaydata.AppendLine("Total :" + totalorder.TotalCost); displaydata.AppendLine("============================"); displaydata.AppendLine(); } } catch (Exception e) { Console.WriteLine(e); } return(displaydata.ToString()); }