コード例 #1
0
 /// <summary>   Resets the synchronise status. </summary>
 private void ResetSyncStatus()
 {
     using (var uow = _dataService.StartUnitOfWork())
     {
         uow.ResourceRepository.ResetSyncStatus();
         uow.Commit();
     }
 }
コード例 #2
0
        /// <summary>   Place where query handling happens. </summary>
        /// <param name="query">    This is the query instance. </param>
        /// <returns>
        ///     You have to return something from the query execution. Of course you can return
        ///     <c>null</c> as well if you will.
        /// </returns>
        public IEnumerable <LocalizationResource> Execute(GetAllResources.Query query)
        {
            var all = new List <LocalizationResource>();

            using (var uow = _dataService.StartUnitOfWork())
            {
                var compound = uow.TranslationRepository.GetAllCompound();

                // ReSharper disable once IteratorMethodResultIsIgnored
                foreach (var entity in compound)
                {
                    var resource = new LocalizationResource(entity.Resource.ResourceKey)
                    {
                        Id               = entity.Resource.Id,
                        Author           = entity.Resource.Author,
                        FromCode         = entity.Resource.FromCode,
                        IsHidden         = entity.Resource.IsHidden,
                        IsModified       = entity.Resource.IsModified,
                        ModificationDate = entity.Resource.ModificationDate
                    };
                    resource.Translations = new List <LocalizationResourceTranslation>(entity.Translations.Select(t =>
                                                                                                                  new LocalizationResourceTranslation
                    {
                        Id                   = t.Id,
                        Language             = t.Language,
                        LocalizationResource = resource,
                        ResourceId           = resource.Id,
                        Value                = t.Value
                    }));
                    all.Add(resource);
                }
            }

            return(all);
        }
コード例 #3
0
        /// <summary>   Gets resource from database. </summary>
        /// <param name="key">  The key. </param>
        /// <returns>   The resource from database. </returns>
        private LocalizationResource GetResourceFromDb(string key)
        {
            using (var uow = _dataService.StartUnitOfWork())
            {
                var resource = uow.ResourceRepository.GetByKey(key);
                if (resource == null)
                {
                    return(null);
                }

                var translations = uow.TranslationRepository.ByResource(resource);
                if (translations == null)
                {
                    return new LocalizationResource(key)
                           {
                               Translations = new List <LocalizationResourceTranslation>()
                           }
                }
                ;

                var r = new LocalizationResource(key)
                {
                    Id               = resource.Id,
                    Author           = resource.Author,
                    FromCode         = resource.FromCode,
                    IsHidden         = resource.IsHidden,
                    IsModified       = resource.IsModified,
                    ModificationDate = resource.ModificationDate
                };
                r.Translations = translations.Select(t => new LocalizationResourceTranslation
                {
                    Id                   = t.Id,
                    Language             = t.Language,
                    ResourceId           = t.ResourceId,
                    LocalizationResource = r,
                    Value                = t.Value
                }).ToList();
                return(r);
            }
        }
    }
コード例 #4
0
        public IActionResult Index(int pageNumber = 1)
        {
            var rGroups = new List <ResourceGroupModel>();

            using (var uow = _localizationDataService.StartUnitOfWork())
            {
                var resources = uow.ResourceRepository.GetAll().ToList();

                var ungroupable = resources.Where(r => r.ResourceKey != null && !r.ResourceKey.Contains(".")).OrderBy(r => r.ResourceKey).ToList();
                var groupable   = resources.Except(ungroupable);
                var groups      = groupable.GroupBy(r =>
                                                    r.ResourceKey.Substring(0, r.ResourceKey.LastIndexOf(".", StringComparison.Ordinal))).OrderBy(g => g.Key);

                rGroups.Add(new ResourceGroupModel {
                    Name = _localizer.GetString(r => r.Ungrouped), Entries = ungroupable.Count
                });
                rGroups.AddRange(groups.Select(g => new ResourceGroupModel {
                    Name = g.Key, Entries = g.Count()
                }));
            }

            var page = PageableModel <ResourceGroupModel> .PageExisting(rGroups, pageNumber).InitRoute(this, nameof(Index));

            return(View(page));
        }