/// <summary>
        /// Adds a new product to the database
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public ServiceResponse <Product> CreateProduct(Product product)
        {
            try
            {
                _solarDb.Add(product);
                var newInvertory = new ProductInventory
                {
                    Product        = product,
                    QuantityOnHand = 0,
                    IdealQuantity  = 10
                };

                _solarDb.Add(newInvertory);
                _solarDb.SaveChanges();

                return(new ServiceResponse <Product>
                {
                    Data = product,
                    Time = DateTime.UtcNow,
                    IsSuccess = true,
                    Message = "Saved new product"
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Product>
                {
                    Data = product,
                    Time = DateTime.UtcNow,
                    IsSuccess = false,
                    Message = ex.StackTrace
                });
            }
        }
 /// <summary>
 /// Add Customer record
 /// </summary>
 /// <param name="customer"></param>
 /// <returns>ServiceResponse<Customer></returns>
 public ServiceResponse <Customer> CreateCustomer(Customer customer)
 {
     try
     {
         db.Add(customer);
         var response = db.SaveChanges();
         if (response >= 1)
         {
             return(new ServiceResponse <Customer>
             {
                 IsSuccess = true,
                 Message = "New Customer Added",
                 Time = DateTime.UtcNow,
                 Data = customer
             });
         }
         return(new ServiceResponse <Customer>
         {
             IsSuccess = false,
             Message = "Customer not Added",
             Time = DateTime.UtcNow,
             Data = customer
         });
     }
     catch (Exception ex)
     {
         return(new ServiceResponse <Customer>
         {
             IsSuccess = false,
             Message = ex.StackTrace,
             Time = DateTime.UtcNow,
             Data = null
         });
     }
 }
        /// <summary>
        /// Creates a Snapshot record using the provided ProductInventory instance
        /// </summary>
        /// <param name="inventory"></param>
        //private void CreateSnapshot(ProductInventory inventory) // OLD VERSION
        private void CreateSnapshot()
        {
            var now = DateTime.UtcNow;

            /* OLD VERSION
             * var snapshot = new ProductInventorySnapshot
             * {
             *  Product = inventory.Product,
             *  QuantityOnHand = inventory.QuantityOnHand,
             *  SnapshotTime = now
             * };
             *
             * // Entity framework will infer type of 'snapshot' & its respective table
             * _db.Add(snapshot);
             */

            // NEW VERSION
            var inventories = _db.ProductInventories
                              .Include(inv => inv.Product)
                              .ToList();

            foreach (var inventory in inventories)
            {
                var snapshot = new ProductInventorySnapshot
                {
                    SnapshotTime   = now,
                    Product        = inventory.Product,
                    QuantityOnHand = inventory.QuantityOnHand
                };

                _db.Add(snapshot);
            }
        }
示例#4
0
        //Creates an open SalesOrder
        public ServiceResponse <bool> GenerateOpenOrder(SalesOrder order)
        {
            var now = DateTime.UtcNow;

            _logger.LogInformation("Generating new order");
            foreach (var item in order.SalesOrderItems)
            {
                item.Product = _productService.GetProductById(item.Product.Id);
                var inventoryId = _inventoryService.GetByProductId(item.Product.Id).Id;
                _inventoryService.UpdateUnitsAvailable(inventoryId, -item.Quantity);
            }
            try{
                _db.Add(order);
                _db.SaveChanges();
                return(new ServiceResponse <bool> {
                    IsSuccess = true,
                    Data = true,
                    Time = now,
                    Message = "Open Order Created"
                });
            }
            catch (Exception e) {
                return(new ServiceResponse <bool> {
                    IsSuccess = false,
                    Data = false,
                    Time = now,
                    Message = e.StackTrace
                });
            }
        }
示例#5
0
        private void CreateSnpashot(data.models.ProductInventory inventory)
        {
            data.models.ProductInventorySnapshot snapshot = new data.models.ProductInventorySnapshot {
                SnapshotTime   = DateTime.UtcNow,
                Product        = inventory.Product,
                quantityOnHand = inventory.quantityOnHand
            };

            _db.Add(snapshot);
        }
示例#6
0
        private void CreateSnapShot(ProductInventory inventory)
        {
            var snapshot = new ProductInventorySnapshot {
                SnapshotTime   = DateTime.UtcNow,
                Product        = inventory.Product,
                QuantityOnHand = inventory.QuantityOnHand
            };

            _db.Add(snapshot);
            //_db.SaveChanges();
        }
示例#7
0
        private void CreateSnapshot(ProductInventory inventory)
        {
            var snapshot = new ProductInventorySnapshot
            {
                SnapshotTime   = DateTime.UtcNow,
                Product        = inventory.Product,
                QuantityOnHand = inventory.QuantityOnHand
            };

            _solarDbContext.Add(snapshot);
        }
        private void CreateSnapshot(ProductInventory inventory)
        {
            var snapshot = new ProductInventorySnapshot
            {
                SnapshotTime   = now,
                Product        = inventory.Product,
                QuantityOnHand = inventory.QuantityOnHand
            };

            db.Add(snapshot);
        }
示例#9
0
        private void CreateSnapshot(ProductInventory inventory)
        {
            var snapshot = new ProductInventorySnapshot
            {
                SnapshotTime   = DateTime.UtcNow,
                QuantityOnHand = inventory.QuantityOnHand,
                Product        = inventory.Product
            };

            _db.Add(snapshot);
        }
示例#10
0
        public void CreateSnapshot(ProductInventory inventory)
        {
            var snapshot = new ProductInventorySnapshot {
                SnapshotTime   = DateTime.UtcNow,
                Product        = inventory.Product,
                QuantityOnHand = inventory.QuantityOnHand
            };

            // z automatu doda do dobrej tabeli poniewaz zna typ
            _db.Add(snapshot);
            _db.SaveChanges(); // komentarz
        }
示例#11
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);
        }
示例#12
0
        private void CreateSnapshot(ProductInventory inventory)
        {
            var now = DateTime.UtcNow;

            var snapshot = new ProductInventorySnapshot
            {
                SnapshotTime   = now,
                Product        = inventory.Product,
                QuantityOnHand = inventory.QuantityOnHand,
            };

            context.Add(snapshot);
            context.SaveChanges();
        }
示例#13
0
        //Create a snapshot record using the provided ProductIventory instance
        private void CreateSnapshot()
        {
            var now         = DateTime.UtcNow;
            var inventories = _db.ProductInventorys
                              .Include(inv => inv.Product).ToList();

            foreach (var inventory in inventories)
            {
                var snapshot = new ProductInventorySnapshot {
                    SnapshotTime   = now,
                    Product        = inventory.Product,
                    QuantityOnHand = inventory.QuantityOnHand
                };
                _db.Add(snapshot);
            }
        }
示例#14
0
 //Add a new customer
 public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer)
 {
     try{
         _db.Add(customer);
         _db.SaveChanges();
         return(new ServiceResponse <Data.Models.Customer> {
             IsSuccess = true,
             Message = "New Customer Add",
             Time = DateTime.UtcNow,
             Data = customer
         });
     }catch (Exception e) {
         return(new ServiceResponse <Data.Models.Customer> {
             IsSuccess = false,
             Message = e.StackTrace,
             Time = DateTime.UtcNow,
             Data = customer
         });
     }
 }
示例#15
0
        /// <summary>
        /// Creates a Snapshot record using the provided ProductInventory instance
        /// </summary>
        /// <param name="inventory"></param>
        private void CreateSnapshot()
        {
            var now = DateTime.UtcNow;

            var inventories = _db.ProductInventories
                              .Include(inv => inv.Product).ToList();

            foreach (var inventory in inventories)
            {
                var snapshot = new ProductInventorySnapshot
                {
                    SnapshotTime   = now,
                    Product        = inventory.Product,
                    QuantityOnHand = inventory.QuantityOnHand
                };
                _db.Add(snapshot);
            }


            // don't need to save changes because CreateSnapshot is follewed by _db.SaveChanges
        }