public static Entities.Product Map(Library.Product product) => new Entities.Product { ProductId = product.ProductId, ProductName = product.ProductName, InventoryId = product.InventoryId, Cost = Convert.ToDecimal(product.Cost), Inventory = product.Inventory.Select(Map).ToList() };
//Data object --> Entity public static Entities.Product MapProductWithEF(Library.Product OProduct) { return(new Entities.Product { Pid = OProduct.PID, Names = OProduct.Names, Model = OProduct.Model, Price = OProduct.Price }); }
public static void DisplayOptions(Repository repository) { while (true) { Console.WriteLine("You are now viewing the Product Management Menu."); Console.WriteLine(); Console.WriteLine("c: To Create A New Product"); Console.WriteLine("q: To Return Back to the Main Menu"); Console.WriteLine(); string userinput = Console.ReadLine().ToLower(); if (userinput == "c") { Console.WriteLine("Please Enter The Products Name\n"); string productname = Console.ReadLine(); decimal price; while (true) { Console.WriteLine("Please Enter The Products Price\n"); string pricestring = Console.ReadLine(); if (decimal.TryParse(pricestring, out price)) { break; } } try { Library.Product product = new Library.Product(productname, price); if (repository.AddProduct(product)) { Console.WriteLine("Successfully added Product"); Console.WriteLine("Remember to save to lock in changes."); } } catch (ArgumentException exception) { Console.WriteLine("Could not Create Product"); Console.WriteLine(exception.Message); } } else if (userinput == "q") { Console.WriteLine(); Console.WriteLine("Returning to Main Menu\n"); break; } } }
/*------------------------------------------------------*/ /* Product mapping */ public static Entities.Products MapProduct(Library.Product model) { Entities.Products result = new Entities.Products { ProductId = model.ID, Name = model.Name, Price = model.Price, ColorId = model.ColorID //ColorId = model.ColorID }; return(result); }
public void UpdateProduct(Library.Product product) { // get existing product var dbProduct = _context.Products.First(p => p.Name == product.Name); // update the entries except the name and id dbProduct.Description = product.Description; dbProduct.Price = product.Price; dbProduct.OrderLimit = product.OrderLimit; _context.Update(dbProduct); _context.SaveChanges(); }
public void Add(Library.Product product) { Product dbProduct = new Product() { Name = product.Name, Description = product.Description, Price = product.Price, OrderLimit = product.OrderLimit }; _context.Add(dbProduct); _context.SaveChanges(); }
public void AddProduct(Library.Product product) { using var context = new project0Context(_dbContext); var dbProduct = new Product() { Name = product.Name, Price = product.Price }; context.Add(dbProduct); context.SaveChanges(); }
public static Library.Product MapProduct(Entities.Products dbmodel) { Library.Product result = new Library.Product { ID = dbmodel.ProductId, Price = dbmodel.Price, Name = dbmodel.Name, ColorName = dbmodel.Color.Color, ColorID = dbmodel.ColorId ?? 0 //ColorID = dbmodel.ColorId ?? 0 }; return(result); }
public Library.Location GetWithInventory(int id) { var dbLocation = _context.Locations.Include(l => l.Inventories).ThenInclude(i => i.Product).FirstOrDefault(l => l.Id == id); // convert Inventories to Library model var inventory = new List <Library.Inventory>(); foreach (var item in dbLocation.Inventories) { var product = new Library.Product(item.Product.Name, item.Product.Id, item.Product.Price, item.Product.Description, item.Product.OrderLimit); inventory.Add(new Library.Inventory(product, item.Quantity)); } return(new Library.Location(dbLocation.Name, dbLocation.Id, inventory) ?? null); }
//public string AddressLine1 { get; set; } //public string AddressLine2 { get; set; } //public string City { get; set; } //public string State { get; set; } //public int ZipCode { get; set; } //public IEnumerable<string> productStrings { get; set; } //public string StoreName { get; set; } public string AddToOrder(Library.Product product) { string returnString = "Product successfully added to order."; // Low performance implementation, however for small orders // which they are all less than 13, it shouldn't be too bad int numberProductsInOrder = 0; foreach (var item in OrderDetail) { numberProductsInOrder += item.QtyOrdered; } this.TotalCost += product.UnitPrice; if (numberProductsInOrder <= 12) { if (TotalCost <= 500) { bool insert = true; foreach (var item in OrderDetail) { if (item.ProductID == product.ProductID) { insert = false; item.QtyOrdered++; } } if (insert == true) { OrderDetail.Add(new OrderDetail() { ProductID = product.ProductID, QtyOrdered = 1 }); } } else { this.TotalCost -= product.UnitPrice; returnString = "Total Cost of order exceeds $500. Cannot add product to order."; } } else { returnString = "Number of products in an order cannot exceed 12. Cannot add product to order."; } return(returnString); }
public void AddProduct(int storeId) { var product = new Library.Product(); string name; while (true) { Console.WriteLine(); Console.WriteLine("Please enter the product name:"); name = Console.ReadLine(); if (name.Equals("") || name.Equals(null)) { Console.WriteLine(); Console.WriteLine("Invalid Product Name..."); } else { product.Name = name; break; } } Console.WriteLine(); Console.WriteLine("Please enter the product price:"); float price; bool input = float.TryParse(Console.ReadLine(), out price); if (input) { product.Price = price; } _dbContext.Add(Mapping.MapI(product)); var newProduct = _dbContext.Iproduct.Last(); AddInventory(storeId, newProduct.Id); }
public void AddProduct(int orderId, Library.Product p) { if (!_dbContext.Oproduct.Any(s => s.Name == p.Name)) { var product = new Library.Product(); product.Name = p.Name; product.Price = (float)p.Price; _dbContext.Add(Mapping.MapO(product)); _dbContext.SaveChanges(); var newProduct = _dbContext.Oproduct.Last(); AddOrderItems(orderId, newProduct.Id); } else { AddOrderItems(orderId, _dbContext.Oproduct.First(s => s.Name == p.Name).Id); } }
public static Iproduct MapI(Library.Product product) => new Iproduct { Id = product.Id, Name = product.Name, Price = (decimal)product.Price };
public static Product Map(Library.Product product) => new Product { Id = product.Id, Name = product.Name, Cost = product.Cost };
public void AddProduct(Library.Product product) { _db.Add(Mapper.Map(product)); }
public void UpdateProduct(Library.Product product) { _db.Entry(_db.Product.Find(product.Id)).CurrentValues.SetValues(Mapper.Map(product)); }