public Domain.Models.Customer GetOrderHistoryByCustomer(int id)
        {
            // This method is called because we need the information on the whole catalog
            // Since the catalog is small I went with this implementation.
            // If it was much large I would only fill the Domain with the relevant books
            FillBookLibrary();

            // Attempt to find the customer
            Entities.CustomerEntity dbCustomer = _context.Customers
                                                 .Include(l => l.Location)
                                                 .Include(o => o.Orders)
                                                 .ThenInclude(ol => ol.Orderlines)
                                                 .FirstOrDefault(c => c.Id == id);

            // If the customer was not found then let the user know
            if (dbCustomer == null)
            {
                return(null);
            }

            // if one was found then map it to a usable object
            Domain.Models.Customer m_customer = MapperCustomer.MapCustomerWithOrders(dbCustomer);

            return(m_customer);
        }
Exemple #2
0
 /// <summary>
 /// This turns a customer Entity into a customer model.
 /// </summary>
 /// <param name="customer">The customer entity.</param>
 /// <returns></returns>
 public static Library.Models.Customer Map(Entities.CustomerEntity customer)
 {
     return(new Library.Models.Customer
     {
         ID = customer.Id,
         FirstName = customer.FirstName,
         LastName = customer.LastName
     });
 }
Exemple #3
0
 /// <summary>
 /// Turn an entity customer with their orders into a customer model
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public static Library.Models.Customer MapCustomerWithOrders(Entities.CustomerEntity customer)
 {
     return(new Library.Models.Customer
     {
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         ID = customer.Id,
         Orders = customer.Orders.Select(Mapper_Order.MapOrderWithOrderLines).ToList()
     });
 }
Exemple #4
0
 /// <summary>
 /// Turn an entity customer with their location into a model customer
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public static Library.Models.Customer MapCustomerWithLocation(Entities.CustomerEntity customer)
 {
     return(new Library.Models.Customer
     {
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         ID = customer.Id,
         MyStoreLocation = Mapper_Location.MapLocationsWithInventory(customer.Location)
     });
 }
 /// <summary>
 /// This turns a customer Entity into a customer model.
 /// </summary>
 /// <param name="customer">The customer entity.</param>
 /// <returns></returns>
 public static Domain.Models.Customer Map(Entities.CustomerEntity customer)
 {
     return(new Domain.Models.Customer
     {
         ID = customer.Id,
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         MyStoreLocation = MapperLocation.Map(customer.Location)
     });
 }
 /// <summary>
 /// Turn an entity customer with their orders into a customer model
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public static Domain.Models.Customer MapCustomerWithOrders(Entities.CustomerEntity customer)
 {
     return(new Domain.Models.Customer
     {
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         ID = customer.Id,
         MyStoreLocation = MapperLocation.Map(customer.Location),
         Orders = customer.Orders.Select(MapperOrder.MapOrderWithOrderLines)
     });
 }
 /// <summary>
 /// Turn an entity customer with their location into a model customer
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public static Domain.Models.Customer MapCustomerWithLocation(Entities.CustomerEntity customer)
 {
     return(new Domain.Models.Customer
     {
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         ID = customer.Id,
         MyStoreLocation = MapperLocation.MapLocationsWithInventory(customer.Location),
         MyCart = customer.Shoppingcarts.Select(sc => new Domain.Models.ShoppingCart
         {
             DateCreated = (System.DateTime)sc.CreateData,
             ID = sc.CartId,
             CartItems = sc.Cartitems.Select(ci => new Domain.Models.CartItem
             {
                 ID = ci.ItemId,
                 Book = Domain.Models.Book.GetBookFromLibrary(ci.BookIsbn),
                 Quantity = ci.Quantity
             })
         }).FirstOrDefault()
     });
 }