public ActionResult DeleteAlert(int id) { var settings = AlertSettingsService.GetSettings(); var settingToRemove = settings.AlertRules.FirstOrDefault(x => x.Id == id); settings.AlertRules.Remove(settingToRemove); var result = AlertSettingsService.SaveSettings(settings); if (result) { return(RedirectToAction("Index")); } return(View("Error")); }
public ActionResult UpdateEmailSettings(AlertSettingsViewModel model) { var currentRules = AlertSettingsService.GetSettings(); var dto = Mapper.Map <AlertSettingsDto>(model); dto.AlertRules = currentRules.AlertRules; var result = AlertSettingsService.SaveSettings(dto); if (result) { return(RedirectToAction("Index")); } Logger.Error("There has been an error trying to update the AlertSettingsViewModel"); return(View("Error")); }
public ActionResult UpdateAlert(AlertRules model) { if (!model.IsValid) { switch (model.AlertType) { case AlertType.Cpu: return(PartialView("CpuAlertModal", model)); case AlertType.Network: model = LoadNetwork(model); return(PartialView("NetworkAlertModal", model)); case AlertType.Hdd: model = LoadHdd(model); return(PartialView("DriveAlertModal", model)); default: Logger.Fatal("ArgumentOutOfRangeException on AlertType: {0}", model.AlertType); throw new ArgumentOutOfRangeException(); } } var currentSettings = AlertSettingsService.GetSettings(); var maxRecord = 1; if (currentSettings.AlertRules.Count > 0) { maxRecord = currentSettings.AlertRules.Max(x => x.Id); } var match = currentSettings.AlertRules.FirstOrDefault(x => x.Id == model.Id); if (match == null) { // We don't yet have any rules so create one var dtoRule = Mapper.Map <AlertRules, AlertRulesDto>(model); dtoRule.Id = ++maxRecord; currentSettings.AlertRules.Add(dtoRule); Logger.Trace("Saving new rule with id {0}", dtoRule.Id); var result = AlertSettingsService.SaveSettings(currentSettings); if (result) { return(Json(new { Result = "True" }, JsonRequestBehavior.AllowGet)); } } else { // We have rules already so let's modify the existing rules, remove the existing and add the new var dtoModel = new AlertRulesDto(); dtoModel = Mapper.Map <AlertRulesDto>(model); currentSettings.AlertRules.Remove(match); currentSettings.AlertRules.Add(dtoModel); var result = AlertSettingsService.SaveSettings(currentSettings); if (result) { return(Json(new { Result = "True" }, JsonRequestBehavior.AllowGet)); } } return(View("Error")); }