// GET: Store/Create
        public ActionResult Create()
        {
            var selectList = from region in db.region
                             select new { regionID = region.regionID, regionColor = region.colors.colorName };

            ViewBag.relay = new { regionID = new SelectList(selectList, "regionID", "regionColor") };
            RelayModel relayModel = new RelayModel();

            relayModel.checkboxRelayModel = GetCheckboxRelays(db.region.First().regionID);
            relayModel.checkboxStoreModel = GetCheckboxStores(db.region.First().regionID);
            return(View(relayModel));
        }
        public ActionResult Create(RelayModel relayModel)
        {
            if (!relayIPOkay(relayModel.relay))
            {
                ModelState.AddModelError("relay.relayIP", "IP already exists");
            }

            if (relayModel.checkboxRelayModel.Where(x => x.selected).Count() <= 0)
            {
                ModelState.AddModelError("", "Must select at least one relay connection");
            }
            if (relayModel.checkboxStoreModel.Where(x => x.selected).Count() <= 0)
            {
                if (relayModel.checkboxRelayModel.Where(x => x.selected).Count() <= 1)
                {
                    ModelState.AddModelError("", "Incorrect number of connections");
                }
            }
            if (ModelState.IsValid)
            {
                db.relay.Add(relayModel.relay);

                db.SaveChanges();

                var selectedRelays = relayModel.checkboxRelayModel.Where(x => x.selected);
                foreach (var selectedRelay in selectedRelays)
                {
                    connections connection = new connections()
                    {
                        relayID     = relayModel.relay.relayID,
                        destRelayID = selectedRelay.relayID,
                        isActive    = true,
                        weight      = selectedRelay.weight
                    };

                    db.connections.Add(connection);
                }

                var selectedStores = relayModel.checkboxStoreModel.Where(x => x.selected);
                foreach (var selectedStore in selectedStores)
                {
                    connections connection2 = new connections()
                    {
                        storeID     = selectedStore.storeID,
                        destRelayID = relayModel.relay.relayID,
                        isActive    = true,
                        weight      = selectedStore.weight
                    };

                    db.connections.Add(connection2);
                }

                db.SaveChanges();

                return(RedirectToAction("Index", "Relay"));
            }


            //relayModel.checkboxRelayModel = GetCheckboxRelays(relayModel.relay.regionID);
            //relayModel.checkboxStoreModel = GetCheckboxStores(relayModel.relay.regionID);

            var selectList = from region in db.region
                             select new { regionID = region.regionID, regionColor = region.colors.colorName };


            ViewBag.relay = new { regionID = new SelectList(selectList, "regionID", "regionColor") };

            return(View(relayModel));
        }