Exemplo n.º 1
0
        public string 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 library with the relevant books
            FillBookLibrary();

            // Attempt to find the customer
            CustomerEntity dbCustomer = _context.Customers
                                        .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("No Customer exists by this name.");
            }
            string result = "";

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

            // Build the string that needs to be returned
            result += m_customer;
            foreach (Library.Models.Order order in m_customer.Orders)
            {
                result += $"\n{order}";
            }
            return(result);
        }