Пример #1
0
        public override async Task HandleAsync(CallbackQueryUpdateMessage message)
        {
            if (!long.TryParse(Parameter, out long metricId))
            {
                throw new ArgumentException($"Can't perfom {Button} command, id parameter is not a number - {Parameter}");
            }

            var source = _sourceRepository.GetByExternalId(message.ChatId)
                         ?? throw new ArgumentException($"Can't perfom {Button} command, there is no source with id {message.ChatId}");

            var metric = _metricRepository.GetById(metricId)
                         ?? throw new ArgumentException($"Can't perfom {Button} command, there is no metric with id {metricId}");

            metric.SetDeleted();
            _metricRepository.Update(metric);

            if (metric.IsMain)
            {
                // after removed the main metric, set any other main
                var hasMainMain = _metricRepository.SetMainMetricIfHasNo(source.Id);
                source.UpdateState(hasMainMain ? StateType.HasMetric : StateType.NeedAddMetric);
                _sourceRepository.Update(source);
            }

            await _botClient.SendTextMessageAsync(message, MessageCode.Done);
        }
Пример #2
0
        public override async Task HandleAsync(CallbackQueryUpdateMessage message)
        {
            if (!long.TryParse(Parameter, out long id))
            {
                throw new ArgumentException($"Can't perfom {Button} command, id parameter is not a number - {Parameter}");
            }

            var newMainMetric = _metricRepository.GetById(id)
                                ?? throw new ArgumentException($"Can't perfom {Button} command, there is no metric with id {id}");

            var oldMainMetric = _metricRepository.GetMainByExternalId(message.ChatId);

            if (oldMainMetric != null && oldMainMetric.Id != newMainMetric.Id)
            {
                oldMainMetric.UpdateMain(false);
                _metricRepository.Update(oldMainMetric);

                newMainMetric.UpdateMain(true);
                _metricRepository.Update(newMainMetric);
            }

            await _botClient.SendTextMessageAsync(message, MessageCode.Done);
        }
Пример #3
0
        public Metric GetMetric(int id)
        {
            var metric = metricRepository.GetById(id);

            return(metric);
        }