Пример #1
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            questions question = await dbContext.questions.FirstOrDefaultAsync(x => x.Id == Id);

            if (question == null)
            {
                throw new NullReferenceException($"Could no find question with Id: {Id}");
            }

            question.Type                 = Type;
            question.Image                = Image;
            question.BackButtonEnabled    = BackButtonEnabled;
            question.Maximum              = Maximum;
            question.Minimum              = Minimum;
            question.Prioritised          = Prioritised;
            question.RefId                = RefId;
            question.FontSize             = FontSize;
            question.MaxDuration          = MaxDuration;
            question.MinDuration          = MinDuration;
            question.ImagePosition        = ImagePosition;
            question.QuestionType         = QuestionType;
            question.ValidDisplay         = ValidDisplay;
            question.QuestionIndex        = QuestionIndex;
            question.QuestionSetId        = QuestionSetId;
            question.ContinuousQuestionId = ContinuousQuestionId;

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                dbContext.question_versions.Add(MapVersions(question));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Update(MicrotingDbContext dbContext)
        {
            entity_items entityItem = await dbContext.entity_items.FirstOrDefaultAsync(x => x.Id == Id);

            if (entityItem == null)
            {
                throw new NullReferenceException($"Could not find Entity Item with Id: {Id}");
            }

            entityItem.EntityGroupId = EntityGroupId;
            entityItem.MicrotingUid  = MicrotingUid;
            entityItem.Name          = Name;
            entityItem.Description   = Description;
            entityItem.Synced        = Synced;
            entityItem.DisplayIndex  = DisplayIndex;

            if (dbContext.ChangeTracker.HasChanges())
            {
                entityItem.UpdatedAt = DateTime.UtcNow;
                entityItem.Version  += 1;

                dbContext.entity_item_versions.Add(MapEntityItemVersions(entityItem));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Handle(eFormCaseUpdated message)
        {
            ItemCaseSite itemCaseSite = await _dbContext.ItemCaseSites.SingleOrDefaultAsync(x => x.MicrotingSdkCaseId == message.caseId);

            if (itemCaseSite != null)
            {
                var caseDto = await _sdkCore.CaseReadByCaseId(message.caseId);

                var microtingUId      = caseDto.MicrotingUId;
                var microtingCheckUId = caseDto.CheckUId;
                await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
                Site site = await microtingDbContext.Sites.SingleAsync(x => x.Id == itemCaseSite.MicrotingSdkSiteId);

                Language language = await microtingDbContext.Languages.SingleAsync(x => x.Id == site.LanguageId);

                var theCase = await _sdkCore.CaseRead((int)microtingUId, (int)microtingCheckUId, language);

                itemCaseSite = await SetFieldValue(itemCaseSite, theCase.Id);

                await itemCaseSite.Update(_dbContext);

                ItemCase itemCase = await _dbContext.ItemCases.SingleOrDefaultAsync(x => x.Id == itemCaseSite.ItemCaseId);

                itemCase = await SetFieldValue(itemCase, theCase.Id);

                await itemCase.Update(_dbContext);
            }
        }
Пример #4
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            options option = await dbContext.options.FirstOrDefaultAsync(x => x.Id == Id);

            if (option == null)
            {
                throw new NullReferenceException($"Could not find option with Id: {Id}");
            }

            option.QuestionId         = QuestionId;
            option.Weight             = Weight;
            option.WeightValue        = WeightValue;
            option.NextQuestionId     = NextQuestionId;
            option.ContinuousOptionId = ContinuousOptionId;
            option.OptionsIndex       = OptionsIndex;
            option.DisplayIndex       = DisplayIndex;

            if (dbContext.ChangeTracker.HasChanges())
            {
                Version  += 1;
                UpdatedAt = DateTime.UtcNow;

                dbContext.option_versions.Add(MapVersions(option));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Update(MicrotingDbContext dbContext)
        {
            check_list_values clv = await dbContext.check_list_values.FirstOrDefaultAsync(x => x.Id == Id);

            if (clv == null)
            {
                throw new NullReferenceException($"Could not find Check List Value with Id: {Id}");
            }

            clv.Status               = Status;
            clv.UserId               = UserId;
            clv.CaseId               = CaseId;
            clv.CheckListId          = CheckListId;
            clv.CheckListDuplicateId = CheckListDuplicateId;


            if (dbContext.ChangeTracker.HasChanges())
            {
                clv.UpdatedAt = DateTime.UtcNow;
                clv.Version  += 1;

                dbContext.check_list_value_versions.Add(MapCheckListValueVersions(clv));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Update(MicrotingDbContext dbContext)
        {
            uploaded_data uploadedData = await dbContext.uploaded_data.FirstOrDefaultAsync(x => x.Id == Id);

            if (uploadedData == null)
            {
                throw new NullReferenceException($"Could not find Uploaded Data with Id: {Id}");
            }

            uploadedData.UploaderId      = UploaderId;
            uploadedData.UploaderType    = UploaderType;
            uploadedData.Checksum        = Checksum;
            uploadedData.Extension       = Extension;
            uploadedData.Local           = Local;
            uploadedData.FileName        = FileName;
            uploadedData.CurrentFile     = CurrentFile;
            uploadedData.FileLocation    = FileLocation;
            uploadedData.ExpirationDate  = ExpirationDate;
            uploadedData.TranscriptionId = TranscriptionId;

            if (dbContext.ChangeTracker.HasChanges())
            {
                uploadedData.Version  += 1;
                uploadedData.UpdatedAt = DateTime.UtcNow;

                dbContext.uploaded_data_versions.Add(MapVersions(uploadedData));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task <OperationDataResult <DisplayTemplateColumnsModel> > GetCurrentColumns(int templateId)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                await using MicrotingDbContext dbContext = core.DbContextHelper.GetDbContext();
                var locale = await _userService.GetCurrentUserLocale();

                Language language = dbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower());
                var      template = await core.TemplateItemRead(templateId, language);

                var model = new DisplayTemplateColumnsModel()
                {
                    TemplateId = template.Id,
                    FieldId1   = template.Field1?.Id,
                    FieldId2   = template.Field2?.Id,
                    FieldId3   = template.Field3?.Id,
                    FieldId4   = template.Field4?.Id,
                    FieldId5   = template.Field5?.Id,
                    FieldId6   = template.Field6?.Id,
                    FieldId7   = template.Field7?.Id,
                    FieldId8   = template.Field8?.Id,
                    FieldId9   = template.Field9?.Id,
                    FieldId10  = template.Field10?.Id
                };

                return(new OperationDataResult <DisplayTemplateColumnsModel>(true, model));
            }
            catch (Exception)
            {
                return(new OperationDataResult <DisplayTemplateColumnsModel>(false,
                                                                             _localizationService.GetString("ErrorWhileObtainColumns")));
            }
        }
Пример #8
0
        public static IQueryable <AnswerViewModel> GetAnswerByMicrotingUid(int microtingUid,
                                                                           MicrotingDbContext dbContext)
        {
            var answersQueryable = dbContext.Answers
                                   .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                                   .Where(x => x.MicrotingUid == microtingUid)
                                   .AsNoTracking()
                                   .AsQueryable()
                                   .Select(answers => new AnswerViewModel()
            {
                MicrotingUid = (int)answers.MicrotingUid,
                Id           = answers.Id,
                AnswerValues = dbContext.AnswerValues
                               .Where(answerValues => answerValues.AnswerId == answers.Id)
                               .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                               .AsQueryable()
                               .Select(a => new AnswerValuesViewModel()
                {
                    Value        = a.Value,
                    Id           = a.Id,
                    Translations = dbContext.OptionTranslations
                                   .Where(x => x.OptionId == a.OptionId)
                                   .AsQueryable()
                                   .Select(translations => new AnswerValueTranslationModel()
                    {
                        Value        = translations.Name,
                        LanguageId   = translations.LanguageId,
                        LanguageName = dbContext.Languages
                                       .FirstOrDefault(x => x.Id == translations.LanguageId).Name
                    }).ToList()
                }).ToList()
            });

            return(answersQueryable);
        }
Пример #9
0
        private async Task CreateSmileyOption(MicrotingDbContext dbContext, string smiley, int languageId, int index)
        {
            switch (smiley)
            {
            case "smiley1":
                await CreateSpecialOption(dbContext, 5, 100, smiley, languageId, index);

                break;

            case "smiley2":
                await CreateSpecialOption(dbContext, 4, 75, smiley, languageId, index);

                break;

            case "smiley3":
                await CreateSpecialOption(dbContext, 3, 50, smiley, languageId, index);

                break;

            case "smiley4":
                await CreateSpecialOption(dbContext, 2, 25, smiley, languageId, index);

                break;

            case "smiley5":
                await CreateSpecialOption(dbContext, 1, 0, smiley, languageId, index);

                break;

            case "smiley6":
                await CreateSpecialOption(dbContext, 0, 999, smiley, languageId, index);

                break;
            }
        }
Пример #10
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            survey_configurations surveyConfigurations =
                await dbContext.survey_configurations.FirstOrDefaultAsync(x => x.Id == Id);

            if (surveyConfigurations == null)
            {
                throw new NullReferenceException($"Could not find survey configuration with Id: {Id}");
            }

            surveyConfigurations.Name       = Name;
            surveyConfigurations.Stop       = Stop;
            surveyConfigurations.Start      = Start;
            surveyConfigurations.TimeOut    = TimeOut;
            surveyConfigurations.TimeToLive = TimeToLive;

            if (dbContext.ChangeTracker.HasChanges())
            {
                surveyConfigurations.Version  += 1;
                surveyConfigurations.UpdatedAt = DateTime.UtcNow;

                dbContext.survey_configuration_versions.Add(MapVersions(surveyConfigurations));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Пример #11
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            answers answer = await dbContext.answers.FirstOrDefaultAsync(x => x.Id == Id);

            if (answer == null)
            {
                throw new NullReferenceException($"Could not find answer with Id: {Id}");
            }

            answer.SiteId                = SiteId;
            answer.UnitId                = UnitId;
            answer.TimeZone              = TimeZone;
            answer.FinishedAt            = FinishedAt;
            answer.LanguageId            = LanguageId;
            answer.AnswerDuration        = AnswerDuration;
            answer.QuestionSetId         = QuestionSetId;
            answer.SurveyConfigurationId = SurveyConfigurationId;
            answer.UtcAdjusted           = UtcAdjusted;

            if (dbContext.ChangeTracker.HasChanges())
            {
                answer.UpdatedAt = DateTime.UtcNow;
                answer.Version  += 1;

                dbContext.answer_versions.Add(MapVersions(answer));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Пример #12
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            question_translations questionTranslation =
                await dbContext.QuestionTranslations.SingleOrDefaultAsync(x => x.Id == Id).ConfigureAwait(false);

            if (questionTranslation == null)
            {
                throw new NullReferenceException($"Could not find question_translation with id {Id}");
            }

            questionTranslation.LanguageId    = LanguageId;
            questionTranslation.QuestionId    = QuestionId;
            questionTranslation.Name          = Name;
            questionTranslation.WorkflowState = WorkflowState;
            questionTranslation.MicrotingUid  = MicrotingUid;

            if (dbContext.ChangeTracker.HasChanges())
            {
                questionTranslation.UpdatedAt = DateTime.UtcNow;
                questionTranslation.Version  += 1;

                dbContext.QuestionTranslationVersions.Add(MapVersions(questionTranslation));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Пример #13
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            field_values fieldValues = await dbContext.field_values.FirstOrDefaultAsync(x => x.Id == Id);

            if (fieldValues == null)
            {
                throw new NullReferenceException($"Could not find Field Value with Id: {Id}");
            }

            fieldValues.DoneAt               = DoneAt;
            fieldValues.Date                 = Date;
            fieldValues.WorkerId             = WorkerId;
            fieldValues.CaseId               = CaseId;
            fieldValues.FieldId              = FieldId;
            fieldValues.CheckListId          = CheckListId;
            fieldValues.CheckListDuplicateId = CheckListDuplicateId;
            fieldValues.UploadedDataId       = UploadedDataId;
            fieldValues.Value                = Value;
            fieldValues.Latitude             = Latitude;
            fieldValues.Longitude            = Longitude;
            fieldValues.Altitude             = Altitude;
            fieldValues.Heading              = Heading;
            fieldValues.Accuracy             = Accuracy;

            if (dbContext.ChangeTracker.HasChanges())
            {
                fieldValues.UpdatedAt = DateTime.UtcNow;
                fieldValues.Version  += 1;

                dbContext.field_value_versions.Add(MapFieldValueVersions(fieldValues));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task Setup()
        {
            ConnectionString = @"Server = localhost; port = 3306; Database = eformsdk-tests; user = root; Convert Zero Datetime = true;";

            dbContext = GetContext(ConnectionString);

            dbContext.Database.SetCommandTimeout(300);

            try
            {
                await ClearDb().ConfigureAwait(false);
            }
            catch
            {
            }
            try
            {
                AdminTools adminTools = new AdminTools(ConnectionString);
                await adminTools.DbSetup("abc1234567890abc1234567890abcdef").ConfigureAwait(false);
            } catch
            {
            }

            await DoSetup().ConfigureAwait(false);
        }
Пример #15
0
        public async Task Update(MicrotingDbContext dbContext)
        {
            notifications notification = await dbContext.notifications.SingleOrDefaultAsync(x => x.Id == Id);

            if (notification == null)
            {
                throw new NullReferenceException($"Could not find notification with id {Id}");
            }

            notification.WorkflowState   = WorkflowState;
            notification.MicrotingUid    = MicrotingUid;
            notification.Transmission    = Transmission;
            notification.NotificationUid = NotificationUid;
            notification.Activity        = Activity;
            notification.Exception       = Exception;
            notification.Stacktrace      = Stacktrace;

            if (dbContext.ChangeTracker.HasChanges())
            {
                notification.UpdatedAt = DateTime.UtcNow;
                notification.Version  += 1;

                dbContext.notification_versions.Add(MapVersions(notification));
                await dbContext.SaveChangesAsync().ConfigureAwait(false);
            }
        }
Пример #16
0
        public static IQueryable <Answer> GetAnswerQueryByMicrotingUidForDelete(int microtingUid,
                                                                                MicrotingDbContext dbContext)
        {
            var answerQuery = dbContext.Answers
                              .Where(x => x.MicrotingUid == microtingUid);

            return(answerQuery);
        }
Пример #17
0
        private static void CheckUploadedDataIntegrity(MicrotingDbContext dbContext, Core core)
        {
            AmazonS3Client s3Client;
            string         s3AccessKeyId       = dbContext.Settings.Single(x => x.Name == Settings.s3AccessKeyId.ToString()).Value;
            string         s3SecretAccessKey   = dbContext.Settings.Single(x => x.Name == Settings.s3SecrectAccessKey.ToString()).Value;
            string         s3Endpoint          = dbContext.Settings.Single(x => x.Name == Settings.s3Endpoint.ToString()).Value;
            string         s3BucktName         = dbContext.Settings.Single(x => x.Name == Settings.s3BucketName.ToString()).Value;
            string         customerNo          = dbContext.Settings.Single(x => x.Name == Settings.customerNo.ToString()).Value;
            string         comAddressApi       = dbContext.Settings.Single(x => x.Name == Settings.comAddressApi.ToString()).Value;
            string         token               = dbContext.Settings.Single(x => x.Name == Settings.token.ToString()).Value;
            string         comOrganizationId   = dbContext.Settings.Single(x => x.Name == Settings.comOrganizationId.ToString()).Value;
            string         fileLocationPicture = Path.Combine(Path.GetTempPath(), "pictures");

            Directory.CreateDirectory(fileLocationPicture);

            if (s3Endpoint.Contains("https"))
            {
                s3Client = new AmazonS3Client(s3AccessKeyId, s3SecretAccessKey, new AmazonS3Config
                {
                    ServiceURL = s3Endpoint,
                });
            }
            else
            {
                s3Client = new AmazonS3Client(s3AccessKeyId, s3SecretAccessKey, RegionEndpoint.EUCentral1);
            }
            var uploadedDatas = dbContext.UploadedDatas.Where(x => x.FileLocation.Contains("https")).ToList();

            foreach (UploadedData ud in uploadedDatas)
            {
                GetObjectMetadataRequest request = new GetObjectMetadataRequest
                {
                    BucketName = $"{s3BucktName}/{customerNo}",
                    Key        = ud.FileName
                };
                if (ud.FileName == null)
                {
                    core.DownloadUploadedData(ud.Id).GetAwaiter().GetResult();
                }
                else
                {
                    try
                    {
                        var result = s3Client.GetObjectMetadataAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
                    }
                    catch (AmazonS3Exception s3Exception)
                    {
                        if (s3Exception.ErrorCode == "Forbidden")
                        {
                            core.DownloadUploadedData(ud.Id).GetAwaiter().GetResult();
                        }
                    }
                }

                ud.Local = 0;
                ud.Update(dbContext).GetAwaiter().GetResult();
            }
        }
Пример #18
0
        public async Task Create(MicrotingDbContext dbContext, bool CreateSpecialQuestionTypes)
        {
            await Create(dbContext);

            if (CreateSpecialQuestionTypes)
            {
                await GenerateSpecialQuestionTypes(dbContext, 1);
            }
        }
        private void GetContext(string connectionStr)
        {
            var contextFactory = new MicrotingDbContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
Пример #20
0
        private static void FixDoneAt(MicrotingDbContext dbContext)
        {
            var cases = dbContext.Cases.Where(x => x.DoneAtUserModifiable == null).ToList();

            foreach (Microting.eForm.Infrastructure.Data.Entities.Case theCase in cases)
            {
                theCase.DoneAtUserModifiable = theCase.DoneAt;
                theCase.Update(dbContext).GetAwaiter().GetResult();
            }
        }
Пример #21
0
        private async Task <Folder> GetTopFolderName(int folderId, MicrotingDbContext dbContext)
        {
            var result = await dbContext.Folders.FirstAsync(y => y.Id == folderId);

            if (result.ParentId != null)
            {
                result = await GetTopFolderName((int)result.ParentId, dbContext);
            }
            return(result);
        }
        public static string GetRuleTriggerString(NotificationRule notificationRule, MicrotingDbContext dbContext)
        {
            var result       = "";
            var jsonSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Include
            };

            switch (notificationRule.RuleType)
            {
            case RuleType.Select:
                var multiSelectBlock = JsonConvert.DeserializeObject <SelectBlock>(notificationRule.Data, jsonSettings);
                result = multiSelectBlock.KeyValuePairList
                         .Where(i => i.Selected)
                         .Aggregate(result, (current, item) => current + $"<p>{multiSelectBlock.Label} = {item.Value}</p>");
                break;

            case RuleType.CheckBox:
                var checkBoxBlock = JsonConvert.DeserializeObject <CheckBoxBlock>(notificationRule.Data, jsonSettings);
                var checkboxState = checkBoxBlock.Selected ? "Checked" : "Not Checked";
                result = $"<p>{checkBoxBlock.Label} = {checkboxState}</p>";
                break;

            case RuleType.Number:
                var numberBlock = JsonConvert.DeserializeObject <NumberBlock>(notificationRule.Data, jsonSettings);

                if (numberBlock.GreaterThanValue != null)
                {
                    result += $"<p>{numberBlock.Label} > {numberBlock.GreaterThanValue}</p>";
                }

                if (numberBlock.LessThanValue != null)
                {
                    result += $"<p>{numberBlock.Label} < {numberBlock.LessThanValue}</p>";
                }

                if (numberBlock.EqualValue != null)
                {
                    result += $"<p>{numberBlock.Label} = {numberBlock.EqualValue}</p>";
                }
                break;

            case null:
                if (notificationRule.DeviceUsers.Any())
                {
                    foreach (DeviceUser deviceUser in notificationRule.DeviceUsers)
                    {
                        result += dbContext.Sites.Single(x => x.MicrotingUid == deviceUser.DeviceUserId).Name;
                    }
                }
                break;
            }

            return(result);
        }
Пример #23
0
        private async Task GenerateSmileyOptions(MicrotingDbContext dbContext, int languageId)
        {
            string[] smileys = new [] { "" };
            switch (this.QuestionType)
            {
            case Constants.Constants.QuestionTypes.Smiley:
                smileys = new[] { "smiley1", "smiley2", "smiley3", "smiley5", "smiley6" };
                break;

            case Constants.Constants.QuestionTypes.Smiley2:
                smileys = new[] { "smiley1", "smiley2", "smiley3", "smiley4", "smiley5", "smiley6" };
                break;

            case Constants.Constants.QuestionTypes.Smiley3:
                smileys = new[] { "smiley1", "smiley5" };
                break;

            case Constants.Constants.QuestionTypes.Smiley4:
                smileys = new[] { "smiley1", "smiley5", "smiley6" };
                break;

            case Constants.Constants.QuestionTypes.Smiley5:
                smileys = new[] { "smiley1", "smiley3", "smiley5" };
                break;

            case Constants.Constants.QuestionTypes.Smiley6:
                smileys = new[] { "smiley1", "smiley3", "smiley5", "smiley6" };
                break;

            case Constants.Constants.QuestionTypes.Smiley7:
                smileys = new[] { "smiley1", "smiley2", "smiley3", "smiley5" };
                break;

            case Constants.Constants.QuestionTypes.Smiley8:
                smileys = new[] { "smiley1", "smiley2", "smiley4", "smiley5" };
                break;

            case Constants.Constants.QuestionTypes.Smiley9:
                smileys = new[] { "smiley1", "smiley2", "smiley4", "smiley5", "smiley6" };
                break;

            case Constants.Constants.QuestionTypes.Smiley10:
                smileys = new[] { "smiley1", "smiley2", "smiley3", "smiley4", "smiley5" };
                break;
            }

            int i = 0;

            foreach (string smiley in smileys)
            {
                await CreateSmileyOption(dbContext, smiley, languageId, i);

                i++;
            }
        }
        public async Task Handle(eFormRetrieved message)
        {
            await using MicrotingDbContext sdkDbContext = _sdkCore.DbContextHelper.GetDbContext();
            Case theCase = await sdkDbContext.Cases.FirstOrDefaultAsync(x => x.MicrotingUid == message.CaseId);

            if (theCase != null)
            {
                PlanningCaseSite planningCaseSite =
                    await _dbContext.PlanningCaseSites.FirstOrDefaultAsync(x => x.MicrotingSdkCaseId == theCase.Id);

                if (planningCaseSite is { Status : < 77 })
Пример #25
0
        public async Task Delete(MicrotingDbContext dbContext)
        {
            field_types fieldTypes = await dbContext.field_types.FirstOrDefaultAsync(x => x.Id == Id);

            if (fieldTypes == null)
            {
                throw new NullReferenceException($"Could not find Field Type with Id: {Id}");
            }
            dbContext.Remove(fieldTypes);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #26
0
        public async Task Create(MicrotingDbContext dbContext)
        {
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;
            Version       = 1;
            WorkflowState = Constants.Constants.WorkflowStates.Created;
            dbContext.answers.Add(this);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            dbContext.answer_versions.Add(MapVersions(this));
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #27
0
        public async Task <OperationDataResult <List <Field> > > GetFields(int id)
        {
            var core = await _coreHelper.GetCore();

            await using MicrotingDbContext dbContext = core.DbContextHelper.GetDbContext();
            var locale = await _userService.GetCurrentUserLocale();

            Language language = dbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower());
            var      fields   = core.Advanced_TemplateFieldReadAll(id, language).Result.Select(f => core.Advanced_FieldRead(f.Id, language).Result).ToList();

            return(new OperationDataResult <List <Field> >(true, fields));
        }
Пример #28
0
        public async Task Handle(PushMessage message)
        {
            Planning planning = await _dbContext.Plannings.FirstOrDefaultAsync(x => x.Id == message.PlanningId);

            if (planning != null)
            {
                await using MicrotingDbContext microtingDbContext = _sdkCore.DbContextHelper.GetDbContext();
                List <PlanningSite> planningSites =
                    await _dbContext.PlanningSites.Where(x => x.PlanningId == message.PlanningId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync();

                foreach (PlanningSite planningSite in planningSites)
                {
                    Site site = await microtingDbContext.Sites.FirstOrDefaultAsync(x => x.Id == planningSite.SiteId);

                    if (site != null)
                    {
                        PlanningNameTranslation planningNameTranslation =
                            await _dbContext.PlanningNameTranslation.FirstAsync(x =>
                                                                                x.PlanningId == planning.Id &&
                                                                                x.LanguageId == site.LanguageId);

                        var folder = await GetTopFolderName((int)planning.SdkFolderId !, microtingDbContext);

                        string body = "";
                        if (folder != null)
                        {
                            planning.SdkFolderId = microtingDbContext.Folders.First(y => y.Id == planning.SdkFolderId).Id;
                            FolderTranslation folderTranslation =
                                await microtingDbContext.FolderTranslations.SingleAsync(x =>
                                                                                        x.FolderId == folder.Id && x.LanguageId == site.LanguageId);

                            body = $"{folderTranslation.Name} ({site.Name};{DateTime.Now:dd.MM.yyyy})";
                        }

                        PlanningCaseSite planningCaseSite = await _dbContext.PlanningCaseSites.FirstOrDefaultAsync(x =>
                                                                                                                   x.PlanningId == planningSite.PlanningId &&
                                                                                                                   x.MicrotingSdkSiteId == planningSite.SiteId &&
                                                                                                                   x.Status != 100 &&
                                                                                                                   x.WorkflowState == Constants.WorkflowStates.Created);

                        Log.LogEvent($"[DBG] ItemsPlanningService PushMessageHandler.Handle : Sending push message body: {body}, title : {planningNameTranslation.Name} to site.id : {site.Id}");
                        Case @case =
                            await microtingDbContext.Cases.FirstAsync(x =>
                                                                      x.Id == planningCaseSite.MicrotingSdkCaseId);

                        await _sdkCore.SendPushMessage(site.Id, planningNameTranslation.Name, body, (int)@case.MicrotingUid !);
                    }
                }

                planning.PushMessageSent = true;
                await planning.Update(_dbContext);
            }
        }
        public async Task Create(MicrotingDbContext dbContext)
        {
            WorkflowState = Constants.Constants.WorkflowStates.Created;
            Version       = 1;
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;

            dbContext.entity_items.Add(this);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            dbContext.entity_item_versions.Add(MapEntityItemVersions(this));
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task Create(MicrotingDbContext dbContext)
        {
            WorkflowState = Constants.Constants.WorkflowStates.Created;
            Version       = 1;
            CreatedAt     = DateTime.UtcNow;
            UpdatedAt     = DateTime.UtcNow;

            dbContext.check_list_values.Add(this);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            dbContext.check_list_value_versions.Add(MapCheckListValueVersions(this));
            await dbContext.SaveChangesAsync().ConfigureAwait(false);
        }