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); }
/// <summary> /// Right now this is mainly a helper method when placing the order. This is because this returns a Domain.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 Domain.Models.Customer GetCustomerWithLocationAndInventory(int id) { // first we create our db customer to check if we find it Entities.CustomerEntity dbCustomer; // if we do then we assign it to the customer dbCustomer = _context.Customers .Include(l => l.Location) .Include(sc => sc.Shoppingcarts) .ThenInclude(ci => ci.Cartitems).First(c => c.Id == id); // since we found it we map the new customer with the location Domain.Models.Customer m_customer = MapperCustomer.MapCustomerWithLocation(dbCustomer); // then we get the stocks for the location m_customer.MyStoreLocation.Inventory = GetStocksForLocation(m_customer.MyStoreLocation.ID).ToList(); return(m_customer); }
/// <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 IEnumerable <Domain.Models.Customer> FindCustomerByName(string[] search) { // Search the db and if someone is found assign it if no one was found assign null List <Entities.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(new List <Domain.Models.Customer>()); } List <Domain.Models.Customer> m_customers = new List <Domain.Models.Customer>(); foreach (Entities.CustomerEntity customer in dbCustomer) { m_customers.Add(MapperCustomer.Map(customer)); } return(m_customers); }
/// <summary> /// Add a new Customer from Models to Database. /// </summary> /// <param name="customer"> This is the new Model to be put into the database. It only has a firstname and last name.</param> public void AddACustomer(Domain.Models.Customer customer) { // Create the Entity item to be put into the database Entities.CustomerEntity entity; // Since the database handles the ID setting with identity, we only need to assign the new entity the firstname and the lastname // Maybe in the future we could add a way to change the location, but for now the database sets the location to the default 1. entity = MapperCustomer.Map(customer); // Add the new entity to the context to send over to the database _context.Add(entity); Save(); // Create their shopping cart Entities.ShoppingcartEntity shoppingcartEntity = new Entities.ShoppingcartEntity { CustomerId = entity.Id }; _context.Add(shoppingcartEntity); // I am using the aproach of sending the data over after each change instead of having a universal save button Save(); }
public CustomerController() { repCustomer = new CustomerRep(); mapperCustomer = new MapperCustomer(); }