public Model.Customer AddNewCustomer(Model.Customer customer) { Entity.Customer newCust = _context.Customers.Add(_mapper.ParseCustomer(customer, true)).Entity; _context.SaveChanges(); _context.ChangeTracker.Clear(); return(_mapper.ParseCustomer(newCust)); }
public Models.Customer ParseCustomer(Entities.Customer customer) { Models.Customer c = new Models.Customer(); c.CustomerID = customer.CustomerId; c.Name = customer.CustomerName; c.IsManager = customer.IsManager; return(c); }
public Model.Order UpdateOrder(Model.Order order, Model.Location location, Model.Customer customer) { Entity.Order updateOrder = _context.Orders.Single(ord => ord.OrderId == order.OrderID); updateOrder.Total = order.Total; _context.SaveChanges(); Log.Information("DL persisted order update to DB"); return(order); }
public Entity.Customer ParseCustomer(Model.Customer customer) { return(new Entity.Customer { FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber }); }
public Model.Customer GetCustomer(Model.Customer customer) { Entity.Customer found = _context.Customers.FirstOrDefault(custo => custo.FirstName == customer.FirstName && custo.LastName == customer.LastName && custo.Birthdate == customer.Birthdate && custo.PhoneNumber == customer.PhoneNumber && custo.Email == customer.Email && custo.MailAddress == customer.MailAddress); if (found == null) { return(null); } Log.Information("DL sent customer to BL"); return(new Model.Customer(found.CustomerId, found.FirstName, found.LastName, found.Birthdate, found.PhoneNumber, found.Email, found.MailAddress)); }
public Entities.Customer ParseCustomer(Models.Customer customer) { Entities.Customer c = new Entities.Customer(); if (customer.CustomerID != null) { c.CustomerId = (int)customer.CustomerID; } c.CustomerName = customer.Name; c.IsManager = customer.IsManager; return(c); }
public int?AddCustomer(string name, Models.Customer customer) { Entities.Customer cEntity = mapper.ParseCustomer(customer); ctx.Customers.Add(cEntity); ctx.SaveChanges(); using var log = new LoggerConfiguration() .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, shared: true) .CreateLogger(); log.Information("TRANSACTION: Created a new customer"); return(cEntity.CustomerId); }
public Entity.Customer ParseCustomer(Model.Customer customer) { return(new Entity.Customer { Id = customer.CustID, FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email, PhoneNumber = customer.PhoneNumber }); }
public Model.Customer AddCustomer(Model.Customer newCustomer) { _context.Customers.Add( new Entity.Customer { Username = newCustomer.UserName, Name = newCustomer.Name } ); _context.SaveChanges(); return(newCustomer); }
public Model.Order AddOrder(Model.Order order, Model.Location location, Model.Customer customer) { _context.Orders.Add( new Entity.Order { LocationId = order.LocationID, CustomerId = order.CustomerID, Total = order.Total, OrderDate = order.OrderDate } ); Log.Information("DL persisted order add to DB"); _context.SaveChanges(); return(order); }
public Model.Customer AddCustomer(Model.Customer customer) { _context.Customers.Add( new Entity.Customer { FirstName = customer.FirstName, LastName = customer.LastName, Birthdate = customer.Birthdate, PhoneNumber = customer.PhoneNumber, Email = customer.Email, MailAddress = customer.MailAddress } ); _context.SaveChanges(); Log.Information("DL persisted customer add to DB"); return(customer); }
public Entity.Customer ToEntity(Model.Customer customer) { List <Entity.Order> orders = new List <Entity.Order>(); if (customer.Orders is not null) { foreach (Model.Order order in customer.Orders) { orders.Add(ToEntity(order)); } } return(new Entity.Customer { Id = customer.Id, CName = customer.Name, Orders = orders }); }
// public Model.Customer ParseCustomer(int? customer) // { // return new Model.Customer // { // CustomerName = customerTemp.CustomerName, // PhoneNumber = customerTemp.PhoneNumber, // CarType = (Model.CarType)customerTemp.CarType, // Id = (int)customerTemp.Id // }; // } // //get public Model.Customer ParseCustomer(Entity.Customer customer) { customerTemp = new Model.Customer { CustomerName = customer.CustomerName, PhoneNumber = customer.PhoneNumber, CarType = (Model.CarType)customer.CarType, Id = (int)customer.Id }; return(new Model.Customer { CustomerName = customer.CustomerName, PhoneNumber = customer.PhoneNumber, CarType = (Model.CarType)customer.CarType, Id = (int)customer.Id }); }
public Entity.Customer ParseCustomer(Model.Customer customer) { if (customer.CustomerID == null) { return(new Entity.Customer { CustomerName = customer.CustomerName, CustomerEmail = customer.CustomerEmail }); } return(new Entity.Customer { CustomerName = customer.CustomerName, CustomerEmail = customer.CustomerEmail, Id = (int)customer.CustomerID }); }
public Entity.Customer ParseCustomer(Model.Customer customer) { //when customer is a new customer, NO id is set if (customer.Id == 0) { return(new Entity.Customer { Name = customer.CustomerName, Email = customer.CustomerEmail }); } //for updating and deleting return(new Entity.Customer { Name = customer.CustomerName, Email = customer.CustomerEmail, Id = (int)customer.Id }); }
//Set public Entity.Customer ParseCustomer(Model.Customer customer) { if (customer.Id == null) { return(new Entity.Customer { CustomerName = customer.CustomerName, PhoneNumber = customer.PhoneNumber, CarType = (int)customer.CarType, }); } return(new Entity.Customer { CustomerName = customer.CustomerName, PhoneNumber = customer.PhoneNumber, CarType = (int)customer.CarType, Id = (int)customer.Id }); }
public List <Model.Order> GetCustomerOrderByTotal(Model.Customer customer) { List <Model.Order> allOrders = GetAllOrder(); List <Model.Order> customerOrder = new List <Model.Order>(); foreach (Model.Order order in allOrders) { if (order.Customer.UserName == customer.UserName) { customerOrder.Add(order); } } customerOrder.Sort(delegate(Model.Order x, Model.Order y) { return(x.Total.CompareTo(y.Total)); }); return(customerOrder); }
public Entity.Customer ParseCustomer(Model.Customer customer, bool create) { if (customer is null) { return(null); } if (create) { return(new Entity.Customer { CName = customer.Name, }); } else { return(new Entity.Customer { Id = customer.Id, CName = customer.Name, }); } }
static void Login() { string name; do { name = userInterface.GetLine("Enter your name: "); } while (name.Equals("")); currentUser = dataStore.GetCustomer(name); if (currentUser == null) { currentUser = new StoreModels.Customer(); currentUser.Name = name; currentUser.CustomerID = dataStore.AddCustomer(name, currentUser); } cart = new StoreModels.Order(); cart.Customer = currentUser; managerMenu = false; if (currentUser.IsManager) { managerMenu = userInterface.GetLine("Would you like to log in as a manager? [ y / N ]: ").ToLower().Equals("y"); } Console.Clear(); }
public Entity.Customer ParseCustomer(Model.Customer customer) { if (customer.Id == null) { return(new Entity.Customer { CustomerName = customer.CustomerName, CustomerEmail = customer.CustomerEmail, CustomerPasswordHash = customer.CustomerPasswordHash, CustomerPhone = customer.CustomerPhone, CustomerAddress = customer.CustomerAddress, }); } return(new Entity.Customer { CustomerName = customer.CustomerName, CustomerEmail = customer.CustomerEmail, CustomerPasswordHash = customer.CustomerPasswordHash, CustomerPhone = customer.CustomerPhone, CustomerAddress = customer.CustomerAddress, Id = (int)customer.Id }); }
public Model.Customer AddCustomer(Model.Customer newCustomer) { _context.Customers.Add(_mapper.ParseCustomer(newCustomer)); _context.SaveChanges(); return(newCustomer); }
public string GetCustomerName(string username) { Model.Customer found = customerDB.GetCustomer(username); return(found.Name); }
public Model.Customer ParseCustomer(Entity.Customer customer) { Model.Customer newCustomer = new Model.Customer(customer.FirstName, customer.LastName, customer.PhoneNumber); newCustomer.CustID = customer.CustId; return(newCustomer); }
static bool MainMenu() { while (currentUser != null) { userInterface.PrintText("Welcome, " + currentUser.Name); userInterface.PrintText( "Please choose an option to continue...\n" + (managerMenu ? "[0] View inventory changes\n" : "[0] View cart\n") + (managerMenu ? "[1] Restock item\n" : (cart.CheckedOut ? "[1] Check Cart Inventory\n" : "[1] Add item to cart\n")) + "[2] Search for items\n" + (cart.CheckedOut ? "[3] Repeat Order\n" : (managerMenu ? "[3] Save inventory changes\n" : "[3] Check Out\n")) + (managerMenu ? "[4] View order history\n" : (cart.CheckedOut ? "[4] Close previous order\n" : "[4] View Previous Order\n")) + "[5] Log Out\n" + "[6] Exit" ); switch (userInterface.GetLine()) { case "0": // View cart Console.Clear(); ViewCartMenu(); break; case "1": // Search available items & add to cart | Check inventory of items in cart Console.Clear(); if (cart.CheckedOut) { string inventoryLog = "Checking whether all products from this order are still in stock\n"; bool canReorder = true; foreach (Item item in cart.Items) { int curInventory = dataStore.GetLocationInventory(cart.Location, item.Product); inventoryLog += "\n" + item.Product.ProductName + " in stock: " + curInventory + " (ordered " + item.Quantity + ')'; if (curInventory < item.Quantity) { canReorder = false; } } inventoryLog += "\n\nYour order is" + (canReorder ? "" : " not") + " in stock."; userInterface.PrintResult(inventoryLog); break; } AddToCartMenu(); break; case "2": // Search full item list Console.Clear(); ListProductsMenu(); break; case "3": // Check out | Copy Cart Console.Clear(); if (cart.CheckedOut) { bool canReorder = true; foreach (Item item in cart.Items) { int curInventory = dataStore.GetLocationInventory(cart.Location, item.Product); if (curInventory < item.Quantity) { canReorder = false; } } if (canReorder) { Order newCart = cart.copy(); foreach (Item item in cart.Items) { dataStore.UpdateLocationInventory(newCart.Location, item.Product, item.Quantity * (managerMenu ? 1 : -1)); } cart = newCart; newCart.Customer = currentUser; userInterface.PrintResult("Copied all items into your cart"); } else { userInterface.PrintResult("Not enough inventory to copy this order"); } break; } if (cart.Items.Count == 0) { userInterface.PrintResult("Please add at least one item to your cart first"); break; } if (managerMenu || userInterface.GetLine("Your total is " + cart.Total.ToString("C") + "\nCheck out? [ y / N ]: ").ToLower().Equals("y")) { userInterface.PrintResult(managerMenu ? "Restock successful" : "Order successful, thanks for shopping with us!"); cart.CheckedOut = true; cart.CheckoutTimestamp = DateTime.Now; dataStore.PlaceOrder(cart); cart = new Order(); cart.Customer = currentUser; } Console.Clear(); break; case "4": // View previous order | return to current order Console.Clear(); if (cart.CheckedOut) { cart = new Order(); cart.Customer = currentUser; break; } bool sortByPrice = userInterface.GetLine("Sort by price? (default: date) [ y / N ]: ").ToLower().Equals("y"); bool desc = userInterface.GetLine("Use descending order? [ y / N ]: ").ToLower().Equals("y"); string loc = userInterface.GetLine("Enter a location to filter by or press enter to view all orders: "); List <Order> previousOrders = managerMenu ? dataStore.GetAllOrders() : dataStore.GetCustomerOrders(currentUser); if (!loc.Equals("")) { for (int i = previousOrders.Count - 1; i >= 0; i--) { if (previousOrders[i].Location.LocationName.Equals(loc)) { continue; } previousOrders.RemoveAt(i); } } if (sortByPrice) { previousOrders.Sort((o1, o2) => { decimal diff = o1.Total - o2.Total; if (diff == 0) { return(0); } if (diff < 0) { return(-1); } return(1); }); } if (desc) { previousOrders.Reverse(); } int index = CartSelectMenu(previousOrders); if (index < 0) { break; } if (userInterface.GetLine("This will overwrite your current cart\nProceed? [ y / N ]: ").ToLower().Equals("y")) { cart = previousOrders[index]; } Console.Clear(); break; case "5": // Log out Console.Clear(); currentUser = null; break; case "6": // Exit Console.Clear(); return(true); default: Console.Clear(); userInterface.PrintText("Invalid input, please enter one of the given options"); break; } } return(false); }
public List <Models.Order> GetCustomerOrders(Models.Customer customer) { return(ctx.StoreOrders.Include(o => o.Customer).Include(o => o.Location).Include(o => o.OrderItems).ThenInclude(i => i.Product).Where(o => o.CustomerId == customer.CustomerID).Select(o => mapper.ParseOrder(o)).ToList()); }
public Customer GetCustomerByNumber(string number) { customerTemp = _context.Customers.AsNoTracking().Select(x => _mapper.ParseCustomer(x)).ToList().FirstOrDefault(x => x.PhoneNumber == number); return(_context.Customers.AsNoTracking().Select(x => _mapper.ParseCustomer(x)).ToList().FirstOrDefault(x => x.PhoneNumber == number)); }
public Model.Customer GetCustomer(string username) { Model.Customer found = customerDB.GetCustomer(username); return(new Model.Customer(found.Name, found.UserName)); }