static void Main(string[] args) { Order ord = new Order(); ord.product = "Vector Robots"; ord.amount = 500; Item itm = new Item(); ord.product = "Vector Robot"; itm.cost = 174.99; Console.WriteLine("=========CreateSeparateServices========="); OrderController sep = CreateSeparateServices(); sep.CreateOrder(ord); //save order to DB sep.DeleteOrder(ord); //delete order Console.WriteLine("=========CreateSingleService========="); OrderController sing = CreateSingleService(); sing.CreateOrder(ord); Console.WriteLine("=========GenericController<Order>========="); GenericController <Order> generic = CreateGenericServices(); generic.CreateEntity(ord); Console.WriteLine("=========GenericController<Item>========="); GenericController <Item> genericItem = CreateGenericItemServices(); genericItem.CreateEntity(itm); Console.WriteLine("Hit any key to quit"); Console.ReadKey(); }
static void Main(string[] args) { // Create an order object to use and add ToString method Order myOrder = new Order(); myOrder.id = Guid.NewGuid(); myOrder.product = "Zenbo"; myOrder.amount = 2; Console.WriteLine(myOrder.ToString()); Console.WriteLine("=========CreateSeparateServices========="); OrderController sep = CreateSeparateServices(); //Use the sep OrderController: CreateOrder(), DeleteOrder() // CreateOrder() methods: (1)Main(), (2)CreateSeparateServices, (3)OrderController() constructor, // (4)sep.CreateOrder(myOrder) in OrderController, (5)saver.Save(order) in Saver<TEntity> : ISave<TEntity> class, //(6) Save(TEntity entity) in class Save<TEntity> : ISave<TEntity> CrudImplementations sep.CreateOrder(myOrder); // DeleteOrder() methods: (1)Main(), (2)CreateSeparateServices, (3)OrderController() constructor, // (4)sep.DeleteOrder(myOrder) in OrderController, (5)deleter.Delete(order) in Deleter<TEntity> : IDelete<TEntity> class //(6) Delete(TEntity entity) in class Deleter<TEntity> : IDelete<TEntity> in CrudImplementations sep.DeleteOrder(myOrder); // Use the sing OrderController: Console.WriteLine("=========CreateSingleService========="); OrderController sing = CreateSingleService(); // sing.CreateOrder methods: (1) Main, (2) CreateSingleService in Program class (3) OrderController(crud, crud, crud) constructor in OrderController class // (4) CreateOrder(Order order) in OrderController Class, (5) saver.Save(order) in Crud<TEntity> : IRead<TEntity>, ISave<TEntity>, IDelete<TEntity> , // (6)Save(TEntity entity) in Crud<TEntity> : IRead<TEntity>, ISave<TEntity>, IDelete<TEntity> class sing.CreateOrder(myOrder); // sing.DeleteOrder methods: (1) Main, (2) CreateSingleService in Program class (3) OrderController(crud, crud, crud) constructor in OrderController class // (4) Delete(Order order) in OrderController Class, (5) deleter.Delete(order) in Crud<TEntity> : IRead<TEntity>, ISave<TEntity>, IDelete<TEntity> , // (6)Delete(TEntity entity) in Crud<TEntity> : IRead<TEntity>, ISave<TEntity>, IDelete<TEntity> class sing.DeleteOrder(myOrder); //Use the GenericController: CreateEntity() Console.WriteLine("=========GenericController<Order>========="); GenericController <Order> generic = CreateGenericServices(); // generic.CreateEntity methods: (1) Main, (2) CreateGenericServices() in program class, // (3) Activator.CreateInstance(typeof(GenericController<Order>), reader, saver, deleter) in GenericController<TEntity> Class, // (4) CreateEntity in GenericController<TEntity>, (5) saver.Save(entity) in GenericController<TEntity> // (6) Save(TEntity entity) in Saver<TEntity> : ISave<TEntity> class generic.CreateEntity(myOrder); ///////////////////////////////////// // Use the GenericController for Items: Item myItem = new Item(); myItem.itemId = Guid.NewGuid(); myItem.product = "Charging Cord"; myItem.cost = 50; // Code Modification: // Created a new CreateGenricServiceItem() method in the progam class, it is exactly like the // CreateGenericService() method used for objects except for the fact that any references to Order was changed to Item GenericController <Item> genericItem = CreateGenericServicesItem(); ItemController itemTest = CreateSingleServiceItem(); itemTest.CreateItem(myItem); itemTest.DeleteItem(myItem); Console.WriteLine("Hit any key to quit"); Console.ReadKey(); }