public void AddT(Pizza pizza) { if (pizza is null) { //log it! throw new ArgumentNullException("Cannot add null pizza"); } else { if (GetTById(pizza.Id) != null) //if given pizza is already in db { throw new ArgumentOutOfRangeException("Pizza with given id already exists."); } else { try { Context.Pizza.Add(pizza); //add to local context Context.SaveChanges(); //run context.SaveChanges() to run the appropriate insert, adding it to db } catch (DbUpdateException) { //log it! throw; } } } }
public void AddT(Customer customer) { if (customer is null) { //log it! throw new ArgumentNullException("Cannot add null customer"); } else { if (GetTById(customer.Id) != null) //if given customer is already in db { throw new ArgumentOutOfRangeException("Customer with given id already exists."); } else { try { Context.Customer.Add(customer); //add to local context Context.SaveChanges(); //run context.SaveChanges() to run the appropriate insert, adding it to db } catch (DbUpdateException) { //log it! throw; } } } }
public void AddT(OrderItems obj) { if (obj is null) { //log it! throw new ArgumentNullException("Cannot add null OrderItems"); } else { if (GetTById(obj.Id) != null) //if given OrderItems is already in db { throw new ArgumentOutOfRangeException("OrderItems with given id already exists."); } else { try { Context.OrderItems.Add(obj); //add to local context Context.SaveChanges(); //run context.SaveChanges() to run the appropriate insert, adding it to db } catch (DbUpdateException) { //log it! throw; } } } }
public void AddT(PizzaIngredients PizzaIngredient) { if (PizzaIngredient is null) { //log it! throw new ArgumentNullException("Cannot add null PizzaIngredient"); } else { if (GetTById(PizzaIngredient.Id) != null) //if given PizzaIngredient is already in db { throw new ArgumentOutOfRangeException("PizzaIngredient with given id already exists."); } else { try { context.PizzaIngredients.Add(PizzaIngredient); //add to local context context.SaveChanges(); //run context.savechanges() to run the appropriate insert, adding it to db } catch (DbUpdateException) { //log it! throw; } } } }
/// <summary> /// Method to create an order in the db /// </summary> /// <param name="order">The order object with order info</param>\ /// <param name="total">The grand total of order</param> public void CreateOrder(BusinessLibrary.Order order, double total) { //create order Entity.Entities.Order o = new Entity.Entities.Order(); o.UserId = order.OrderCustomerId; o.StoreId = order.OrderStoreLocationId; o.OrderTime = DateTime.Now; o.OrderTotal = (decimal)total; //add and save _dbContext.Orders.Add(o); _dbContext.SaveChanges(); }
/// <summary> /// This method is use to add new product to stock of a given store location /// </summary> /// <param name="context"></param> public void AddNewProduct(project0Context context) { Inventory product = new Inventory(); //get the product name Console.WriteLine("Enter the product name"); product.Name = Console.ReadLine(); //get the product storeId Console.WriteLine("Enter the storeId "); string iD = Console.ReadLine(); if (!int.TryParse(iD, out int qty)) { // Parsing failed, handle the error however you like } product.Quantity = qty; //get the descrition of the product Console.WriteLine("Enter the product description"); product.Description = Console.ReadLine(); //get the product list price Console.WriteLine("Enter the price "); string pricestr = Console.ReadLine(); if (!int.TryParse(iD, out int price)) { // Parsing failed, handle the error however you like } product.ListPrice = price; context.Inventory.Add(product); context.SaveChanges(); }
public bool AddStoreInventory(Store store, Product product, int stock) { // set up context using var context = new project0Context(_dbContext); // make the new inventory Inventory inventory = new Inventory() { StoreId = store.Id, Stock = stock, ProductId = product.Id }; context.Inventories.Add(inventory); // ensure that the save works successfully try { context.SaveChanges(); } catch (DbUpdateException) { return(false); } return(true); }
public void AddOrder(Customer customer, Store location, ICollection <OrderItem> items) { // get the context of the db using var context = new project0Context(_dbContext); // create list converting from Library.Sale to DatabaseModel.Sale var dbItems = new List <OrderItem>(); decimal orderTotal = 0.0m; foreach (var item in items) { // need the product details var dbProduct = context.Products.First(p => p.Id == item.ProductId); var dbItem = new OrderItem() { ProductId = item.ProductId, ProductName = dbProduct.Name, Price = (decimal)dbProduct.Price, Quantity = item.Quantities, }; // add to the sum of the order total orderTotal += item.Quantity * item.Price; // add the sale to the running list dbItems.Add(dbItem); // remove the amount from the inventory of the store var locationInventory = context.Inventories.First(i => i.StoreId == location.Id && i.ProductId == item.ProductId); locationInventory.Stock -= item.Quantity; context.Inventories.Update(locationInventory); context.SaveChanges(); } // create the classes var order = new Order() { CustomerId = customer.Id, StoreId = location.Id, Date = DateTime.Now, OrderItem = dbItems }; // calculate total order.OrderTotal = orderTotal; context.Orders.Add(order); context.SaveChanges(); }
public void PlaceOrder(project0Context context) { List <Orderlist> orderlists = new List <Orderlist>(); int orderId = GetTheLastOrderId(context) + 1; Console.WriteLine("What is the customerId:"); string cs = Console.ReadLine(); int custId; if (!int.TryParse(cs, out custId)) { Console.WriteLine("We don't have you in our system"); } else { char stop = 'A'; do { orderlists.Add(AddProductToOrder(context, custId, orderId)); Console.WriteLine("Contnue shopping enter and letter or enter E to stop:"); string str = Console.ReadLine(); if (str != "") { stop = str[0]; } } while (stop != 'E'); } Orders order = new Orders() { UserId = custId, Total = sumTotal, OrderDate = DateTime.Now }; context.Add(order); context.SaveChanges(); context.Add(orderlists); context.SaveChanges(); /*foreach(Orderlist ol in orderlists) * { * context * }*/ }
public void DeleteCustomer(Customer customer) { using var context = new project0Context(_context); var dbCustomer = context.Customers .Where(i => i.CustomerId == customer.CustomerId) .FirstOrDefault(); context.Remove(dbCustomer); context.SaveChanges(); }
public void DeleteStore(Store store) { using var context = new project0Context(_context); var dbLocation = context.Stores .Where(i => i.StoreId == store.StoreId) .FirstOrDefault(); context.Remove(dbLocation); context.SaveChanges(); }
public void UpdateOrder(Order order) { using var context = new project0Context(_contextOptions); var dbOrder = context.Orders .Where(o => o.OrderId == order.OrderId) .FirstOrDefault(); dbOrder.OrderTotal = order.OrderTotalPrice; context.SaveChanges(); }
public void UpdateStore(Store store) { using var context = new project0Context(_context); var dbLocation = context.Stores .Where(i => i.StoreId == store.StoreId) .FirstOrDefault(); dbLocation.StoreName = store.StoreName; context.SaveChanges(); }
public void DeleteOrder(Order order) { using var context = new project0Context(_contextOptions); var dbOrder = context.Orders .Where(i => i.OrderId == order.OrderId) .FirstOrDefault(); context.Remove(dbOrder); context.SaveChanges(); }
public void UpdateProduct(Product product) { using var context = new project0Context(_contextOptions); var dbProduct = context.Products .Where(a => a.ProductId == product.ProductId) .FirstOrDefault(); dbProduct.ProductName = product.ProductName; dbProduct.Price = product.Price; context.SaveChanges(); }
public void CreateStore(Store location) { using var context = new project0Context(_context); var newEntry = new Models.Store() { StoreName = location.StoreName }; context.Stores.Add(newEntry); context.SaveChanges(); }
public void CreateOrder(Order order) { using var context = new project0Context(_contextOptions); var orderEntry = new Models.Order() { CustomerId = order.Customer.CustomerId, StoreId = order.Store.StoreId, Date = order.Date, OrderTotal = order.OrderTotalPrice }; context.Orders.Add(orderEntry); context.SaveChanges(); foreach (var orderItem in order.OrderItems) { orderItem.OrderId = orderEntry.OrderId; CreateOrderItem(orderItem); } context.SaveChanges(); }
public void UpdateOrderItem(OrderItem orderItem) { using var context = new project0Context(_contextOptions); var dbOrderItem = context.OrderItems .Where(o => o.ItemId == orderItem.ItemId) .FirstOrDefault(); dbOrderItem.Quantity = orderItem.Quantity; dbOrderItem.Total = orderItem.PurchasePrice; context.SaveChanges(); }
public void UpdateInventory(int storeId, string productName, int stock) { using var context = new project0Context(_context); var dbInventory = context.Inventories .Include(i => i.Product) .Where(i => i.StoreId == storeId && i.Product.ProductName == productName) .FirstOrDefault(); dbInventory.Stock = stock; context.SaveChanges(); }
public void UpdateOrderDetail(OrderDetail orderDetail) { using var context = new project0Context(_dbContext); var dbOrderDetail = context.OrderDetails .Where(o => o.OrderId == orderDetail.OrderId) .FirstOrDefault(); dbOrderDetail.Quantity = orderDetail.Quantity; context.SaveChanges(); }
/// <summary> /// Update an Inventory /// </summary> /// <returns>The Inventory with changed values</return> public void UpdateInventory(int locationId, int productId, int quantity) { using var context = new project0Context(_dbContext); var dbInventory = context.Inventories .Where(o => o.LocationId == locationId && o.ProductId == productId) .FirstOrDefault(); dbInventory.Quantity = quantity; context.SaveChanges(); }
public void CreateProduct(Product product) { using var context = new project0Context(_contextOptions); var newEntry = new Models.Product() { ProductName = product.ProductName, Price = product.Price }; context.Products.Add(newEntry); context.SaveChanges(); }
public void CreateCustomer(Customer customer) { using var context = new project0Context(_context); var newEntry = new Models.Customer() { FirstName = customer.FirstName, LastName = customer.LastName, }; context.Customers.Add(newEntry); context.SaveChanges(); }
public void AddProduct(Library.Product product) { using var context = new project0Context(_dbContext); var dbProduct = new Product() { Name = product.Name, Price = product.Price }; context.Add(dbProduct); context.SaveChanges(); }
/// <summary> /// Update an Inventory /// </summary> /// <returns>The Inventory with changed values</return> public DataModel.Inventory UpdateInventory(int locationId, int productId, int quantity) { using var context = new project0Context(_dbContext); var inventory = context.Inventories .Include(o => o.LocationId == locationId) .Include(o => o.ProductId == productId) .First(); inventory.Quantity -= quantity; context.SaveChanges(); return(inventory); }
/// <summary> /// Adds order to a particular customer /// </summary> /// <param name="order">Order Added</param> public void AddOrderByCustomerId(int customerId, int productId, int locationId, int quantity) { using var context = new project0Context(_dbContext); var dbOrders = new DataModel.Order() { CustomerId = customerId, ProductId = productId, LocationId = locationId, OrderQuantity = quantity, }; context.Add(dbOrders); context.SaveChanges(); }
public void AddOrderItem(Library.OrderDetail orderItem) { using var context = new project0Context(_dbContext); var dbItem = new OrderDetail() { OrderId = orderItem.OrderId, ProductId = orderItem.ProductId, Quantity = orderItem.Quantity }; context.Add(dbItem); context.SaveChanges(); }
public void CreateOrderItem(OrderItem orderItem) { using var context = new project0Context(_contextOptions); var orderItemEntry = new Models.OrderItem() { OrderId = orderItem.OrderId, ProductId = orderItem.Product.ProductId, Quantity = orderItem.Quantity, Total = orderItem.PurchasePrice }; context.OrderItems.Add(orderItemEntry); context.SaveChanges(); }
/// <summary> /// Adds a customer /// </summary> /// <param name="customer">Added customer</param> public void AddCustomer(Library.Customer customer) { using var context = new project0Context(_dbContext); var dbCustomer = new StoreApp.DataModel.Customer() { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email }; context.Add(dbCustomer); context.SaveChanges(); }
public void CreateInventory(Store store, Product product, int stock) { using var context = new project0Context(_context); var currentLocation = store; var currentProduct = product; var newEntry = new Models.Inventory() { StoreId = currentLocation.StoreId, ProductId = currentProduct.ProductId, Stock = stock }; context.Inventories.Add(newEntry); context.SaveChanges(); }