public async Task <OperationDataResult <MonitoringBaseSettings> > GetSettings()
        {
            try
            {
                var option = _options.Value;

                if (option?.SdkConnectionString == "...")
                {
                    var connectionString = _dbContext.Database.GetDbConnection().ConnectionString;

                    var dbNameSection = Regex.Match(connectionString, @"(Database=(...)_eform-angular-\w*-plugin;)").Groups[0].Value;
                    var dbPrefix      = Regex.Match(connectionString, @"Database=(\d*)_").Groups[1].Value;
                    var sdk           = $"Database={dbPrefix}_SDK;";
                    connectionString = connectionString.Replace(dbNameSection, sdk);
                    await _options.UpdateDb(settings => { settings.SdkConnectionString = connectionString; }, _dbContext, UserId);
                }

                return(new OperationDataResult <MonitoringBaseSettings>(true, option));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <MonitoringBaseSettings>(false,
                                                                        _monitoringLocalizationService.GetString("ErrorWhileObtainingMonitoringSettings")));
            }
        }
コード例 #2
0
        public async Task <OperationResult> DeleteRule(int id)
        {
            using (var transaction = await _dbContext.Database.BeginTransactionAsync())
            {
                try
                {
                    var notificationRule = await _dbContext.Rules
                                           .FirstOrDefaultAsync(x => x.Id == id);

                    if (notificationRule == null)
                    {
                        return(new OperationResult(
                                   false,
                                   _localizationService.GetString("NotificationRuleNotFound")));
                    }

                    var recipients = await _dbContext.Recipients
                                     .Where(x => x.NotificationRuleId == notificationRule.Id)
                                     .ToListAsync();

                    foreach (var recipient in recipients)
                    {
                        await recipient.Delete(_dbContext);
                    }

                    await notificationRule.Delete(_dbContext);

                    transaction.Commit();
                    return(new OperationResult(
                               true,
                               _localizationService.GetString("NotificationRuleDeletedSuccessfully")));
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    _logger.LogError(e.Message);
                    return(new OperationResult(false, _localizationService.GetString("ErrorWhileRemovingNotificationRule")));
                }
            }
        }
コード例 #3
0
        public async Task <OperationDataResult <NotificationRulesListModel> > Index(NotificationListRequestModel requestModel)
        {
            var core = await _coreHelper.GetCore();

            await using MicrotingDbContext dbContext = core.DbContextHelper.GetDbContext();
            List <KeyValuePair <int, string> > eForms = new List <KeyValuePair <int, string> >();

            try
            {
                var rules = await _dbContext.Rules
                            .AsNoTracking()
                            .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                            .Skip(requestModel.Offset)
                            .Take(requestModel.PageSize)
                            .Include(x => x.Recipients)
                            .Include(x => x.DeviceUsers)
                            .ToListAsync();

                var result = new NotificationRulesListModel();
                foreach (var rule in rules)
                {
                    string eFormName;
                    if (eForms.Any(x => x.Key == rule.CheckListId))
                    {
                        eFormName = eForms.First(x => x.Key == rule.CheckListId).Value;
                    }
                    else
                    {
                        eForms.Add(new KeyValuePair <int, string>(rule.CheckListId, dbContext.CheckLists.Single(x => x.Id == rule.CheckListId).Label));
                        eFormName = eForms.First(x => x.Key == rule.CheckListId).Value;
                    }

                    var ruleModel = new NotificationRuleSimpleModel
                    {
                        Id        = rule.Id,
                        EFormName = eFormName,
                        Event     = "Email"
                    };

                    if (rule.Data != null && !string.IsNullOrEmpty(rule.Data))
                    {
                        try
                        {
                            ruleModel.Trigger = RulesBlockHelper.GetRuleTriggerString(rule, dbContext);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    result.Rules.Add(ruleModel);
                }

                result.Total = await _dbContext.Rules.CountAsync(x =>
                                                                 x.WorkflowState != Constants.WorkflowStates.Removed);

                return(new OperationDataResult <NotificationRulesListModel>(true, result));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(new OperationDataResult <NotificationRulesListModel>(
                           false,
                           _localizationService.GetString("ErrorWhileObtainingNotificationRulesInfo")));
            }
        }