Example #1
0
        public async Task <IActionResult> Target(string id)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(id) || !Guid.TryParse(id, out _))
                {
                    return(RedirectToAction("index"));
                }

                var target = await _targetService.GetTargetAsync(id, User);

                var updateTargetBindingModel = new UpdateTargetBindingModel
                {
                    Id = target.Id,
                    MonitoringInterval = target.MonitoringInterval,
                    Name = target.Name,
                    Url  = target.Url
                };

                return(View(updateTargetBindingModel));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception occurred in Dashboard-Target GET action.");
                return(RedirectToAction("Exception", "Error"));
            }
        }
        /// <summary>
        /// Updates the Target of the user.
        /// </summary>
        public async Task UpdateAsync(UpdateTargetBindingModel model, ClaimsPrincipal user)
        {
            var userId = _userService.GetUserId(user);

            var targetDto = new TargetDto
            {
                Id = model.Id,
                MonitoringInterval = model.MonitoringInterval,
                Name = model.Name,
                Url  = model.Url
            };

            var jobId = await GetJobIdByTargetId(model.Id);

            _jobService.SaveHealtCheckJob(model.Url, jobId, model.MonitoringInterval, model.Id, userId, user.Identity.Name);
            _logger.LogInformation("JobId {jobId} updated by {userName}.", jobId, user.Identity.Name);

            await _targetUpdateRepository.UpdatePartially(targetDto);
        }
Example #3
0
        public async Task <IActionResult> Target(UpdateTargetBindingModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _targetService.UpdateAsync(model, User);

                    _logger.LogInformation("{userName} updated target {targetName}.", User.Identity.Name, model.Name);
                    return(RedirectToAction("index"));
                }

                return(View());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception occurred in Dashboard-Target POST action.");
                return(RedirectToAction("Exception", "Error"));
            }
        }