public string CreateOrder(List <Product> productList, String cred) { using (var db = new SouthwindContext()) { var order = new Order() { CustomerId = cred, OrderDate = DateTime.Now, ShippedDate = DateTime.Now.AddDays(1), ShipCountry = "UK" }; // db.Orders.Add(order); //db.SaveChanges(); // int orderid = db.Orders.Last().OrderId; foreach (var product in productList) { var orderDetail = new OrderDetail() { ProductId = product.ProductID, Order = order, UnitPrice = Decimal.Parse(product.ProductPrice), Discount = 0, Quantity = 1 }; db.OrderDetails.Add(orderDetail); db.SaveChanges(); } return(GetReceipt(order)); } }
public static void DeleteOrder(int orderId) { using (var db = new SouthwindContext()) { var orderDetailsForThisOrder = from od in db.OrderDetails where od.OrderId == orderId select od; bool shipped = GetOrder(orderId).ShippedDate != null; foreach (var od in orderDetailsForThisOrder) { if (!shipped) { DecreaseProductStock(od.ProductId, -1 * od.Quantity); } DeleteOrderDetail(od.OrderDetailId); } } using (var db = new SouthwindContext()) { var orderToBeDeleted = db.Orders.Find(orderId); db.Orders.Remove(orderToBeDeleted); db.SaveChanges(); } }
public void DeleteCustomer(string customerID) { using (var db = new SouthwindContext()) { var selectedCustomer = db.Customers.Where(c => c.CustomerId == customerID); db.Customers.RemoveRange(selectedCustomer); db.SaveChanges(); } }
public static void DeleteProduct(int productId) { using (var db = new SouthwindContext()) { db.Products.Find(productId).Discontinued = true; db.SaveChanges(); } }
public static void DeleteOrderDetail(int orderDetailId) { using (var db = new SouthwindContext()) { db.OrderDetails.Remove(db.OrderDetails.Find(orderDetailId)); db.SaveChanges(); } }
public void RemoveCustomer(string customerId) { using (var db = new SouthwindContext()) { var selectedCustomer = from c in db.Customers where c.CustomerId == customerId select c; db.Customers.RemoveRange(selectedCustomer); db.SaveChanges(); } }
public static void UpdateOrder(int orderId, DateTime shippedDate, string shipCountry) { using (var db = new SouthwindContext()) { var order = db.Orders.Find(orderId); order.ShippedDate = shippedDate; order.ShipCountry = shipCountry; db.SaveChanges(); } }
public void CreateEmployee(string employeeID, string employeeName, string postalCode, string city = null) { var newEmployee = new Employee() { EmployeeId = employeeID, EmployeeName = employeeName, City = city, PostalCode = postalCode }; using (var db = new SouthwindContext()) { db.Employees.Add(newEmployee); db.SaveChanges(); } }
public void DeleteEmployee(string employeeID) { using (var db = new SouthwindContext()) { var selectedEmployee = from e in db.Employees where e.EmployeeId == employeeID select e; db.Employees.RemoveRange(selectedEmployee); db.SaveChanges(); } }
public void TearDown() { using (var db = new SouthwindContext()) { var selectedEmployees = from e in db.Employees where e.EmployeeId == "MANDA" select e; db.Employees.RemoveRange(selectedEmployees); db.SaveChanges(); } }
public void CreateCustomer(string customerID, string contactName, string city, string country, string postcode, string username, string password, char role) { var newCustomer = new Customer() { CustomerId = customerID, ContactName = contactName, City = city, Country = country, PostalCode = postcode, Username = username, Password = password, Role = role }; using (var db = new SouthwindContext()) { db.Customers.Add(newCustomer); db.SaveChanges(); } }
public void TearDown() { using (var db = new SouthwindContext()) { var selectedCustomers = from c in db.Customers where c.CustomerId == "BLACK" select c; db.Customers.RemoveRange(selectedCustomers); db.SaveChanges(); } }
public void UpdateCustomer(string customerID, string contactName, string city, string country, string postcode) { using (var db = new SouthwindContext()) { SelectedCustomer = db.Customers.Find(customerID); SelectedCustomer.ContactName = contactName; SelectedCustomer.City = city; SelectedCustomer.Country = country; SelectedCustomer.PostalCode = postcode; db.SaveChanges(); } }
public void CreateCustomer(string customerId, string contactName, string companyName, string city = null) { var newCust = new Customer() { CustomerId = customerId, ContactName = contactName }; using (var db = new SouthwindContext()) { db.Customers.Add(newCust); db.SaveChanges(); } }
public void Setup() { _customerManager = new CustomerManager(); using (var db = new SouthwindContext()) { var query = from c in db.Customers where c.CustomerId == "WILLC" select c; db.RemoveRange(query); db.SaveChanges(); } }
public void UpdateCustomer(string customerId, string contactName, string city, string postcode, string country) { using (var db = new SouthwindContext()) { SelectedCustomer = db.Customers.Where(c => c.CustomerId == customerId).FirstOrDefault(); SelectedCustomer.ContactName = contactName; SelectedCustomer.City = city; SelectedCustomer.PostalCode = postcode; SelectedCustomer.Country = country; // write changes to database db.SaveChanges(); } }
public void Setup() { _crudmanager = new CRUDManager(); using (var db = new SouthwindContext()) { var selectedCustomers = from c in db.Customers where c.CustomerId == "BLACK" select c; db.Customers.RemoveRange(selectedCustomers); db.SaveChanges(); } }
public static void UpdateCustomer(string customerId, string contactName, string city, string postalCode, string country) { using (var db = new SouthwindContext()) { var customer = db.Customers.Find(customerId); customer.ContactName = contactName; customer.City = city; customer.PostalCode = postalCode; customer.Country = country; db.SaveChanges(); } }
public static void UpdateProduct(int productId, string productName, double price, int stock, DateTime dateAdded) { using (var db = new SouthwindContext()) { var product = db.Products.Find(productId); product.ProductName = productName; product.Price = price; product.Stock = stock; product.DateAdded = dateAdded; db.SaveChanges(); } }
public static void DecreaseProductStock(int productId, int decreaseAmount) { using (var db = new SouthwindContext()) { var product = db.Products.Find(productId); if (decreaseAmount > product.Stock) { throw new Exception("Should not be able to decrease stock to less than 0"); } product.Stock -= decreaseAmount; db.SaveChanges(); } }
public void WhenAEmployeeIsRemoved_TheyAreNoLongerInTheDatabase() { using (var db = new SouthwindContext()) { var newEmployee = new Employee() { EmployeeId = "MANDA", EmployeeName = "Nish Mandal", PostalCode = "BRUM10", City = "Birmingham" }; db.Employees.Add(newEmployee); db.SaveChanges(); _employeeManager.DeleteEmployee("MANDA"); var MANDACount = db.Employees.Where(e => e.EmployeeId == "MANDA").Count(); Assert.AreEqual(0, MANDACount); } }
public void Setup() { _employeeManager = new EmployeeManager(); // remove test entry in DB if present using (var db = new SouthwindContext()) { var selectedEmployee = from e in db.Employees where e.EmployeeId == "MANDA" select e; db.Employees.RemoveRange(selectedEmployee); db.SaveChanges(); } }
public static void CreateNewOrder(string customerId, DateTime orderDate, string shipCountry, List <OrderDetail> orderDetails) { using (var db = new SouthwindContext()) { db.Add(new Order() { CustomerId = customerId, OrderDate = orderDate, ShipCountry = shipCountry, OrderDetails = orderDetails }); db.SaveChanges(); } }
public static void CreateNewProduct(string productName, double price, int stock = 0) { using (var db = new SouthwindContext()) { db.Add(new Product() { ProductName = productName, Price = price, Stock = stock, DateAdded = DateTime.Now, Discontinued = false }); db.SaveChanges(); } }
public static void CreateNewCustomer(string customerId, string contactName, string city, string postalCode, string country) { using (var db = new SouthwindContext()) { db.Add(new Customer() { CustomerId = customerId, ContactName = contactName, City = city, PostalCode = postalCode, Country = country }); db.SaveChanges(); } }
public static void DeleteCustomer(string customerId) { using (var db = new SouthwindContext()) { var ordersByThisCustomer = from o in db.Orders where o.CustomerId == customerId select o.OrderId; foreach (var o in ordersByThisCustomer) { DeleteOrder(o); } db.Customers.Remove(db.Customers.Find(customerId)); db.SaveChanges(); } }