示例#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);
        }
示例#2
0
        /// <summary>
        /// The purpose of this method is to search the db to return a model of the customer object given two strings as names
        /// </summary>
        /// <param name="search">Two strings a first and a last name</param>
        /// <returns>A customer object</returns>
        public List <Library.Models.Customer> FindCustomerByName(string[] search)
        {
            // Search the db and if someone is found assign it if no one was found assign null
            List <CustomerEntity> dbCustomer = _context.Customers.Where(c => (c.FirstName == search[0] && c.LastName == search[1])).ToList();

            // if it is null exit the method and return null
            if (dbCustomer == null)
            {
                return(null);
            }

            List <Library.Models.Customer> m_customers = new List <Library.Models.Customer>();

            foreach (CustomerEntity customer in dbCustomer)
            {
                m_customers.Add(Mapper_Customer.Map(customer));
            }

            return(m_customers);
        }
示例#3
0
        /// <summary>
        /// Right now this is mainly a helper method when placing the order. This is because this returns a Library.Models.Customer object
        /// That is manipulated by the c# code. The intention was to get the Customer and then set the location and it's inventory
        /// </summary>
        /// <param name="name">Two strings that are valid names.</param>
        /// <returns></returns>
        public Library.Models.Customer GetCustomerWithLocationAndInventory(int id)
        {
            // first we create our db customer to check if we find it
            CustomerEntity dbCustomer = new CustomerEntity();

            try
            {
                // if we do then we assign it to the customer
                dbCustomer = _context.Customers.Include(l => l.Location).First(c => c.Id == id);
            }
            catch (InvalidOperationException ex) {
                // if we don't then we return null
                return(null);
            }
            // since we found it we map the new customer with the location
            Library.Models.Customer m_customer = Mapper_Customer.MapCustomerWithLocation(dbCustomer);

            // then we get the stocks for the location
            m_customer.MyStoreLocation.Inventory = GetStocksForLocation(m_customer.MyStoreLocation.ID);

            return(m_customer);
        }