Example #1
0
        /// <summary>
        /// Method to get a customer object by its first and last name
        /// </summary>
        /// <param name="firstName">The firstname of the customer to get the object from db</param>
        /// <param name="lastName">The firstname of the customer to get the object from db</param>
        public BusinessLibrary.Customer GetCustomerByName(string firstName, string lastName)
        {
            BusinessLibrary.Customer customer = null;

            IQueryable <Entity.Entities.User> customers = _dbContext.Users;

            foreach (var c in customers)
            {
                if (c.FirstName.Equals(firstName, StringComparison.InvariantCultureIgnoreCase) && c.LastName.Equals(lastName, StringComparison.InvariantCultureIgnoreCase))
                {
                    customer = new Customer(c.Id, c.FirstName, c.LastName, c.UserType);
                }
            }

            return(customer);
        }
Example #2
0
        /// <summary>
        /// Method to get all orders from a specific customer
        /// </summary>
        /// <param name="c">The customer object to get orders from</param>
        public IEnumerable <BusinessLibrary.Order> GetOrdersByCustomer(BusinessLibrary.Customer c)
        {
            List <BusinessLibrary.Order> ordersList = new List <BusinessLibrary.Order>();

            IQueryable <Entity.Entities.Order> orders = _dbContext.Orders.Where(x => x.UserId == c.CustomerId);

            foreach (var o in orders)
            {
                Customer cust = GetCustomerById(o.UserId);
                BusinessLibrary.StoreLocation sl = new BusinessLibrary.StoreLocation();
                sl = GetStoreById(o.StoreId + 1);
                BusinessLibrary.Order order = new BusinessLibrary.Order(o.Id, cust, o.OrderTime, sl, o.OrderTotal);
                ordersList.Add(order);
            }

            return(ordersList);
        }