public IActionResult OnGetDelete() { Firmware = _db.Firmware.Find(Id); if (Firmware == null) { throw new ApplicationException($"Unable to load firmware with ID '{Id}'."); } Application = _db.Applications.Find(Firmware.ApplicationId); if (Application == null) { throw new ApplicationException($"Unable to load application with ID '{Firmware.ApplicationId}'."); } if (_db.Devices.Any(x => x.CurrentFirmwareId == Id)) { throw new ApplicationException("Unable to delete active firmware"); } _db.Firmware.Remove(Firmware); _db.SaveChanges(); StatusMessage = "Firmware has been deleted"; return(RedirectToPage("/Applications/Details", new { id = Firmware.ApplicationId })); }
public void OnGet([FromServices] Database db) { Firmware = db.Firmware.Find(Id); if (Firmware == null) { throw new ApplicationException($"Unable to load firmware with ID '{Id}'."); } Application = db.Applications.Find(Firmware.ApplicationId); if (Application == null) { throw new ApplicationException($"Unable to load application with ID '{Firmware.ApplicationId}'."); } }
public IActionResult OnPost() { if (ModelState.IsValid) { var application = new EntityLayer.Models.Application { Name = Input.Name, DeviceTypeId = Input.DeviceTypeId.Value, Description = Input.Description, }; _db.Applications.Add(application); _db.SaveChanges(); StatusMessage = "New application has been created"; return(RedirectToPage("./Details", new { id = application.Id })); } return(Page()); }
public IActionResult OnGet() { Firmware = _db.Firmware.Find(Id); if (Firmware == null) { throw new ApplicationException($"Unable to load firmware with ID '{Id}'."); } Application = _db.Applications.Find(Firmware.ApplicationId); if (Application == null) { throw new ApplicationException($"Unable to load application with ID '{Firmware.ApplicationId}'."); } if (_db.Devices.Any(x => x.CurrentFirmwareId == Id)) { StatusMessage = "Firmware is active, and cannot be deleted"; return(RedirectToPage("/Applications/Details", new { id = Firmware.ApplicationId })); } return(Page()); }