public static OrdersBO PriceTotalCalculator(List <ItemsBO> calcItems) { int? totalPrice = 0; OrdersBO Order = new OrdersBO(); foreach (ItemsBO item in calcItems) { totalPrice += item.Price; } Order.Pricetotal = totalPrice; return(Order); }
//Mapping to BLL from presentation layer public static OrdersBO OrdersPOtoOrdersBO(OrdersPO from) { //mapping each individual attribute OrdersBO to = new OrdersBO(); to.OrderID = from.OrderID; to.UserID = from.UserID; to.Requested = from.Requested; to.Due = from.Due; to.CrafterID = from.CrafterID; to.Status = from.Status; to.Username = from.Username; to.Crafter = from.Crafter; to.Pricetotal = from.Pricetotal; //making it usable in future return(to); }
public ActionResult ViewOrderByID(int OrderID) { ActionResult response; OrdersVM orderDetails = new OrdersVM(); try { //mapping all the data to the view page OrdersPO order = Mapper.OrdersDOtoOrdersPO(_OrdersDAO.ViewOrderByID(OrderID)); List <ItemsPO> orderItems = Mapper.ItemsListDOtoPO(_ItemsDAO.ItemsByOrderID(OrderID)); //sending to business logic layer OrdersBO calcOrder = Mapper.OrdersPOtoOrdersBO(order); List <ItemsBO> calcItems = Mapper.ItemsListPOtoBO(orderItems); //doing valculations calcOrder = Calculation.PriceTotalCalculator(calcItems); order.Pricetotal = calcOrder.Pricetotal; //assigning new total price OrdersDO newTotal = Mapper.OrdersPOtoOrdersDO(order); _OrdersDAO.UpdateOrderPricetotal(newTotal); //assigning objects to viewmodel orderDetails.Order = order; orderDetails.Items = orderItems; response = View(orderDetails); } //logging errors and redirecting catch (SqlException sqlEx) { Logger.SqlErrorLog(sqlEx); response = View("Error"); } catch (Exception ex) { Logger.ErrorLog(ex); response = View("Error"); } //return view return(response); }