public async Task <MetadataResult> Build(string language, CancellationToken cancellationToken)
        {
            var languages        = _options.SupportedUICultures.Select(l => l.Name);
            var languageExists   = !string.IsNullOrWhiteSpace(language) && languages.Contains(language);
            var translationCodes = new List <string>();
            var result           = new MetadataResult();

            if (_dic.Any())
            {
                foreach (var kvp in _dic)
                {
                    translationCodes.AddRange(GetTranslationCodes(kvp.Value));
                }

                IEnumerable <OAuthTranslation> translations;
                if (languageExists)
                {
                    translations = await _translationRepository.GetTranslations(translationCodes, language, cancellationToken);

                    languages = new[] { language };
                }
                else
                {
                    translations = await _translationRepository.GetTranslations(translationCodes, cancellationToken);
                }

                translations = SetDefaultValues(translationCodes, languages, translations);
                foreach (var kvp in _dic)
                {
                    result.Content.Add(kvp.Key, BuildMetadataRecord(kvp.Value, language, translations));
                }
            }

            return(result);
        }
Esempio n. 2
0
        public Checklist delete(int id)
        {
            bool isCheckListDeleted    = true;
            bool isItemsDeleted        = true;
            bool isTranslationsDeleted = true;

            Checklist checklistToDelete = _checklistRepo.GetChecklistById(id)
                                          .Include("Items")
                                          .Single();

            var itemsToDelete = checklistToDelete.Items.ToList();

            Checklist deletedChecklist = _checklistRepo.DeleteChecklist(id);

            if (!itemsToDelete.Any() || itemsToDelete == null)
            {
                isCheckListDeleted = _checklistRepo.Save();

                if (!isCheckListDeleted)
                {
                    deletedChecklist = null;
                }

                return(deletedChecklist);
            }
            else
            {
                //Delete all Items and corresponding translations
                foreach (var item in itemsToDelete)
                {
                    Item itemToDelete = _itemRepo.GetItemById(item.Id).FirstOrDefault();

                    List <Translation> translationsToDelete = _translationRepo.GetTranslations(item.Id).ToList();

                    foreach (var translationToDelete in translationsToDelete)
                    {
                        if (translationToDelete != null)
                        {
                            _translationRepo.DeleteTranslation(translationToDelete);
                        }
                    }

                    if (itemToDelete != null)
                    {
                        _itemRepo.DeleteItem(itemToDelete);
                    }
                }

                isCheckListDeleted    = _checklistRepo.Save();
                isTranslationsDeleted = _translationRepo.Save();
                isItemsDeleted        = _itemRepo.Save();

                if (!isTranslationsDeleted || !isTranslationsDeleted && !isTranslationsDeleted)
                {
                    deletedChecklist = null;
                }

                return(deletedChecklist);
            }
        }
Esempio n. 3
0
        public Item delete(int id)
        {
            Item itemToDelete = _itemRepo.GetItemById(id).FirstOrDefault();
            List <Translation> translationsToDelete = _translationRepo.GetTranslations(id).ToList();

            bool isItemDeleted         = true;
            bool isTranslationsDeleted = true;

            foreach (var translationToDelete in translationsToDelete)
            {
                if (translationToDelete != null)
                {
                    _translationRepo.DeleteTranslation(translationToDelete);
                }
            }

            isTranslationsDeleted = _translationRepo.Save();

            if (itemToDelete != null)
            {
                _itemRepo.DeleteItem(itemToDelete);
                isItemDeleted = _itemRepo.Save();
            }

            if (isItemDeleted && isTranslationsDeleted)
            {
                return(itemToDelete);
            }

            return(null);
        }