Beispiel #1
0
        static void Main(string[] args)
        {
            Order order = new Order();

            order.id      = Guid.NewGuid();
            order.product = "Amazon Echo";
            order.amount  = 25;
            Console.WriteLine(order.ToString());

            Item item = new Item();

            item.itemId  = Guid.NewGuid();
            item.product = "Amazon Echo";
            item.cost    = 99.99;

            Console.WriteLine("=========CreateOrderSeparateServices=========");
            OrderController objectSep = CreateOrderSeparateServices();

            objectSep.CreateOrder(order);
            objectSep.DeleteOrder(order);

            Console.WriteLine("=========CreateOrderSingleService=========");
            OrderController objectSing = CreateOrderSingleService();

            objectSing.CreateOrder(order);
            objectSing.DeleteOrder(order);

            Console.WriteLine("=========CreateItemSeparateServices=========");
            ItemController itemSep = CreateItemSeparateServices();

            itemSep.CreateItem(item);
            itemSep.DeleteItem(item);

            Console.WriteLine("=========CreateItemSingleService=========");
            ItemController itemSing = CreateItemSingleService();

            itemSing.CreateItem(item);
            itemSing.DeleteItem(item);

            Console.WriteLine("=========GenericController<Order>=========");
            //Class acts as a factory to create a GenericController of the desired type
            GenericControllerCreation <Order> genericServiceCreation = new GenericControllerCreation <Order>();
            GenericController <Order>         generic = genericServiceCreation.CreateGenericTEntityServices();

            generic.CreateEntity(order);

            Console.WriteLine("=========GenericController<Item>=========");
            //Class acts as a factory to create a GenericController of the desired type
            GenericControllerCreation <Item> genericItemServiceCreation = new GenericControllerCreation <Item>();
            GenericController <Item>         genericItem = genericItemServiceCreation.CreateGenericTEntityServices();

            genericItem.CreateEntity(item);

            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Order orderObj = new Order();

            orderObj.id      = Guid.NewGuid();
            orderObj.product = "Nutcracker";
            orderObj.amount  = 4;

            Item itemObj = new Item();

            itemObj.product = "Ornament";
            itemObj.cost    = 10;

            Console.WriteLine("=========CreateSeparateServices=========");
            OrderController sep = CreateSeparateServices();

            sep.CreateOrder(orderObj);            // save order to database
            sep.DeleteOrder(orderObj);            // delete order from database

            Console.WriteLine("=========CreateSingleService=========");
            OrderController sing = CreateSingleService();

            sing.CreateOrder(orderObj);            // save order to database
            sing.DeleteOrder(orderObj);            // delete order from database

            Console.WriteLine("=========CreateSeparateItemServices=========");
            ItemController sepItm = CreateSeparateItemServices();

            sepItm.CreateItem(itemObj);            // save order to database
            sepItm.DeleteItem(itemObj);            // delete order from database

            Console.WriteLine("=========GenericController<Order>=========");
            // New "factory" type class to handle any type of entity
            GenericControllerServices <Order> genericServices = new GenericControllerServices <Order>();
            GenericController <Order>         genericOrder    = genericServices.CreateGenericTEntityServices();

            genericOrder.CreateEntity(orderObj);

            Console.WriteLine("=========GenericController<Item>=========");
            // New "factory" type class to handle any type of entity
            GenericControllerServices <Item> genericItemServices = new GenericControllerServices <Item>();
            GenericController <Item>         genericItem         = genericItemServices.CreateGenericTEntityServices();

            genericItem.CreateEntity(itemObj);

            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //Step One; creating a new order object and toString()
            Order ord = new Order();

            ord.product = "Vector Robot";
            ord.amount  = 20;
            Console.WriteLine(ord.ToString());

            //Step Two; creating a new item object and toString()
            Item item = new Item();

            item.product = "Vector Robot";
            item.cost    = 40;
            //Console.WriteLine(item.ToString());

            ItemController sep = CreateSeparateServices();

            sep.CreateItem(item);
            sep.DeleteItem(item);

            Console.WriteLine("=========CreateSeparateServices=========");
            OrderController sep = CreateSeparateServices();

            sep.CreateOrder(ord);
            sep.DeleteOrder(ord);

            Console.WriteLine("=========CreateSingleService=========");
            OrderController sing = CreateSingleService();

            sing.CreateOrder(ord);
            sing.DeleteOrder(ord);

            Console.WriteLine("=========GenericController<Order>=========");
            GenericController <Order> generic = CreateGenericServices();

            generic.CreateEntity(ord);

            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();
        }