private int GetFreeIndex(Relay relay)
        {
            var relays = db.Relays.Where(x => x.DeviceID == relay.DeviceID).ToList<Relay>();

            for (int i = 0; i <= relays.Count(); i++)
            {
                if (!relays.Where(x => x.Index == i).Any())
                {
                    return i;
                }

            }

            return relays.Count()+1;
        }
 // GET: Relays/Create
 public ActionResult Create(Guid id)
 {         
     Relay relay = new Relay();         
     relay.DeviceID = id;
     return View(relay);
 }