public ProductBase AddNewProduct(ProductAdd newItem) { // Attempt to fetch the supplier object // If that fails, return null // Otherwise, continue // Create a new design model object // Its properties come from the passed-in 'newItem' object // Remember to configure the Supplier property correctly // Add to the peristent store, and save changes // Prepare the return result // Return the result return(null); }
public ProductBase AddNewProduct(ProductAdd newItem) { // Calculate the next value for the identifier int newId = (ds.Products.Count() > 0) ? newId = ds.Products.Max(id => id.Id) + 1 : 1; var supplier = ds.Suppliers.Find(newItem.SupplierId); Mapper.CreateMap <ProductAdd, Product>(); // Create a new item; notice the property mapping var addedItem = new Product { Id = newId, Supplier = supplier //MSRP = newItem.MSRP, //Name = newItem.Name, //ProductId = newItem.ProductId, //Size = newItem.Size, //SupplierId = newItem.SupplierId, //UPC = newItem.UPC }; var addItem = new ProductBase { Id = addedItem.Id, SupplierName = supplier.Name, MSRP = newItem.MSRP, Name = newItem.Name, ProductId = newItem.ProductId, Size = newItem.Size, SupplierId = newItem.SupplierId, UPC = newItem.UPC }; // Add the new item to the store ds.Products.Add(addedItem); // Return the new item return(Mapper.Map <ProductBase>(addItem)); }