Exemple #1
0
        public async Task <Monitor> CreateAsync(
            Guid monitorId,
            Guid monitorStepId,
            Guid userId,
            [NotNull] string name,
            [NotNull] string url,
            int interval)
        {
            Check.NotNullOrWhiteSpace(name, nameof(name));
            Check.NotNullOrWhiteSpace(url, nameof(url));

            if (interval < 1)
            {
                throw new UserFriendlyException("Interval value cannot be less than one");
            }

            var isExistingMonitorName = _monitorRepository.Any(x => x.CreatorId == userId && x.Name.Equals(name));

            if (isExistingMonitorName)
            {
                throw new UserFriendlyException("This project name is already in use. Please choose a different name.");
            }

            var newMonitorStep = new MonitorStep(
                monitorStepId,
                monitorId,
                url,
                interval,
                MonitorStepTypes.Request,
                MonitorStepStatusTypes.Unknown);

            var newMonitor = new Monitor(
                monitorId,
                name,
                MonitorStatusTypes.Unknown,
                newMonitorStep);

            return(await _monitorRepository.InsertAsync(newMonitor));
        }