protected void Page_Load(object sender, EventArgs e) { // Check if we are already logged in. (see the redirect below) if (HttpContext.Current.User.Identity.IsAuthenticated) { // Get the user that is logged in. var user = Sprocs.GetUserByAspId(Membership.GetUser().ProviderUserKey.ToString()); var devices = new List <object>(); var getUnregistered = (Request["unreg"] != null); foreach (var device in user.Devices) { // See if we're only asking for unregistured devices. If so, skip ones with a serial. if (getUnregistered && !String.IsNullOrEmpty(device.Serial)) { continue; } devices.Add(new { name = device.Name, id = device.UID, owner = Sprocs.GetDeviceOwner(device.Owner), serial = device.Serial }); } if (devices.Count > 0) { Utils.JsonResponse(Response, true, devices); } else { Utils.JsonResponse(Response, false, new { error = getUnregistered ? "NO_UNREGISTERED_DEVICES" : "NO_DEVICES" }); } return; } else { Utils.JsonResponse(Response, false, new { error = "NOT_LOGGED_IN" }); } }
/* * protected void EditIdButton_Click(object sender, EventArgs e) * { * DeviceIdTextBox.Enabled = true; * EditIdButton.Visible = false; * } */ protected void SaveButton_Click(object sender, EventArgs e) { int userID = 0; Int32.TryParse(UserDropDown.SelectedValue, out userID); var device = new Device(); device.Name = DeviceNameTextBox.Text; //device.Serial = SerialNumberTextBox.Text; device.UID = DeviceIdTextBox.Text; device.Owner = Sprocs.GetDeviceOwner(OwnerDropDown.SelectedValue); device.User = Sprocs.GetUserById(userID); Sprocs.CreateDevice(device); Response.Redirect("/"); }