// Create a location /// <summary> /// Create a new location with a provided name. /// The location will have no inventory starting out. /// </summary> /// <param name="name">The name that will be given to Location</param> public void Create(string name) { Location newLoc = new Location { Name = name }; ctx.Locations.Add(newLoc); ctx.SaveChanges(); }
// * Handling data /// <summary> /// Add a new product to the database /// </summary> /// <param name="name">Product's name</param> /// <param name="catagory">Product's catagory</param> public void Create(string name, string catagory) { Product p = new Product { Name = name, CatagoryType = catagory }; ctx.Add(p); ctx.SaveChanges(); }
/// <summary> /// Add a new order to the database /// </summary> /// <param name="firstName">Order's first name</param> /// <param name="lastName">Order's last name</param> public Order Create(Customer _customer, string locationName, string productName, int quantitySold) { Customer customer = ctx.Customers.Find(_customer.CustomerId); Order order = new Order { Customer = customer, LocationName = locationName, ProductName = productName, QuantitySold = quantitySold }; ctx.Orders.Add(order); ctx.SaveChanges(); return(order); }
// * Handling data // Create a ProductInventory record // TODO: add docs public void Create(Location location, Product product, int quantity = 0) { // TODO throw exception on negative quantity ProductInventory pI = new ProductInventory { ProductLocation = location, Product = product, Quanitity = quantity, }; ctx.LocationInventory.Add(pI); ctx.SaveChanges(); }
/// <summary> /// Add a new customer to the database /// </summary> /// <param name="username">Customer's username</param> /// <param name="email">Customer's email</param> public void Create(Customer customer) { ctx.Customers.Add(customer); // ! Catch error if user couldnt be saved try { ctx.SaveChanges(); } catch (DbUpdateException e) { Console.WriteLine("An issue occured when trying to save a customer into the DB"); Console.WriteLine(e.InnerException.Message); } }
public void AddCustomerTest() { string customerFirstName = "John"; var options = new DbContextOptionsBuilder <VendorContext>() .UseInMemoryDatabase(databaseName: "TestDB") .Options; // Save something to imdb using (var ctx = new VendorContext(options)) { ctx.Customers.Add(new Customer { Username = customerFirstName, Email = "Doe" }); ctx.SaveChanges(); } using (var ctx = new VendorContext(options)) { CustomerService customerService = new CustomerService(ctx); var result = customerService.FindByUsername(customerFirstName); Assert.Equal(customerFirstName, result.Username); } }
public void SaveChanges() { _db.SaveChanges(); }
public int Insert(Vendor vendor) { _db.Vendor.Add(vendor); return(_db.SaveChanges()); }
public int?Add(Vendor entity) { _vendorContext.Vendors.Add(entity); _vendorContext.SaveChanges(); return(entity.ID); }