public OrderBase AddOrder(OrderBase newItem) { ///// int newId = (orders.Count > 0) ? newId = orders.Max(id => id.Id) + 1 : 1; // Ensure that the new item's association property is value var associatedObject = producers.SingleOrDefault(i => i.Id == newItem.Id); if (associatedObject == null) { return(null); } var addedItem = new ProduceOrderModel { Id = newId, Produce = associatedObject }; addedItem.Price = newItem.Price; addedItem.Quantity += 1; orders.Add(addedItem); return(Mapper.Map <OrderBase>(addedItem)); }
public SurveyFull AddSurvey(SurveyAdd newItem) { // Calculate the next value for the identifier int newId = (surveys.Count > 0) ? newId = surveys.Max(id => id.Id) + 1 : 1; Survey addedItem = Mapper.Map <Survey>(newItem); addedItem.Id = newId; // Add the new item to the store surveys.Add(addedItem); // Return the new item return(Mapper.Map <SurveyFull>(addedItem)); }
//adding method public SurveyFull AddSurvey(SurveyAdd newItem) { //New id int newId = (surveys.Count > 0) ? newId = surveys.Max(id => id.Id) + 1 : 1; //new item w/ Mapper Survey addedItem; addedItem = Mapper.Map <Survey>(newItem); addedItem.Id = newId; //Add new item surveys.Add(addedItem); //return value return(Mapper.Map <SurveyFull>(addedItem)); }
public ProduceBase AddProduce(ProduceAdd newItem) { int newId = (producers.Count > 0) ? newId = producers.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Produce { Id = newId, Name = newItem.Name, Location = newItem.Location, Price = newItem.Price }; producers.Add(addedItem); return(Mapper.Map <ProduceBase>(addedItem)); }
// Add a new person public PersonFull AddPerson(PersonAdd newItem) { // Calculate the next value for the identifier int newId = (persons.Count > 0) ? newId = persons.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new PersonFull { Id = newId, FirstName = newItem.FirstName, LastName = newItem.LastName, Age = newItem.Age }; // Add the new item to the store persons.Add(addedItem); // Return the new item return(addedItem); }
//adding method public CarFull AddCar(CarAdd newItem) { //New id int newId = (cars.Count > 0) ? newId = cars.Max(id => id.Id) + 1 : 1; //new item var addedItem = new CarFull { Id = newId, Manufacturer = newItem.Manufacturer, Model = newItem.Model, MSRP = newItem.MSRP, Year = newItem.Year }; //Add new item cars.Add(addedItem); //return value return(addedItem); }
public VehicleBase AddVehicle(VehicleAdd newItem) { // Calculate the next value for the identifier int newId = (vehicles.Count > 0) ? newId = vehicles.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Vehicle { Id = newId, Model = newItem.Model, Trim = newItem.Trim, ModelYear = newItem.ModelYear, MSRP = newItem.MSRP }; // Add the new item to the store vehicles.Add(addedItem); // Return the new item return(Mapper.Map <VehicleBase>(addedItem)); }
public VehicleBase AddVehicle(VehicleAdd newItem) { // Calculate the next value for the identifier int newId = (vehicles.Count > 0) ? newId = vehicles.Max(id => id.Id) + 1 : 1; // Ensure that the new item's association property is value var associatedObject = manufacturers.SingleOrDefault(i => i.Id == newItem.ManufacturerId); if (associatedObject == null) { // Uh oh... return(null); } // Create a new item; notice the property mapping var addedItem = new Vehicle { Id = newId, Model = newItem.Model, Trim = newItem.Trim, ModelYear = newItem.ModelYear, MSRP = newItem.MSRP, // New... Manufacturer = associatedObject }; // Alternative... use AutoMapper to do the job... //addedItem = Mapper.Map<Vehicle>(newItem); //addedItem.Id = newId; //addedItem.Manufacturer = associatedObject; // Add the new item to the store vehicles.Add(addedItem); // Return the new item return(Mapper.Map <VehicleBase>(addedItem)); }
public ManufacturerBase AddManufacturer(ManufacturerAdd newItem) { // Calculate the next value for the identifier int newId = (manufacturers.Count > 0) ? newId = manufacturers.Max(id => id.Id) + 1 : 1; // Create a new item; notice the property mapping var addedItem = new Manufacturer { Id = newId, Name = newItem.Name, Country = newItem.Country, YearStarted = newItem.YearStarted }; // Alternative... use AutoMapper to do the job... addedItem = Mapper.Map <Manufacturer>(newItem); addedItem.Id = newId; // Add the new item to the store manufacturers.Add(addedItem); // Return the new item return(Mapper.Map <ManufacturerBase>(addedItem)); }