Пример #1
0
        public void CheckAndUpdateTextDescriptionToJson()
        {
            Console.WriteLine("Check and update text descriptions...");

            using (var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var scopedCtxMgr     = serviceScope.ServiceProvider.GetService <IContextManager>();
                var commonService    = serviceScope.ServiceProvider.GetService <ICommonService>();
                int updatedItemCount = 0;

                scopedCtxMgr.ExecuteWriter(unitOfWork =>
                {
                    //Organization description
                    updatedItemCount = 0;
                    var organizationDescriptionRep = unitOfWork.CreateRepository <IOrganizationDescriptionRepository>();
                    organizationDescriptionRep.All().ForEach(entity =>
                    {
                        if (!string.IsNullOrEmpty(entity.Description) && !IsValidJson(entity.Description))
                        {
                            entity.Description = _textManager.ConvertTextWithLineBreaksToJson(entity.Description);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update OrganizationDescription is done. Result updated {updatedItemCount}.");


                    //Service description
                    updatedItemCount          = 0;
                    var serviceDescriptionRep = unitOfWork.CreateRepository <IServiceDescriptionRepository>();
                    serviceDescriptionRep.All().ForEach(entity =>
                    {
                        if ((commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.Description.ToString()) || commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.ServiceUserInstruction.ToString())) &&
                            !string.IsNullOrEmpty(entity.Description) && !IsValidJson(entity.Description))
                        {
                            entity.Description = _textManager.ConvertTextWithLineBreaksToJson(entity.Description);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update ServiceDescription is done. Result updated {updatedItemCount}.");

                    //Service requirement
                    updatedItemCount          = 0;
                    var serviceRequirementRep = unitOfWork.CreateRepository <IServiceRequirementRepository>();
                    serviceRequirementRep.All().ForEach(entity =>
                    {
                        if (!string.IsNullOrEmpty(entity.Requirement) && !IsValidJson(entity.Requirement))
                        {
                            entity.Requirement = _textManager.ConvertTextWithLineBreaksToJson(entity.Requirement);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update ServiceRequirement is done. Result updated {updatedItemCount}.");

                    //ServiceChannel description
                    updatedItemCount = 0;
                    var serviceChannelDescriptionRep = unitOfWork.CreateRepository <IServiceChannelDescriptionRepository>();
                    serviceChannelDescriptionRep.All().ForEach(entity =>
                    {
                        if (commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.Description.ToString()) && !string.IsNullOrEmpty(entity.Description) && !IsValidJson(entity.Description))
                        {
                            entity.Description = _textManager.ConvertTextWithLineBreaksToJson(entity.Description);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update ServiceChannelDescription is done. Result updated {updatedItemCount}.");

                    //Statutory service requirement
                    updatedItemCount = 0;
                    var statutoryServiceRequirementRep = unitOfWork.CreateRepository <IStatutoryServiceRequirementRepository>();
                    statutoryServiceRequirementRep.All().ForEach(entity =>
                    {
                        if (!string.IsNullOrEmpty(entity.Requirement) && !IsValidJson(entity.Requirement))
                        {
                            entity.Requirement = _textManager.ConvertTextWithLineBreaksToJson(entity.Requirement);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update StatutoryServiceRequirement is done. Result updated {updatedItemCount}.");

                    //Statutory service description
                    updatedItemCount = 0;
                    var statutoryServiceDescriptionRep = unitOfWork.CreateRepository <IStatutoryServiceDescriptionRepository>();
                    statutoryServiceDescriptionRep.All().ForEach(entity =>
                    {
                        if ((commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.Description.ToString()) ||
                             commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.BackgroundDescription.ToString()) ||
                             commonService.IsDescriptionEnumType(entity.TypeId, DescriptionTypeEnum.ServiceUserInstruction.ToString())) &&
                            !string.IsNullOrEmpty(entity.Description) && !IsValidJson(entity.Description))
                        {
                            entity.Description = _textManager.ConvertTextWithLineBreaksToJson(entity.Description);
                            updatedItemCount++;
                        }
                    });
                    Console.WriteLine($@"Update StatutoryServiceDescription is done. Result updated {updatedItemCount}.");

                    unitOfWork.Save(SaveMode.NonTrackedDataMigration);
                    Console.WriteLine("Done.");
                });
            }
        }