// GET: Relays/Create
 public ActionResult Create(Guid id)
 {
     ViewData["deviceparentid"] = id;
     Relay relay = new Relay();
     relay.Id = Guid.NewGuid();
     relay.DeviceId = id;
     return View(relay);
 }
        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();
        }