public void newUserUI() { Console.WriteLine("Please enter your First Name, Last Name and Email"); Console.WriteLine("First Name:"); FirstName = GetUserInput(); while (string.IsNullOrEmpty(FirstName)) { Console.WriteLine("First Name can't be empty. Input your First Name"); FirstName = GetUserInput(); } Console.WriteLine("Last Name:"); LastName = GetUserInput(); while (string.IsNullOrEmpty(LastName)) { Console.WriteLine("Last Name can't be empty. Input your First Name"); LastName = GetUserInput(); } Console.WriteLine("Email:"); string Email = GetUserInput(); while (string.IsNullOrEmpty(LastName)) { Console.WriteLine("Last Name can't be empty. Input your First Name"); LastName = GetUserInput(); } Library.Customer newCustomer = new Library.Customer(FirstName, LastName, Email); storeRepo.AddCustomer(newCustomer); }
public ActionResult AddOrder(int Id) { try { if (ModelState.IsValid) { Library.Customer customer = CustomerRepo.GetCustomerById(Id); OrderRepo.AddOrder(new Lib.Order { CustomerId = customer.Id, StoreId = customer.StoreId, TimePlaced = DateTime.Now }); var order = OrderRepo.GetAllOrders().Last(); var inv = StoreRepo.GetInventoryProducts(StoreRepo.GetInventory(customer.StoreId)); foreach (Lib.Product item in inv) { OrderRepo.AddProduct(order.Id, item); } return(RedirectToAction("Index", "Cart", new { @id = order.Id })); } } catch { return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
/// <summary> /// Finds customer from db to be updated, then switch values with the input'd customer values /// </summary> /// <param name="customer"></param> public void UpdateCustomer(Library.Customer customer) { Customers entity = dbcontext.Customers.Find(customer.CustomerId); Customers modelToEntity = Mapper.MapCustomer(customer); dbcontext.Entry(entity).CurrentValues.SetValues(modelToEntity); }
public ActionResult Edit(int id, [Bind("FirstName,LastName,Id")] CustomerViewModel viewCustomer, IFormCollection collection) { // get the current id from tempdata to ensure the user hasn't modified the id that the page put out int tdId = (int)TempData.Peek("Customer"); if (tdId != id && tdId != viewCustomer.Id) { // *ER add error message return(RedirectToAction(nameof(Index))); } // check the modelstat if (!ModelState.IsValid) { return(View(viewCustomer)); } try { var customer = new Library.Customer(viewCustomer.FirstName, viewCustomer.LastName, viewCustomer.Id); _customerRepository.Update(customer); return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "There was a problem updating the Customer"); return(View(viewCustomer)); } }
public void MostOrders() { float high = 0; float temp = 0; Library.Customer best = new Library.Customer(); var customerRepo = new CustomerRepository(_dbContext); var customers = customerRepo.GetAll().ToList(); var orders = GetAllOrders(); foreach (Library.Customer c in customers) { foreach (Library.Order o in orders.Where(ord => ord.CustomerId == c.Id)) { temp++; } if (temp > high) { high = temp; best = c; } temp = 0; } Console.WriteLine($"{best.FirstName + ' ' + best.LastName} had" + $" the most orders with: {high}"); Console.WriteLine(); }
public void HighestSumTotal() { float high = 0; float temp = 0; Library.Customer best = new Library.Customer(); var customerRepo = new CustomerRepository(_dbContext); var customers = customerRepo.GetAll().ToList(); var orders = GetAllOrders(); foreach (Library.Customer c in customers) { foreach (Library.Order o in orders.Where(ord => ord.CustomerId == c.Id)) { var items = GetOrderItems(o.Id).ToList(); var products = GetOrderProducts(items); var orderTotal = OrderTotal(o.Id); temp += orderTotal; } if (temp > high) { high = temp; best = c; } } Console.WriteLine($"{best.FirstName + ' ' + best.LastName} had" + $" the highest \"Order Total\" sum: ${high}"); }
public static DataAccess.Customer Map(Library.Customer customer) => new DataAccess.Customer { CustomerId = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, DefaultLocation = customer.DefaultLocation };
public CustomerViewModel(Library.Customer customer, Library.Location store) { Id = customer.Id; FullName = customer.FirstName + ' ' + customer.LastName; Birthday = customer.Birthday; Store = store; }
// GET: Customers/Details/5 public ActionResult Details(int?id) { if (id == null) { return(NotFound()); } Library.Customer customer = Repo.SearchCustomersById((int)id); if (customer == null) { return(NotFound()); } CustomerViewModel model = new CustomerViewModel { Id = customer.CustId, FirstName = customer.FName, LastName = customer.LName, DateOfBirth = customer.DateOfBirth, PrefLocNavigation = Repo.SearchLocationsById(customer.Loc) }; return(View(model)); }
public void EditCustomer(Library.Customer customer) { if (_db.Customer.Find(customer.CustomerId) != null) { _db.Customer.Update(CustomerMapper.Map(customer)); } }
public ActionResult Create(Models.Customer newCustomer) { try { if (ModelState.IsValid) { Library.Customer newCustomerMapped = ManualMapper.ManMap2(newCustomer); //var newCustomerMapped2 = ManualMapper.ManMap(newCustomerMapped); Repo.InsertCustomer(newCustomerMapped); } else { return(View()); } return(RedirectToAction(nameof(Index))); } catch (ArgumentException ex) { ModelState.AddModelError("Id", ex.Message); return(View()); } catch { return(View()); } }
public static Entities.Customer Map(Library.Customer customer) => new Entities.Customer { CustomerId = customer.CustomerId, FirstName = customer.FirstName, LastName = customer.LastName, DefaultStoreNavigation = Map(customer.DefaultStore) };
// GET: Order public ActionResult Index(int Id) { if (CustomerRepo.ContainsId(Id)) { ViewBag.customerId = Id; Library.Customer customer = CustomerRepo.GetCustomerById(Id); IEnumerable <Lib.Inventory> libInv = StoreRepo.GetInventory(customer.StoreId); IEnumerable <Lib.Product> libProducts = StoreRepo.GetInventoryProducts(libInv); IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel { Id = x.Id, Name = x.Name, Price = (decimal)x.Price, Quantity = libInv.First(i => i.ProductId == x.Id && i.StoreId == customer.StoreId).Quantity, StoreName = StoreRepo.GetStoreById(customer.StoreId).Name, CustomerName = customer.FirstName + ' ' + customer.LastName }); return(View(ivm)); } else { return(RedirectToAction("Index", "Home")); } }
public static Entities.Customer Map(Library.Customer customer) => new Entities.Customer { Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber, PurOrder = customer.PurOrder.Select(Map).ToList() };
public static Customer Map(Library.Customer customer) => new Customer { Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, Birthday = customer.Birthday, StoreId = customer.StoreId, };
public static Customer Map(Library.Customer customer) => new Customer { CustomerId = customer.CustId, FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber, DefaultLocationId = customer.DefaultStoreId };
public Library.Customer GetCustomerById(int customerId) { using var context = new project0Context(_dbContext); var dbCustomer = context.Customers.FirstOrDefault(o => o.CustomerId == customerId); var appCustomer = new Library.Customer(dbCustomer.CustomerId, dbCustomer.FirstName, dbCustomer.LastName, dbCustomer.Email); return(appCustomer); }
/// <summary> /// Maps a Customer object to an entry in the database /// </summary> /// <param name="customer"></param> /// <returns></returns> public static Model.Customer MapCustomerToDbEntry(Library.Customer customer) { return(new Model.Customer { FirstName = customer.FirstName, LastName = customer.LastName }); }
public Entities.Customer ParseCreator(Library.Customer creator) { return(new Entities.Customer() { FirstName = creator.FirstName, LastName = creator.LastName, PhoneNumber = creator.PhoneNumber }); }
public static Customer Map(Library.Customer customer) => new Customer { Id = customer.ID, StoreId = customer.StoreId, FirstName = customer.FirstName, LastName = customer.LastName, Address = customer.Address, PhoneNumber = customer.PhoneNumber, };
public static Library.Order Map(Entities.Orders order, Library.Customer custom) => new Library.Order { Id = order.OrderId, CustomerId = order.CustomerId, Recipient = custom, LocationId = order.LocationId, Ordered = Map(order.OrderLine).ToList(), ItemCount = MapDic(order.OrderLine), PlacedTime = (DateTime)order.PurchaseDate };
//Map business model to EF //object data --> Entity public static Entities.Customer MapCustomerWithEF(Library.Customer Ocustomer) { return(new Entities.Customer { Cid = Ocustomer.ID, Names = Ocustomer.Names, Addresses = Ocustomer.Address, Phone = Ocustomer.Phone }); }
public void Create(Library.Customer customer) { var cust = new Customer() { FirstName = customer.FirstName, LastName = customer.LastName }; _context.Add(cust); _context.SaveChanges(); }
public void Update(Library.Customer customer) { // get customer from db var dbCust = _context.Customers.First(c => c.Id == customer.Id); // update names dbCust.FirstName = customer.FirstName; dbCust.LastName = customer.LastName; // save changes _context.SaveChanges(); }
/* Customer mapping */ public static Entities.Customers MapCustomer(Library.Customer model) { Entities.Customers result = new Entities.Customers { CustomerId = model.CustomerId, FirstName = model.FirstName, LastName = model.LastName, }; return(result); }
public static Library.Customer MapCustomer(Entities.Customers dbmodel) { Library.Customer result = new Library.Customer { CustomerId = dbmodel.CustomerId, FirstName = dbmodel.FirstName, LastName = dbmodel.LastName, }; return(result); }
public static Customer Map(Library.Customer customer) => new Customer { Userid = customer.Userid, Username = customer.Username, Deflocationid = customer.Deflocationid, Haveorder = customer.Haveorder, Dateplaced = customer.Dateplaced, // Deflocation = Map(customer.Deflocation), // History = Map(customer.History).ToList(), // Orderdetails = Map(customer.Orderdetails).ToList(), };
public void UpdateCustomerDb(Library.Customer customer) { using var context = new AquariumContext(_contextOptions); var dbCust = context.Customers .Where(c => c.CustomerId == customer.CustomerId) .FirstOrDefault(); dbCust.FirstName = customer.FirstName; dbCust.LastName = customer.LastName; dbCust.Email = customer.Email; context.SaveChanges(); }
public void AddToCustomerDb(Library.Customer customer) { using var context = new AquariumContext(_contextOptions); var newCust = new DataModel.Customer() { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email }; context.Customers.Add(newCust); context.SaveChanges(); }
// Get orders from the database public List <Library.Order> GetCustOrders(Library.Customer customer) { using var context = new AquariumContext(_contextOptions); var dbOrders = context.Orders .Where(o => o.CustomerId == customer.CustomerId); var orders = new List <Library.Order>(); foreach (var obj in dbOrders) { orders.Add(GetOrderById(obj.OrderId)); } return(orders); }