static AlertMapperInitialise()
        {
            // View to DTO
            Mapper.AddMap<AlertSettingsViewModel, AlertSettingsDto>(x =>
            {
                //var settings = new AlertSettingsDto
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new AlertRulesDto().InjectFrom(c)).Cast<AlertRulesDto>()
                //        .ToList()
                //};

                var settings = new AlertSettingsDto();
                settings.InjectFrom(x);
                foreach (var a in x.AlertRules)
                {
                    var newA = new AlertRulesDto();
                    newA.InjectFrom(a);
                    newA.AlertType = (AlertTypeDto)(int)a.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // DTO to Entity
            Mapper.AddMap<AlertSettingsDto, AlertSettings>(x =>
            {
                //var settings = new AlertSettings
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new DataAccessLayer.Models.Settings.AlertRules().InjectFrom(c)).Cast<DataAccessLayer.Models.Settings.AlertRules> ()
                //        .ToList()
                //};

                var settings = new AlertSettings { AlertRules = new List<DataAccessLayer.Models.Settings.AlertRules>()};
                settings.InjectFrom(x);
                foreach (var a in x.AlertRules)
                {
                    var newA = new DataAccessLayer.Models.Settings.AlertRules();
                    newA.InjectFrom(a);
                    newA.AlertType = (DataAccessLayer.Models.Settings.AlertType)(int)a.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // Entity to DTO
            Mapper.AddMap<AlertSettings, AlertSettingsDto>(x =>
            {
                var settings = new AlertSettingsDto { AlertRules = new List<AlertRulesDto>() };
                settings.InjectFrom(x);
                //foreach (var entityAr in x.AlertRules)
                //{
                //    settings.AlertRules.Add((AlertRulesDto)new AlertRulesDto().InjectFrom(entityAr));
                //}
                foreach (var entityAr in x.AlertRules)
                {
                    var newA = new AlertRulesDto();
                    newA.InjectFrom(entityAr);
                    newA.AlertType = (AlertTypeDto)(int)entityAr.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // DTO to View
            Mapper.AddMap<AlertSettingsDto, AlertSettingsViewModel>(x =>
            {
                //var settings = new AlertSettingsViewModel
                //{
                //    AlertRules = x.AlertRules
                //        .Select(c => new AlertRules().InjectFrom(c)).Cast<AlertRules>()
                //        .ToList()
                //};

                var settings = new AlertSettingsViewModel();
                settings.InjectFrom(x);
                foreach (var entityAr in x.AlertRules)
                {
                    var newA = new AlertRules();
                    newA.InjectFrom(entityAr);
                    newA.AlertType = (AlertType)(int)entityAr.AlertType;
                    settings.AlertRules.Add(newA);
                }

                return settings;
            });

            // View to DTO
            Mapper.AddMap<AlertRules, AlertRulesDto>(x =>
            {
                var dto = new AlertRulesDto();
                dto.InjectFrom(x);
                dto.AlertType = (AlertTypeDto)(int)x.AlertType;
                return dto;
            });

            // DTO to Entity
            Mapper.AddMap<AlertRulesDto, DataAccessLayer.Models.Settings.AlertRules>(x =>
            {
                var dto = new DataAccessLayer.Models.Settings.AlertRules();
                dto.InjectFrom(x);
                dto.AlertType = (DataAccessLayer.Models.Settings.AlertType)(int)x.AlertType;
                return dto;
            });

            // Entity to DTO
            Mapper.AddMap<DataAccessLayer.Models.Settings.AlertRules, AlertRulesDto>(x =>
            {
                var dto = new AlertRulesDto();
                dto.InjectFrom(x);
                dto.AlertType = (AlertTypeDto)(int)x.AlertType;
                return dto;
            });

            // DTO to View
            Mapper.AddMap<AlertRulesDto, AlertRules>(x =>
            {
                var dto = new AlertRules();
                dto.InjectFrom(x);
                dto.AlertType = (AlertType)(int)x.AlertType;
                return dto;
            });
        }
        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");
        }