Ejemplo n.º 1
0
        //
        // GET: /CleverHouse/
        public ActionResult Index()
        {
            IDictionary <int, Device> devicesDictionary;
            ICreate Create;

            if (Session["Devices"] == null)
            {
                devicesDictionary = new SortedDictionary <int, Device>();
                Create            = new CreateNew();


                devicesDictionary.Add(1, Create.NewFridge());
                devicesDictionary.Add(2, Create.NewHoover());
                devicesDictionary.Add(3, Create.NewBicycle());
                devicesDictionary.Add(4, Create.NewTV());
                devicesDictionary.Add(5, Create.NewGame());

                Session["Devices"] = devicesDictionary;
                Session["NextId"]  = 6;
            }
            else
            {
                devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];
            }

            SelectListItem[] devicesList = new SelectListItem[5];
            devicesList[0] = new SelectListItem {
                Text = "Fridge", Value = "FR", Selected = true
            };
            devicesList[1] = new SelectListItem {
                Text = "Hoover", Value = "HO"
            };
            devicesList[2] = new SelectListItem {
                Text = "Bicycle", Value = "BI"
            };
            devicesList[3] = new SelectListItem {
                Text = "Television", Value = "TV"
            };
            devicesList[4] = new SelectListItem {
                Text = "Warhammer", Value = "WH"
            };
            ViewBag.DevicesList = devicesList;
            ViewBag.Title       = "Smart House MVC";

            return(View(devicesDictionary));
        }
Ejemplo n.º 2
0
        public ActionResult Add(string deviceType)
        {
            Device  newDevice;
            ICreate Create = new CreateNew();

            switch (deviceType)
            {
            default:
                newDevice = Create.NewFridge();
                break;

            case "HO":
                newDevice = Create.NewHoover();
                break;

            case "BI":
                newDevice = Create.NewBicycle();
                break;

            case "TV":
                newDevice = Create.NewTV();
                break;

            case "WH":
                newDevice = Create.NewGame();
                break;
            }
            int id = (int)Session["NextID"];
            IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];

            devicesDictionary.Add(id, newDevice);
            Session["Devices"] = devicesDictionary;
            id++;
            Session["NextId"] = id;
            return(RedirectToAction("Index"));
        }