示例#1
0
        /// <summary>
        /// delete a customer from the database
        /// </summary>
        /// <param name="customer">customer to be deleted</param>
        public void DeleteCustomer(Customer customer)
        {
            Log.Information("Removing customer {FirstName} {LastName}", customer.FirstName, customer.LastName);

            Customers entity = _context.Customers.Find(customer.Id);

            _context.Remove(entity);
        }
        /// <summary>
        /// delete a customer from the database
        /// </summary>
        /// <param name="customer">customer to be deleted</param>
        public void DeleteCustomerById(int id)
        {
            Customers entity = _context.Customers
                               .Include(o => o.Orders)
                               .ThenInclude(po => po.ProductOrdered)
                               .First(c => c.Id == id);

            Log.Information("Removing customer with Id: {id}", id);
            _context.Remove(entity);
        }
示例#3
0
        public void DeleteCigar(int cigarId)
        {
            _logger.LogInformation("Deleting cigar with ID {cigarId}", cigarId);
            Cigar entity = _dbContext.Cigar.Find(cigarId);

            _dbContext.Remove(entity);
        }
        /// <summary>
        /// Removes a whole product from inventory
        /// </summary>
        /// <remarks>
        /// Will remove the entire product, currently there is no way to remove a particular quantity yet
        /// </remarks>
        /// <param name="location">The location to remove from</param>
        /// <param name="productId">The product to remove</param>
        /// <returns>true is sucessful, false otherwise</returns>
        public bool RemoveLocationInventory(Location location, int productId)
        {
            // set up context
            using var context = new Project0Context(_dbContext);

            // nest in a try catch block to report error to user
            try
            {
                context.Remove(context.Inventories.First(i => i.LocationId == location.Id && i.ProductId == productId));
                context.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(false);
            }

            return(true);
        }