public Model.Product AddNewProduct(Model.Product product)
        {
            Entity.Product prodToAdd = _context.Products.Add(_mapper.ParseProduct(product, true)).Entity;
            _context.SaveChanges();

            return(_mapper.ParseProduct(prodToAdd));
        }
Example #2
0
 public void UpdateLocationInventory(Models.Location location, Models.Product product, int delta)
 {
     Entities.Inventory i = ctx.Inventories.Where(i => i.LocationId == location.LocationID && i.ProductId == product.ProductID).ToList().FirstOrDefault();
     if (i == null)
     {
         i = new Entities.Inventory();
         if (location.LocationID != null)
         {
             i.LocationId = (int)location.LocationID;
         }
         if (product.ProductID != null)
         {
             i.ProductId = (int)product.ProductID;
         }
         i.Quantity = 0;
         ctx.Inventories.Add(i);
     }
     i.Quantity += delta;
     if (i.Quantity < 0)
     {
         throw new Exception("Tried to set inventory quantity to " + i.Quantity);
     }
     else if (i.Quantity == 0)
     {
         ctx.Inventories.Remove(i);
     }
     using var log = new LoggerConfiguration()
                     .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, shared: true)
                     .CreateLogger();
     log.Information("TRANSACTION: Updated inventory");
     ctx.SaveChanges();
 }
 public Entity.Product ParseProduct(Model.Product product, bool create)
 {
     if (product is null)
     {
         return(null);
     }
     if (create)
     {
         return(new Entity.Product
         {
             PName = product.Name,
             PDesc = product.Description,
             Price = product.Price,
             Category = product.Category
         });
     }
     else
     {
         return(new Entity.Product
         {
             Id = product.Id,
             PName = product.Name,
             PDesc = product.Description,
             Price = product.Price,
             Category = product.Category
         });
     }
 }
Example #4
0
        static void LocationSelectMenu(StoreModels.Product product)
        {
            userInterface.PrintText("Enter the number corresponding to the location you want to order from");
            userInterface.PrintText("Or press enter to return to the main menu");
            List <StoreModels.Location> locations = dataStore.GetAvailableLocations(product);

            for (int i = 0; i < locations.Count; i++)
            {
                userInterface.PrintText("[" + i + "] " + locations[i].LocationName + "\t(" + dataStore.GetLocationInventory(locations[i], product) + " in stock)");
            }
            if (locations.Count == 0)
            {
                userInterface.PrintText("There are no locations to show");
            }
            string input = userInterface.GetLine();

            Console.Clear();
            int index;

            if (!int.TryParse(input, out index))
            {
                return;
            }
            if (index < 0 || index >= locations.Count)
            {
                return;
            }
            cart.Location = locations[index];
        }
 public Models.Product ParseProduct(Entities.Product product)
 {
     Models.Product p = new Models.Product();
     p.ProductID   = product.ProductId;
     p.ProductName = product.ProductName;
     p.Price       = product.ProductPrice;
     return(p);
 }
Example #6
0
 public Entity.Product ParseProduct(Model.Product product)
 {
     return(new Entity.Product()
     {
         Location = (int)product.Id,
         ProductName = (int)product.ProductName,
         Price = product.Price,
         PieCount = product.PieCount,
     });
 }
 public Entity.Product ParseProduct(Model.Product product)
 {
     return(new Entity.Product
     {
         ProductName = product.ProductName,
         ProductDescription = product.ProductDescription,
         ProductID = product.ProductID,
         ProductPrice = (decimal)product.ProductPrice
     });
 }
Example #8
0
 public Model.Product GetProduct(Model.Product product)
 {
     Entity.Product found = _context.Products.FirstOrDefault(prod => prod.ItemName == product.ItemName && prod.Price == product.Price && prod.Description == product.Description);
     if (found == null)
     {
         return(null);
     }
     Log.Information("DL sent product to BL");
     return(new Model.Product(found.ProductId, found.ItemName, found.Price, found.Description));
 }
Example #9
0
 public Entity.Product ToEntity(Model.Product prod)
 {
     return(new Entity.Product
     {
         Id = prod.Id,
         PName = prod.Name,
         PDesc = prod.Description,
         Price = prod.Price
     });
 }
 public void GetProductByBarcode()
 {
     using (var context = new Entity.StoreAppDBContext(options))
     {
         IRepository   _repo  = new RepoDB(context);
         Model.Product result = _repo.GetProduct("j-g-t-s-01");
         Assert.NotNull(result);
         Assert.Equal(1, result.Id);
     }
 }
 public Entities.Product ParseProduct(Models.Product product)
 {
     Entities.Product p = new Entities.Product();
     if (product.ProductID != null)
     {
         p.ProductId = (int)product.ProductID;
     }
     p.ProductName  = product.ProductName;
     p.ProductPrice = product.Price;
     return(p);
 }
Example #12
0
 public Model.Product AddProduct(Model.Product product)
 {
     _context.Products.Add(
         new Entity.Product {
         ItemName    = product.ItemName,
         Price       = product.Price,
         Description = product.Description
     }
         );
     Log.Information("DL persisted product add to DB");
     _context.SaveChanges();
     return(product);
 }
Example #13
0
 public Model.LineItem AddLineItem(Model.LineItem lineItem, Model.Product product)
 {
     _context.LineItems.Add(
         new Entity.LineItem {
         ProductId = lineItem.ProductID,
         Quantity  = lineItem.Quantity,
         OrderId   = lineItem.OrderID
     }
         );
     Log.Information("DL persisted line item add to DB");
     _context.SaveChanges();
     return(lineItem);
 }
        public void UpdateInventoryByProductId()
        {
            using (var context = new Entity.StoreAppDBContext(options))
            {
                IRepository   _repo   = new RepoDB(context);
                Model.Product product = _repo.GetProductById(1);

                _repo.UpdateInventory(product, 10);
                var result = _repo.GetInventory(product);

                Assert.Equal("j-g-t-s-01", product.Barcode);
                Assert.Equal(10, result.Quantity);
            }
        }
Example #15
0
 public Entity.Product ParseProduct(Model.Product product)
 {
     if (product.ProductID == null)
     {
         return(new Entity.Product
         {
             ProductName = product.ProductName,
             ProductPrice = product.ProductPrice
         });
     }
     return(new Entity.Product
     {
         ProductName = product.ProductName,
         ProductPrice = product.ProductPrice,
         Id = (int)product.ProductID
     });
 }
 public Entity.Product ParseProduct(Model.Product product)
 {
     //when there are no products, NO id is set
     if (product.Id == 0)
     {
         return(new Entity.Product
         {
             Name = product.ProductName,
             Price = product.ProductPrice,
         });
     }
     //for updating and deleting
     return(new Entity.Product
     {
         Name = product.ProductName,
         Price = product.ProductPrice,
         Id = product.ProductID
     });
 }
Example #17
0
        public Entity.Product ParseProduct(Model.Product product)
        {
            if (product.Id == null)
            {
                return(new Entity.Product
                {
                    ProdName = product.ProdName,
                    ProdPrice = product.ProdPrice,
                    ProdCategory = (int)product.ProdCategory,
                    ProdBrandName = product.ProdBrandName,
                });
            }

            return(new Entity.Product
            {
                ProdName = product.ProdName,
                ProdPrice = product.ProdPrice,
                ProdCategory = (int)product.ProdCategory,
                ProdBrandName = product.ProdBrandName,
                Id = (int)product.Id
            });
        }
Example #18
0
 public Inventory UpdateInventory(Model.Inventory inventory, Model.Location location, Model.Product product)
 {
     Entity.Inventory updateInventory = _context.Inventories.Single(inven => inven.InventoryId == inventory.Id);
     updateInventory.Quantity = inventory.Quantity;
     _context.SaveChanges();
     Log.Information("DL persisted inventory update to DB");
     return(inventory);
 }
Example #19
0
 public Model.Inventory AddInventory(Model.Inventory inventory, Model.Location location, Model.Product product)
 {
     _context.Inventories.Add(
         new Entity.Inventory {
         InventoryId = inventory.Id,
         LocationId  = GetLocation(location).Id,
         ProductId   = GetProduct(product).Id,
         Quantity    = inventory.Quantity
     }
         );
     _context.SaveChanges();
     Log.Information("DL persisted inventory add to DB");
     return(inventory);
 }
Example #20
0
 public Model.Product ParseProduct(Entity.Product product)
 {
     Model.Product newProduct = new Model.Product(product.ProductName, decimal.ToDouble(product.Price), product.Description);
     newProduct.ProductID = product.ProductId;
     return(newProduct);
 }
Example #21
0
 public int GetLocationInventory(Models.Location location, Models.Product product)
 {
     return(ctx.Inventories.Where(i => i.LocationId == location.LocationID && i.ProductId == product.ProductID).Select(i => i.Quantity).ToList().FirstOrDefault());
 }
 public Model.Product AddProduct(Model.Product newProduct)
 {
     _context.Products.Add(_mapper.ParseProduct(newProduct));
     _context.SaveChanges();
     return(newProduct);
 }
Example #23
0
 public List <Models.Location> GetAvailableLocations(Models.Product product)
 {
     return(ctx.Inventories.Include(i => i.Location).Where(i => i.ProductId == product.ProductID).Select(i => mapper.ParseLocation(i.Location)).ToList());
 }