Beispiel #1
0
 /// <summary>
 /// Creates the specified entity.
 /// </summary>
 /// <param name="product">The product.</param>
 public void Insert(Product product)
 {
     using (var context = new CheckoutContext())
     {
         context.Products.Add(product);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Gets the by identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>
 /// Returns the entity by the id.
 /// </returns>
 public Product GetById(Guid id)
 {
     using (var context = new CheckoutContext())
     {
         return(context.Products.FirstOrDefault(x => x.Id.Equals(id)));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Gets all products.
 /// </summary>
 /// <returns>
 /// Returns all products.
 /// </returns>
 public List <Product> GetAllProducts()
 {
     using (var context = new CheckoutContext())
     {
         return(context.Products.ToList());
     }
 }
Beispiel #4
0
        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <param name="product">The product.</param>
        public void Delete(Product product)
        {
            var entity = GetProductBySkuCode(product.Sku);

            using (var context = new CheckoutContext())
            {
                context.Products.Remove(entity);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets the product by sku code.
        /// </summary>
        /// <param name="skuCode">The sku code.</param>
        /// <returns>
        /// Returns the product by the sku code.
        /// </returns>
        /// <exception cref="InvalidProductException"></exception>
        public Product GetProductBySkuCode(string skuCode)
        {
            using (var context = new CheckoutContext())
            {
                var product = context.Products.FirstOrDefault(p => p.Sku == skuCode);
                if (product == null)
                {
                    throw new InvalidProductException();
                }

                return(product);
            }
        }
Beispiel #6
0
 public Database(string dbPath)
 {
     this.dbPath = dbPath ?? throw new ArgumentNullException(nameof(dbPath));
     context     = new CheckoutContext(dbPath);
 }