Exemplo n.º 1
0
        public ActionResult UpdateAlert(int id)
        {
            var settings = AlertSettingsService.GetSettings();
            var selected = settings.AlertRules.FirstOrDefault(x => x.Id == id);
            var vm       = new AlertRules();

            if (selected != null)
            {
                vm = Mapper.Map <AlertRules>(selected);
            }

            switch (vm.AlertType)
            {
            case AlertType.Cpu:
                return(PartialView("CpuAlertModal", vm));

            case AlertType.Network:
                vm = LoadNetwork(vm);
                return(PartialView("NetworkAlertModal", vm));

            case AlertType.Hdd:
                vm = LoadHdd(vm);
                return(PartialView("DriveAlertModal", vm));

            default:
                return(View("Error"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var settings = AlertSettingsService.GetSettings();
            var model    = Mapper.Map <AlertSettingsViewModel>(settings);

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult OpenEmailModal()
        {
            var settings = AlertSettingsService.GetSettings();
            var model    = Mapper.Map <AlertSettingsViewModel>(settings);

            return(PartialView("EmailSettingsModal", model));
        }
Exemplo n.º 4
0
        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"));
        }
Exemplo n.º 5
0
        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"));
        }
Exemplo n.º 6
0
        public ActionResult OpenModal(AlertType alertType)
        {
            var model = new AlertRules {
                AlertType = alertType
            };
            var settings = AlertSettingsService.GetSettings();

            switch (model.AlertType)
            {
            case AlertType.Cpu:
                if (settings.AlertRules.Any(x => x.AlertType == AlertTypeDto.Cpu))
                {
                    return(PartialView("AlertExistsModal", model.AlertType));
                }
                return(PartialView("CpuAlertModal", model));


            case AlertType.Network:
                model = LoadNetwork(model);
                return(PartialView("NetworkAlertModal", model));


            case AlertType.Hdd:
                if (settings.AlertRules.Any(x => x.AlertType == AlertTypeDto.Hdd))
                {
                    return(PartialView("AlertExistsModal", model.AlertType));
                }
                model = LoadHdd(model);
                return(PartialView("DriveAlertModal", model));


            default:
                Logger.Fatal("ArgumentOutOfRangeException on AlertType: {0}", model.AlertType);
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 7
0
        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"));
        }