Exemplo n.º 1
0
        /// <summary>
        /// Adds new product to the database
        /// </summary>
        /// <param name="products"></param>
        /// <returns></returns>
        public ServiceResponse <Products> CreateProduct(Products products)
        {
            try
            {
                _db.Products.Add(products);

                var newInventory = new ProductsInventory
                {
                    Products       = products,
                    QuantityOnHand = 0,
                    IdealQuantity  = 10
                };

                _db.ProductsInventories.Add(newInventory);
                _db.SaveChanges();

                return(new ServiceResponse <Products>
                {
                    Data = products,
                    Time = DateTime.UtcNow,
                    Message = "Saved new product",
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Products>
                {
                    Data = products,
                    Time = DateTime.UtcNow,
                    Message = ex.StackTrace,
                    IsSuccess = false
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Snapshot record using the provided ProductInventory instance
        /// </summary>
        /// <param name="inventory"></param>
        public void CreateSnapshot(ProductsInventory inventory)
        {
            var now      = DateTime.UtcNow;
            var snapshot = new ProductsInventorySnapshot
            {
                SnapshootTime  = now,
                Products       = inventory.Products,
                QuantityOnHand = inventory.QuantityOnHand
            };

            _db.Add(snapshot);
        }