Esempio n. 1
0
        //#6
        static GenericController <Item> CreateGenericItemServices()
        {
            var reader  = new Reader <Item>();
            var saver   = new Saver <Item>();
            var deleter = new Deleter <Item>();

            //was not able to access
            void CreateItem(Item item)
            {
                saver.Save(item);
                Console.WriteLine("CreateOrder: Saving order of " + item.product);
            }

            //was not able to access
            void DeleteItem(Item item)
            {
                deleter.Delete(item);
                Console.WriteLine("DeleteOrder: Delete order of " + item.product);
            }

            // This must be declared using reflection...
            GenericController <Item> ctl = (GenericController <Item>)Activator.CreateInstance(typeof(GenericController <Item>), reader, saver, deleter);

            //This does not work
            //GenericController<Order> ctl = new GenericController(reader, saver, deleter);
            return(ctl);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Order order = new Order();

            order.product = "Vector Robot";
            order.amount  = 24;
            order.toString();


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

            sep.CreateOrder(order);



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

            sing.CreateOrder(order);


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

            generic.CreateEntity(order);



            Console.WriteLine("Hit any key to quit");
            sep.DeleteOrder(order);
            sing.DeleteOrder(order);
            generic.DeleteEntity(order);
            Console.ReadKey();
        }
        public GenericController <TEntity> CreateGenericTEntityServices()
        {
            var reader  = new Reader <TEntity>();
            var saver   = new Saver <TEntity>();
            var deleter = new Deleter <TEntity>();
            GenericController <TEntity> ctl = (GenericController <TEntity>)Activator.CreateInstance(typeof(GenericController <TEntity>), reader, saver, deleter);

            return(ctl);
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        static GenericController <Item> CreateGenericItemServices()
        {
            var reader  = new Reader <Item>();
            var saver   = new Saver <Item>();
            var deleter = new Deleter <Item>();
            // This must be declared using reflection...
            GenericController <Item> ctl = (GenericController <Item>)Activator.CreateInstance(typeof(GenericController <Item>), reader, saver, deleter);

            return(ctl);
        }
Esempio n. 6
0
        static GenericController <Order> CreateGenericServices()
        {
            var reader  = new Reader <Order>();
            var saver   = new Saver <Order>();
            var deleter = new Deleter <Order>();
            // This must be declared using reflection...
            GenericController <Order> ctl = (GenericController <Order>)Activator.CreateInstance(typeof(GenericController <Order>), reader, saver, deleter);

            //This does not work
            //GenericController<Order> ctl = new GenericController(reader, saver, deleter);
            return(ctl);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("=========CreateSeparateServices=========");
            OrderController sep = CreateSeparateServices();

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

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


            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
        }
Esempio n. 8
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();
        }
        static void Main(string[] args)
        {
            Guid  gid   = new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd");
            Order order = new Order();

            order.product = "Paper";
            order.id      = gid;
            order.amount  = 32;

            Console.WriteLine(order.toString());


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

            //#s 1 & 2 on corresponding Doc.
            sep.CreateOrder(order);
            sep.DeleteOrder(order);

            ItemController itmCon = CreateGenericServicesItem();



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

            //#s 3 & 4 on corresponding Doc.
            sing.CreateOrder(order);
            sing.DeleteOrder(order);

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


            //#5 on corresponding Doc.
            generic.CreateEntity(order);

            Item item = new Item();

            item.product = "Cup";
            item.cost    = .06;
            GenericController <Item> genItem = CreateGenericServicesItem();

            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Order ord  = new Order();
            var   guid = new Guid();
            Item  itm  = new Item();

            ord.product = "Vector Robot";
            ord.amount  = 1;
            ord.id      = guid;

            itm.product = "Vector Robot";
            itm.cost    = 1000;
            itm.itemId  = guid;



            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("=========GenericController<Item>=========");
            GenericController <Item> genericItm = CreateGenericItemServices();

            genericItm.CreateEntity(itm);


            Console.WriteLine("Hit any key to quit");
            Console.ReadKey();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Order ord = new Order();

            ord.product = "candy canes";
            ord.amount  = 100;

            Item itm = new Item();

            itm.product = "candy cane";
            itm.cost    = 1.99;

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

            sep.CreateOrder(ord);

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

            sing.CreateOrder(ord);

            Console.WriteLine("=========CreateSingleItemService=========");
            ItemController singItem = CreateSingleItemService();

            singItem.CreateOrder(itm);

            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();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("=========CreateSeparateServices=========");
            OrderController sep = CreateSeparateServices();

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

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

            //create order #1
            string name     = "tacos";
            Guid   id       = Guid.NewGuid();
            int    amount   = 12;
            Order  newOrder = new Order(name, amount, id);

            //#2
            sep.CreateOrder(newOrder);
            sep.DeleteOrder(newOrder);

            //#3
            sing.CreateOrder(newOrder);
            sing.DeleteOrder(newOrder);

            //#4
            generic.CreateEntity(newOrder);

            //#5
            Item item = new Item("chicken", 48);

            Console.WriteLine("=========GenericController<Item>=========");
            GenericController <Item> generic5 = CreateGenericServices1();

            //#6
            Console.WriteLine("=========GenericController<Item>=========");
            GenericController <Item> generic6 = CreateGenericItemServices();

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