Exemplo n.º 1
0
        public IFacadeUpdateResult <DataPhraseData> SaveDataPhrases(object languageId, List <DataPhraseDto> dtoList)
        {
            FacadeUpdateResult <DataPhraseData> result = new FacadeUpdateResult <DataPhraseData>();
            // Retrieve phrases by languageId
            Dictionary <string, DataPhrase> phrases = new Dictionary <string, DataPhrase>();
            IDataPhraseService service = UnitOfWork.GetService <IDataPhraseService>();
            var query = service.SearchByLanguage(languageId);

            if (query.HasResult)
            {
                foreach (DataPhrase phrase in query.ToBoList <DataPhrase>())
                {
                    phrases.Add(phrase.PhraseKey, phrase);
                }
            }
            // Retrieve or Create instance
            List <DataPhrase> instances = new List <DataPhrase>();

            foreach (DataPhraseDto dto in dtoList)
            {
                DataPhrase instance = null;
                if (phrases.ContainsKey(dto.PhraseKey))
                {
                    instance             = phrases[dto.PhraseKey];
                    instance.PhraseValue = dto.PhraseValue;
                }
                else
                {
                    instance             = service.CreateNew <DataPhrase>();
                    instance.LanguageId  = languageId;
                    instance.PhraseKey   = dto.PhraseKey;
                    instance.PhraseValue = dto.PhraseValue;
                }
                instances.Add(instance);
            }
            // Save batch
            UnitOfWork.BeginTransaction();
            var saveQuery = service.SaveAll(instances);

            result.Merge(saveQuery);

            if (result.IsSuccessful)
            {
                UnitOfWork.CommitTransaction();
            }
            else
            {
                UnitOfWork.RollbackTransaction();
            }

            return(result);
        }
Exemplo n.º 2
0
        internal List <TDto> RetrieveDataPhrasesByLanguage <TDto>(object languageId, IDataConverter <DataPhraseData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("languageId", languageId);
            ArgumentValidator.IsNotNull("converter", converter);

            IDataPhraseService service = UnitOfWork.GetService <IDataPhraseService>();
            var query = service.SearchByLanguage(languageId);

            if (query.HasResult)
            {
                return(query.DataToDtoList(converter).ToList());
            }

            return(null);
        }