public Order Add(Order order) { return(Repository.AddOrder(order)); }
public ActionResult OrderTour(int id, int placeNumber) { UserRepository userRepository = new UserRepository(); OrderRepository orderRepository = new OrderRepository(); TourRepository tourRepository = new TourRepository(); Tour tour = tourRepository.GetById(id); if (tour != null) { Order order = new Order(); order.Date = DateTime.Now; order.PlaceCount = placeNumber; order.Tour = tour; order.User = userRepository.GetBy(x => x.Email == User.Identity.Name); orderRepository.AddOrder(order); } return Redirect("/Tour/Orders"); }
public void AddOrder(Order order) { _repo.AddOrder(order); }
private void ClientOrderCreator() { var internetClient = ClientService.GetInternetClient(_activeClient); var internetOrder = internetClient != null; var exit = false; var objects = _objectRepository.GetAllObjects(); var order = new Order(); order.ClientId = _activeClient.Id; var orderObjects = new List <OrderObject>(); var orderInfo = internetOrder ? "Client ip: " + internetClient.IpAddress + " " : ""; orderInfo += "products: "; while (!exit) { Console.WriteLine(""); Console.WriteLine("Press s to type number of product to add to order"); Console.WriteLine("Press a to get all clients who ordered product"); Console.WriteLine("Press p to place order"); Console.WriteLine("Press esc to comeback to menu"); Console.WriteLine(""); Console.WriteLine(orderInfo); int iter = 0; foreach (var obj in objects) { Console.Out.WriteLine(iter + ". name: " + obj.Description + " price: " + obj.Price + " (In stock: " + obj.InStock + ")"); iter++; } ConsoleKeyInfo currentKey = Console.ReadKey(true); switch (currentKey.Key) { case ConsoleKey.S: Console.Out.WriteLine("Type product number:"); string input = Console.ReadLine(); int number; if (!Int32.TryParse(input, out number)) { Console.Out.WriteLine("Not a valid number - try again!"); Thread.Sleep(1000); } else { if (number >= 0 && number < objects.Count) { var obj = objects[number]; Console.Out.WriteLine("Type amount:"); input = Console.ReadLine(); int amount; if (!Int32.TryParse(input, out amount)) { Console.Out.WriteLine("Not a valid amount - try again!"); Thread.Sleep(1000); } else { var orderObj = new OrderObject(); orderObj.ObjectId = obj.Id; orderObj.Amount = ((amount > 0) ? amount : 1); orderObjects.Add(orderObj); if (orderObjects.Count != 1) { orderInfo += ", "; } orderInfo += obj.Description + " - " + amount; } } } break; case ConsoleKey.A: Console.Out.WriteLine("Type product number:"); string inp = Console.ReadLine(); int num; if (!Int32.TryParse(inp, out num)) { Console.Out.WriteLine("Not a valid number - try again!"); Thread.Sleep(1000); } else { if (num >= 0 && num < objects.Count) { var obj = objects[num]; var objectClients = ClientService.GetAllClientsWhoOrdered(obj); var toPrint = (objectClients.Count > 0) ? "Clients who ordered " + obj.Description + ": " : "Noone ordered " + obj.Description; foreach (var c in objectClients) { if (objectClients.IndexOf(c) != 0) { toPrint += ", "; } toPrint += c.Name; } Console.WriteLine(toPrint); Thread.Sleep(3000); } } break; case ConsoleKey.P: order.Objects = orderObjects; if (order.Objects.Count > 0) { _orderRepository.AddOrder(order); Console.Out.WriteLine("Placed order successfully!"); } else { Console.Out.WriteLine("Order not placed - no products selected!!"); } exit = true; break; case ConsoleKey.Escape: exit = true; break; default: break; } } }
public bool AddOrder(Order _order) { return(_orderRepository.AddOrder(_order)); }
public static void Main() { var optionsBuilder = new DbContextOptionsBuilder <HardwareStoreDbContext>(); optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString); var dbContext = new HardwareStoreDbContext(optionsBuilder.Options); CustomerRepository customerRepository = new CustomerRepository(dbContext); OrderRepository orderRepository = new OrderRepository(dbContext); LocationRepository locationRepository = new LocationRepository(dbContext); ProductsRepository productsRepository = new ProductsRepository(dbContext); Console.WriteLine("Welcome to Francisco's Hardware Store! "); while (true) { Console.WriteLine("\no:\tPlace an order"); Console.WriteLine("n:\tSearch for customer by name"); Console.WriteLine("l:\tDisplay all orders by store location"); Console.WriteLine("c:\tDisplay all orders by customer"); Console.WriteLine("a\tView all orders that have been placed."); Console.WriteLine("q\tQuit"); String input = Console.ReadLine(); if (input == "o") { customerRepository.DisplayCustomers(); Console.WriteLine("Which customer is the order for? input customer id:"); input = Console.ReadLine(); int val = 0; if (Int32.TryParse(input, out val)) { Library.Customer customer = customerRepository.GetCustomerById(Int32.Parse(input)); int customerId = Int32.Parse(input); Console.WriteLine("Your default store id is " + customer.DefaultStoreId + " location: " + locationRepository.GetLocationById(customer.DefaultStoreId).Name); Console.WriteLine("Do you want to order from a different location? input y for yes"); input = Console.ReadLine(); if (input == "y") { locationRepository.DisplayLocations(); Console.WriteLine("input location id"); input = Console.ReadLine(); int val2 = 0; if (Int32.TryParse(input, out val2)) { int storeLoc = Int32.Parse(input); //storeloc will be ordering from var inventory = locationRepository.GetInventoryByLocationId(storeLoc); Console.WriteLine("Printing Inventory for location id " + storeLoc); foreach (var inv in inventory) { Console.WriteLine($"ProductId: {inv.ProductId} Amount in stock: {inv.AmountInStock} Product name: {productsRepository.GetProductByProductId(inv.ProductId).ProductName} Price {productsRepository.GetProductByProductId(inv.ProductId).Price}"); } Console.WriteLine("Place your order."); Console.WriteLine("input product id of the product you wish to buy."); input = Console.ReadLine(); int productId = Int32.Parse(input); Console.WriteLine("input amount of product you wish to buy"); input = Console.ReadLine(); int productAmount = Int32.Parse(input); decimal total = productAmount * productsRepository.GetProductByProductId(productId).Price; Console.WriteLine("Placing order..."); Order myOrder = new Order(); myOrder.OrderTime = DateTime.Now; myOrder.LocationId = storeLoc; myOrder.CustomerId = customerId; myOrder.OrderTotal = total; orderRepository.AddOrder(myOrder); orderRepository.Save(); Library.OrderItem myOrderItem = new Library.OrderItem(); myOrderItem.OrderId = orderRepository.GetLastOrderAdded(); myOrderItem.OrderItemNum = 1; myOrderItem.QuantityBought = productAmount; myOrderItem.ProductId = productId; myOrderItem.Price = productsRepository.GetProductByProductId(productId).Price; orderRepository.AddOrderItem(myOrderItem); orderRepository.Save(); Console.WriteLine("OrderPlaced"); } //Console.WriteLine("checking if input parsed"+input); } else { Console.WriteLine("Order will be placed from default location."); int storeLoc = customerRepository.GetCustomerById(customerId).DefaultStoreId; var inventory = locationRepository.GetInventoryByLocationId(storeLoc); Console.WriteLine("Printing Inventory for location id " + storeLoc); foreach (var inv in inventory) { Console.WriteLine($"ProductId: {inv.ProductId} Amount in stock: {inv.AmountInStock} Product name: {productsRepository.GetProductByProductId(inv.ProductId).ProductName} Price {productsRepository.GetProductByProductId(inv.ProductId).Price}"); } Console.WriteLine("Place your order."); Console.WriteLine("input product id of the product you wish to buy."); input = Console.ReadLine(); int productId = Int32.Parse(input); Console.WriteLine("input amount of product you wish to buy"); input = Console.ReadLine(); int productAmount = Int32.Parse(input); decimal total = productAmount * productsRepository.GetProductByProductId(productId).Price; Console.WriteLine("Placing order..."); Order myOrder = new Order(); myOrder.OrderTime = DateTime.Now; myOrder.LocationId = storeLoc; myOrder.CustomerId = customerId; myOrder.OrderTotal = total; orderRepository.AddOrder(myOrder); orderRepository.Save(); Library.OrderItem myOrderItem = new Library.OrderItem(); myOrderItem.OrderId = orderRepository.GetLastOrderAdded(); myOrderItem.OrderItemNum = 1; myOrderItem.QuantityBought = productAmount; myOrderItem.ProductId = productId; myOrderItem.Price = productsRepository.GetProductByProductId(productId).Price; orderRepository.AddOrderItem(myOrderItem); orderRepository.Save(); Console.WriteLine("OrderPlaced"); //order from default store } } else { Console.WriteLine("No matches"); } } if (input == "n") { do { Console.WriteLine("Enter first name:"); input = Console.ReadLine(); }while (input.Length == 0); string input2; do { Console.WriteLine("Enter last name: "); input2 = Console.ReadLine(); }while (input2.Length == 0); var customerList = customerRepository.GetCustomerByName(input, input2); bool flag = customerList.Any(); if (!flag) { Console.WriteLine("no matches"); } foreach (var c in customerList) { customerRepository.DisplayCustomer(c); } } if (input == "l") { bool flag = false; Console.WriteLine("Do you want to see all of the details for each order? input y for yes"); string deets = Console.ReadLine(); if (deets == "y") { flag = true; } Console.WriteLine("Displaying all stores."); locationRepository.DisplayLocations(); Console.WriteLine("Input a store id: "); input = Console.ReadLine(); int val = 0; if (Int32.TryParse(input, out val)) { Console.WriteLine("Showing all orders for location " + input); foreach (var x in locationRepository.GetOrderHistoryByLocation(Int32.Parse(input))) { if (flag) { orderRepository.DisplayOrderDetailsAll(x.OrderId); } else { orderRepository.DisplayOrderDetailsShort(x.OrderId); } } } else { Console.WriteLine("no matches"); } } if (input == "c") { bool flag = false; Console.WriteLine("Do you want to see all of the details for each order? input y for yes"); string deets = Console.ReadLine(); if (deets == "y") { flag = true; } Console.WriteLine("Displaying all customers."); customerRepository.DisplayCustomers(); Console.WriteLine("Input a customer id: "); input = Console.ReadLine(); int val = 0; if (Int32.TryParse(input, out val)) { Console.WriteLine("Showing all orders for customer " + input); foreach (var x in customerRepository.GetOrderHistoryByCustomer(Int32.Parse(input))) { if (!flag) { orderRepository.DisplayOrderDetailsShort(x.OrderId); } else { orderRepository.DisplayOrderDetailsAll(x.OrderId); } } } else { Console.WriteLine("no matches"); } } if (input == "a") { Console.WriteLine("Displaying all orders placed."); foreach (var o in orderRepository.GetOrders()) { Console.WriteLine("Orders" + "id: " + o.OrderId + " " + o.OrderTime + " Total: " + o.OrderTotal + " id: " + o.LocationId + o.CustomerId); } } if (input == "q") { break; } } }
public Order AddOrder(OrderDto ord) { Order order = orderRepository.AddOrder(ord); return(order); }
public ActionResult AddOrder(Order orderObject) { var newOrder = _orderRepository.AddOrder(orderObject.OrderStatus, orderObject.Total, orderObject.OrderDate, orderObject.PaymentTypeId, orderObject.UserId); return(Created($"api/createdOrder/{newOrder.Id}", newOrder)); }
public int Create(Order order) { return(orderRepository.AddOrder(order)); }
public bool AddOrder(string name, string price, string quantity) { return(_orderRepository.AddOrder(name, price, quantity)); }
public List<OrderDTO> ReserveRooms(List<int> roomIdsList, DateTime dateFrom, int daysCount = 1) { IRoomRepository roomsRepo = new RoomRepository(this._connStrBuilder.ConnectionString); IOrderRepository ordersRepo = new OrderRepository(this._connStrBuilder.ConnectionString); var rooms = new List<Room>(); var orders = new List<OrderDTO>(); if (roomIdsList != null) { rooms = roomsRepo.GetRoomsByIds(roomIdsList); foreach (var room in rooms) { if (room.roomStatus == (int)RoomStatus.Free) { string hash = this.GenHash(); DateTime startDate; if (dateFrom == null || dateFrom < DateTime.Today + TimeSpan.FromDays(1)) { startDate = DateTime.Today + TimeSpan.FromDays(1); } else { startDate = dateFrom; } ordersRepo.AddOrder( new Order() { roomId = room.id, orderToken = hash, reservationStart = startDate, reservationDays = daysCount }); orders.Add(new OrderDTO() { roomId = room.id, orderToken = hash, reservationStart = startDate, reservationDays = daysCount }); } } } return orders; }