public async Task <OperationDataResult <AppointmentBaseSettings> > GetSettings() { try { var option = _options.Value; if (option.Token == "...") { string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); string result = new string(chars.Select(c => chars[random.Next(chars.Length)]).Take(32).ToArray()); await _options.UpdateDb(settings => { settings.Token = result; }, _dbContext, UserId); } if (option.SdkConnectionString == "...") { string connectionString = _dbContext.Database.GetDbConnection().ConnectionString; string dbNameSection = Regex.Match(connectionString, @"(Database=(...)_eform-angular-\w*-plugin;)").Groups[0].Value; string dbPrefix = Regex.Match(connectionString, @"Database=(\d*)_").Groups[1].Value; string sdk = $"Database={dbPrefix}_SDK;"; connectionString = connectionString.Replace(dbNameSection, sdk); await _options.UpdateDb(settings => { settings.SdkConnectionString = connectionString; }, _dbContext, UserId); } if (option.OutlookAddinId == "..." || string.IsNullOrEmpty(option.OutlookAddinId)) { await _options.UpdateDb(settings => settings.OutlookAddinId = Guid.NewGuid().ToString(), _dbContext, UserId); } return(new OperationDataResult <AppointmentBaseSettings>(true, option)); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationDataResult <AppointmentBaseSettings>(false, _trashInspectionLocalizationService.GetString("ErrorWhileObtainingTrashInspectionSettings"))); } }
public async Task <OperationDataResult <AppointmentsListModel> > Index(AppointmentRequestModel requestModel) { try { var list = await _dbContext.Appointments .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed && requestModel.EndDate > x.StartAt && (requestModel.StartDate < x.StartAt || x.RepeatType != null && x.NextId == null && (x.RepeatUntil == null || x.RepeatUntil > requestModel.StartDate))) .Select(x => new AppointmentSimpleModel() { Id = x.Id, StartAt = x.StartAt, ExpireAt = x.ExpireAt, Title = x.Title, ColorHex = x.ColorHex, RepeatUntil = x.RepeatUntil, RepeatEvery = x.RepeatEvery, RepeatType = x.RepeatType, NextId = x.NextId } ).ToListAsync(); var listModel = new AppointmentsListModel { Total = list.Count(), Appointments = list }; return(new OperationDataResult <AppointmentsListModel>(true, listModel)); } catch (Exception e) { Trace.TraceError(e.Message); return(new OperationDataResult <AppointmentsListModel>(false, _appointmentLocalizationService.GetString("ErrorGettingAppointmentsList"))); } }