Пример #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);
     }
 }
Пример #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)));
     }
 }
Пример #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());
     }
 }
Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #6
0
 public Database(string dbPath)
 {
     this.dbPath = dbPath ?? throw new ArgumentNullException(nameof(dbPath));
     context     = new CheckoutContext(dbPath);
 }