public IActionResult OnPost(string Change, string Delete) { if (!string.IsNullOrEmpty(Change)) { if (ModelState.IsValid) { using (var db = new Model.DeviceChannels()) { var device = db.Devices.Single(b => b.DeviceName == SelectedDevice); device.SetChannel = SelectedChannel; db.SaveChanges(); } } return(RedirectToPage("Index")); } else if (!string.IsNullOrEmpty(Delete)) { if (string.IsNullOrEmpty(SelectedDevice)) { ModelState.AddModelError("SelectedDevice", "You must select a device."); return(Page()); } using (var db = new Model.DeviceChannels()) { var device = db.Devices.Where(d => d.DeviceName.Contains(SelectedDevice)); db.Devices.Remove(device.SingleOrDefault()); db.SaveChanges(); } return(RedirectToPage("Index")); } return(Page()); }
public string Add([FromBody] string Name) { using (var db = new Model.DeviceChannels()) { if (Name != null && Name != "") { db.Devices.Add(new Model.Device { DeviceName = Name, SetChannel = 0 }); db.SaveChanges(); } } return("processed"); }
public void OnGet() { using (var db = new Model.DeviceChannels()) { foreach (var device in db.Devices) { DeviceList.Add(new SelectListItem { Value = device.DeviceName, Text = device.DeviceName }); } foreach (var channel in db.Channels) { ChannelList.Add(new SelectListItem { Value = channel.ChannelID.ToString(), Text = channel.ChannelName }); } } }
public IActionResult OnPost() { if (ModelState.IsValid) { using (var db = new Model.DeviceChannels()) { db.Channels.Add(new Model.Channel { ChannelName = ChannelNameIn, Url = URLIn }); db.SaveChanges(); } return(RedirectToPage("Channels")); } else { return(Page()); } }
public ActionResult <string> TVChannel(string DeviceName) { try { using (var db = new Model.DeviceChannels()) { //DeviceJSON returnVals = new DeviceJSON(); var device = db.Devices.Where(d => d.DeviceName.Contains(DeviceName)); if (device.SingleOrDefault().SetChannel == 0) { return("Not Set"); } //old: int SelectChannel = device.SingleOrDefault().SetChannel; return(NameResolver.IDToURL(SelectChannel)); } } catch { return("NaN"); } }