public ActionResult DeleteConfirmed(int id) { Models.Rule rule = db.Rules.Find(id); db.Rules.Remove(rule); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task<JsonResult> UpdateRule(Models.Rule rule) { try { var result = await _rulesCollection.UpdateOneAsync(r => r.Id == rule.Id, Builders<Models.Rule>.Update .Set(r => r.Machine, rule.Machine) .Set(r => r.Name, rule.Name) .Set(r => r.Period, rule.Period) .Set(r => r.Frequency, rule.Frequency) .Set(r => r.Severity, rule.Severity) .Set(r => r.Field, rule.Field) .Set(r => r.ConditionOperator, rule.ConditionOperator) .Set(r => r.Value, rule.Value) .Set(r => r.actions, rule.actions)); if (result.IsAcknowledged && result.ModifiedCount > 0) { if (_config.Grafana.Enabled) SendThreshold(); return Json(new { result = true }); } else return Json(new { result = false }); } catch (Exception e) { log.Error($"Error: {e.Message}"); return Json(new { result = false }); } }
public ActionResult Edit([Bind(Include = "Id,RuleString,ResponseString,Approved,RuleField,ResponseField,LastEditor")] Models.Rule rule) { if (ModelState.IsValid) { db.Entry(rule).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rule)); }
public ActionResult Edit([Bind(Include = "id,title")] Models.Rule rule) { if (ModelState.IsValid) { db.Entry(rule).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rule)); }
public ActionResult Approve(int id) { if (User.IsInRole("Approver")) { Models.Rule rule = db.Rules.Find(id); db.Entry(rule).Entity.Approved = true; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,RuleString,ResponseString,Approved,RuleField,ResponseField,LastEditor")] Models.Rule rule) { if (ModelState.IsValid) { db.Rules.Add(rule); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rule)); }
public ActionResult Create([Bind(Include = "id,title")] Models.Rule rule) { if (ModelState.IsValid) { db.Rules.Add(rule); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rule)); }
// GET: Rules/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Rule rule = db.Rules.Find(id); if (rule == null) { return(HttpNotFound()); } return(View(rule)); }
public ActionResult Edit([Bind(Include = "RuleID,name,active,created_at,modified_at")] Models.Rule rule) { if (ModelState.IsValid) { DateTime dataAtual = DateTime.Now; rule.active = "A"; rule.created_at = dataAtual; rule.modified_at = dataAtual; db.Entry(rule).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rule)); }
public AddAction(Models.Rule rule) { //Initialise InitializeComponent(); _rule = rule; //If Action already created, load the info. _action = rule.Action; //If Communicator already created, load the info. if (_action != null) { var controller = new CommunicatorController(); _comm = controller.GetAllCommunicators().FirstOrDefault(c => c.Id == rule.Action.CommunicatorId); } }
public async Task<JsonResult> InsertRule(Models.Rule rule) { try { //inserimento su database await _rulesCollection.InsertOneAsync(rule); if (_config.Grafana.Enabled) SendThreshold(); return Json(new { result = true }); } catch (Exception e) { log.Error($"Error: {e.Message}"); return Json(new { result = false }); } }
public ActionResult Pesquisar([Bind(Include = "name")] Models.Rule rule) { string pesquisa = rule.name; List <Models.Rule> lista; if (pesquisa.IsNullOrWhiteSpace()) { lista = db.Rules.ToList(); } else { lista = db.Rules .Where(w => w.name.ToUpper().Contains(pesquisa.ToUpper())) .ToList(); } return(View("Index", lista)); }
public static void UpdateRule(Models.Rule domainRule) { Console.WriteLine($"DOMAIN RULE: {domainRule}"); var firewallRule = Mapper.Map <FirewallAPI.Rule>(domainRule); Console.WriteLine($"Pre-FW RULE: {firewallRule}"); if (domainRule.LocalAddress == Models.Rule.ANY_IP_ADDRESS) { firewallRule.LocalAddress = FirewallAPI.Rule.ANY_IP_ADDRESS; } // TODO: See if we can just change the type in the domain model if (domainRule.LocalPort == Models.Rule.ANY_PORT) { firewallRule.LocalPort = FirewallAPI.Rule.ANY_PORT; } else { firewallRule.LocalPort = domainRule.LocalPort.Value; } if (domainRule.RemoteAddress == Models.Rule.ANY_IP_ADDRESS) { firewallRule.RemoteAddress = FirewallAPI.Rule.ANY_IP_ADDRESS; } if (domainRule.RemotePort == Models.Rule.ANY_PORT) { firewallRule.RemotePort = FirewallAPI.Rule.ANY_PORT; } else { firewallRule.RemotePort = domainRule.RemotePort.Value; } Console.WriteLine($"Post-FW rule: {firewallRule}"); FirewallAPI.FirewallManager.UpdateRule(firewallRule); }
public void GoToActionPage(Models.Rule rule = null) { add_tcInnerPages.SelectedTab = pActions; if (rule == null) return; //Create action for specific rule if rule was specified. _rule = rule; add_cbRule.Items.Add(rule); add_cbRule.SelectedIndex = 0; add_cbRule.Enabled = false; }
private void add_cbRule_SelectedIndexChanged(object sender, EventArgs e) { var devController = new DeviceController(); var commController = new CommunicatorController(); _rule = (Models.Rule)add_cbRule.SelectedItem; _rule.Device = devController.RetrieveDevice(_rule.DeviceId); _device = _rule.Device; //add_cbCommunicatorDestination.Items.AddRange(commController.GetAllCommunicators().Where(com=>com.Device.Id==_rule.DeviceId && com.Inbound==false).ToArray()); }
private void add_bSaveRule_Click(object sender, EventArgs e) { var contoller = new RuleController(); _rule = new Models.Rule() { Device = _device, Action = _action, Alarm = add_cAlarm.Checked, Constraint = add_tConstraint.Text, Name = add_tRuleName.Text, DeviceId = _device.Id, RuleType = (Models.RuleType)add_cbRuleType.SelectedItem, ValueType = (Models.ValueType)add_cbRuleCheckValue.SelectedItem }; contoller.CreateRule(_rule); contoller.UpdateRule(_rule); this.Close(); }
private void alarm_lbAlarms_SelectedIndexChanged(object sender, EventArgs e) { //Resetting the form. alarm_bRule.Enabled = false; alarm_bDevice.Enabled = false; alarm_tDateTime.Text = ""; alarm_rbTrue.Checked = false; alarm_rbFalse.Checked = false; alarm_tValue.Text = ""; alarm_tDevice.Text = ""; try { var selected = (Alarm) alarm_lbAlarms.SelectedItem; alarm_tDateTime.Text = selected.TimeStamp.ToString(); alarm_rbTrue.Checked = selected.Accepted; alarm_rbFalse.Checked = !selected.Accepted; //Get Value information. if (selected.ValueId > 0) { var controller = new ValueController(); _value = controller.GetValueById(selected.ValueId); selected.Value = _value; alarm_tValue.Text = selected.Value.StringValue; } //Get Rule information. if (selected.RuleId > 0) { var controller = new RuleController(); _rule = controller.RetrieveRuleById(selected.RuleId); alarm_bRule.Enabled = true; } //Get Device information. if (selected.DeviceId > 0) { var controller = new DeviceController(); _selectedDevice = controller.RetrieveDevice(selected.DeviceId); selected.Device = _selectedDevice; alarm_tDevice.Text = _selectedDevice.ToString(); alarm_bDevice.Enabled = true; } } catch { DebugOutput.Print("Attempted to load an alarm and failed..."); } }
private void modrules_bAddNewRule_Click(object sender, EventArgs e) { //Create and display the DataBoard form. var window = new DataBoard(_communicator, _selectedDevice); window.GoToRulePage(); window.ShowDialog(); //Get the Comm object created. _rule = window.GetRule(); //Return to Device list modrules_tBack.PerformClick(); }
private void add_bAddRule_Click(object sender, EventArgs e) { //Save the new Device. add_bSaveNewDevice.PerformClick(); //Create and display the DataBoard form. var window = new DataBoard(_communicator, _selectedDevice); window.GoToRulePage(); window.ShowDialog(); //Get the Comm object created. _rule = window.GetRule(); //Update the labels. UpdateStartLabels(); }
private void modify_bRules_Click(object sender, EventArgs e) { //Loads the relevant communicators. var controller = new RuleController(); modrules_lbRules.Items.Clear(); modrules_lbRules.Items.AddRange( controller.RetrieveRulesForDevice(_selectedDevice.Id).ToArray()); if (modrules_lbRules.Items.Count > 0) { //Select the first element modrules_lbRules.SelectedItem = modrules_lbRules.Items[0]; //Shows the modify tab. pTabPanel.SelectedTab = pModifyRules; } else { var msg = System.Windows.Forms.MessageBox.Show( "There are no Rules for this Device.", "No Rules Available", MessageBoxButtons.OK, MessageBoxIcon.Hand); // -------- Create new rule ---------- //Create and display the DataBoard form. var window = new DataBoard(null, _selectedDevice); window.GoToRulePage(); window.ShowDialog(); //Get the Comm object created. _rule = window.GetRule(); } }
private void modrules_lbRules_SelectedIndexChanged(object sender, EventArgs e) { var selected = (Models.Rule)modrules_lbRules.SelectedItem; //Set global accessible value for the Rule object. _rule = selected; //Fill in required data. modrules_Name.Text = selected.Name; modrules_tConstraint.Text = selected.Constraint; modrules_cAlarm.Checked = selected.Alarm; modrules_cbValueType.SelectedItem = selected.ValueType; modrules_cbRuleType.SelectedItem = selected.RuleType; }
private void modrules_tSave_Click(object sender, EventArgs e) { _rule.Alarm = modrules_cAlarm.Checked; _rule.Name = modrules_Name.Text; _rule.Constraint = modrules_tConstraint.Text; _rule.RuleType = (Models.RuleType) modrules_cbRuleType.SelectedItem; _rule.ValueType = (Models.ValueType) modrules_cbValueType.SelectedItem; var controller = new RuleController(); var updated = controller.UpdateRule(_rule); if (updated != null) { _rule = updated; DebugOutput.Print($"Rule '{updated}' was updated."); return; } DebugOutput.Print($"Could not updated {updated}!"); }