P1_TrevorGraham/MvcStoreApplication/BusinessLogic/BusinessLogic.cs
/// <summary>
/// returns a viewmodel based on the currently open cart if a user is logged in
/// </summary>
/// <returns></returns>
returns a viewmodel based on the currently open cart if a user is logged in
returns a viewmodel based on the currently open cart if a user is logged in
public OrderViewModel GetCart()
        {
            if (!CurrentUserIsCustomer()) { return null; }
            var loc = (Guid)SessionGetCurrentLocation();
            var cust = (Guid)SessionGetCurrentUser();
            var cart = _repository.GetOpenCartForCustomer(cust);
            var cartLines = _repository.GetOrderLinesForOrder(cart.OrderId);
            var cartLineViewModels = new List<OrderLineViewModel>();
            double total = 0;
            foreach (OrderLine line in cartLines)
            {
                var viewLine = _mapper.ConvertOrderLineToOrderLineViewModel(line);
                total += viewLine.TotalPrice;
                cartLineViewModels.Add(viewLine);
            }
            OrderViewModel viewModel = new OrderViewModel()
            {
                Date = DateTime.Now,
                CustomerId = cust,
                CustomerName = _repository.GetCustomerById(cust).Fname,
                OrderId = cart.OrderId,
                StoreName = _repository.GetLocationById(loc).Name,
                TotalPrice = total,
                orderLines = cartLineViewModels
            };
            return viewModel;
        }
public OrderViewModel GetCart ( ) { if ( ! CurrentUserIsCustomer ( ) ) { return null ; } var loc = ( Guid ) SessionGetCurrentLocation ( ) ; var cust = ( Guid ) SessionGetCurrentUser ( ) ; var cart = _repository . GetOpenCartForCustomer ( cust ) ; var cartLines = _repository . GetOrderLinesForOrder ( cart . OrderId ) ; var cartLineViewModels = new List < OrderLineViewModel > ( ) ; double total = 0 ; foreach ( OrderLine line in cartLines ) { var viewLine = _mapper . ConvertOrderLineToOrderLineViewModel ( line ) ; total += viewLine . TotalPrice ; cartLineViewModels . Add ( viewLine ) ; } OrderViewModel viewModel = new OrderViewModel ( ) { Date = DateTime . Now , CustomerId = cust , CustomerName = _repository . GetCustomerById ( cust ) . Fname , OrderId = cart . OrderId , StoreName = _repository . GetLocationById ( loc ) . Name , TotalPrice = total , orderLines = cartLineViewModels } ; return viewModel ; }
returns a viewmodel based on the currently open cart if a user is logged in
returns a viewmodel based on the currently open cart if a user is logged in
//if (SessionGetCurrentUser() != null) { return null; }
None