private void alertIfNeeded(RegisterFeedback feedback, Register register) { if (register is AnalogRegister) { var areg = (AnalogRegister)register; foreach (var alert in areg.Alerts) { checkAnalogAlert(alert, feedback, areg); } } else if (register is StatusRegister) { var statReg = (StatusRegister)register; var statusRegisterBits = statReg.StatusRegisterBits.Where(bit => bit.Enabled); foreach (var bit in statusRegisterBits) { foreach (var alert in bit.Alerts) { checkStatusAlert(alert, bit, statReg, feedback); } } } }
private bool registerIsUniqueOnDevice(Device dev, Register reg) { var regMatches = dev.Registers.Where(regi => regi.Id != reg.Id && regi.RegisterNumber == reg.RegisterNumber).FirstOrDefault(); if (regMatches != null) { return false; } else { return true; } }
private ActionResult updateRegister(Register reg) { if (!registerIsUniqueOnDevice(db.Devices.Find(reg.DeviceId), reg)) { return redirectToEdit(reg, NOT_UNIQUE); } db.Entry(db.Registers.Find(reg.Id)).CurrentValues.SetValues(reg); db.SaveChanges(); return RedirectToAction("Edit", "Device", new { id = reg.DeviceId }); }
private ActionResult redirectToEdit(Register reg, string message = "") { ViewBag.Message = message; if (reg is AnalogRegister) { return View("EditAnalog", reg); } else if (reg is StatusRegister) { return View("EditStatus", reg); } else { throw new Exception("Unknown Register Type"); } }