Beispiel #1
0
        public async Task <int> CreateMonitorConfig(MonitorConfigViewModel vm)
        {
            _logger.LogInformation("CreateMonitorConfig called.");

            var entity = new MonitorConfig()
            {
                Name     = vm.Name,
                Interval = new TimeSpan(0, 0, vm.Interval),
                Url      = vm.Url
            };

            var result = await _asyncRepository.AddAsync(entity);

            _logger.LogInformation($"Entity created, id: {entity.Id}");

            return(result.Id);
        }
Beispiel #2
0
        public async Task EditMonitorConfig(MonitorConfigViewModel vm)
        {
            _logger.LogInformation("EditMonitorConfig called.");

            var entity = await _asyncRepository.GetByIdAsync(vm.Id);

            if (entity == null)
            {
                return;
            }

            entity.Name     = vm.Name;
            entity.Interval = new TimeSpan(0, 0, vm.Interval);
            entity.Url      = vm.Url;

            await _asyncRepository.UpdateAsync(entity);

            _logger.LogInformation($"Entity updated, id: {entity.Id}");
        }
Beispiel #3
0
        public async Task <MonitorConfigViewModel> GetMonitorConfig(int id)
        {
            _logger.LogInformation("CreateMonitorConfig called.");

            var vm = new MonitorConfigViewModel();

            var entity = await _asyncRepository.GetByIdAsync(id);

            if (entity == null)
            {
                return(null);
            }

            vm.Name     = entity.Name;
            vm.Url      = entity.Url;
            vm.Interval = (int)Math.Round(entity.Interval.TotalSeconds);
            vm.Id       = entity.Id;

            return(vm);
        }
        public async Task <IActionResult> Create(MonitorConfigViewModel vm)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(View(vm));
                }

                var id = await _monitorConfigService.CreateMonitorConfig(vm);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error at creating monitor config.");

                ModelState.AddModelError("", "An internal error occured.");
                return(View(vm));
            }
        }