示例#1
0
        private void SaveAsSystemPhrases(ExcelImportEventArgs arg)
        {
            ExcelSheet excelSheet = arg.Result;
            // Extract data from imported Excel sheet
            List <LanguagePhraseDto> languagePhrases = new List <LanguagePhraseDto>();

            for (int index = excelSheet.DataStartRowIndex; index < excelSheet.Rows.Count; index++)
            {
                ExcelSheetRow     excelRow       = excelSheet.Rows[index];
                LanguagePhraseDto languagePhrase = new LanguagePhraseDto();
                languagePhrases.Add(languagePhrase);
                languagePhrase.PhraseKey   = excelRow.GetValue(Col_Key);
                languagePhrase.PhraseValue = excelRow.GetValue(Col_Value);
            }

            // Save batch
            using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
            {
                LanguageFacade facade = new LanguageFacade(uow);
                IFacadeUpdateResult <LanguagePhraseData> result = facade.SaveSystemPhrases(SelectedLanguageId, languagePhrases);
                if (result.IsSuccessful)
                {
                    arg.IsSuccessful = true;
                    arg.Message      = string.Format("Batch save done. \\nTotal {0} rows.", languagePhrases.Count);
                }
                else
                {
                    arg.IsSuccessful = false;
                    // Deal with Update result
                    ProcUpdateResult(result.ValidationResult, result.Exception);
                }
            }
        }
示例#2
0
 private void StringLocalizer_LocalizeString(object sender, LocalizeStringEventArgs e)
 {
     if (WebContext.Current.ApplicationOption.IsMultiLanguageSupported && e.LanguageId != null)
     {
         LanguageDto currentLanguage = WebContext.Current.LanguageDic[e.LanguageId];
         if (currentLanguage.SysPhrases.ContainsKey(e.Key))
         {
             e.Value = currentLanguage.SysPhrases[e.Key];
         }
         else
         {
             // Save this key and defaultvalue in memory
             currentLanguage.SysPhrases.Add(e.Key, e.DefaultValue);
             // Save this key and defaultvalue in Database
             LanguagePhraseDto phrase = new LanguagePhraseDto();
             phrase.LanguageId  = currentLanguage.Id;
             phrase.PhraseKey   = e.Key;
             phrase.PhraseValue = e.DefaultValue;
             using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
             {
                 LanguagePhraseFacade facade = new LanguagePhraseFacade(uow);
                 facade.SaveLanguagePhrase(phrase);
             }
         }
     }
 }
示例#3
0
        public IFacadeUpdateResult <LanguagePhraseData> SaveLanguagePhrase(LanguagePhraseDto dto)
        {
            UnitOfWork.BeginTransaction();
            IFacadeUpdateResult <LanguagePhraseData> result = LanguagePhraseSystem.SaveLanguagePhrase(dto);

            if (result.IsSuccessful)
            {
                UnitOfWork.CommitTransaction();
            }
            else
            {
                UnitOfWork.RollbackTransaction();
            }
            return(result);
        }
        internal IFacadeUpdateResult <LanguagePhraseData> SaveLanguagePhrase(LanguagePhraseDto dto)
        {
            ArgumentValidator.IsNotNull("dto", dto);

            FacadeUpdateResult <LanguagePhraseData> result = new FacadeUpdateResult <LanguagePhraseData>();
            ILanguagePhraseService service  = UnitOfWork.GetService <ILanguagePhraseService>();
            LanguagePhrase         instance = RetrieveOrNew <LanguagePhraseData, LanguagePhrase, ILanguagePhraseService>(result.ValidationResult, dto.Id);

            if (result.IsSuccessful)
            {
                instance.LanguageId   = dto.LanguageId;
                instance.PhraseKey    = dto.PhraseKey;
                instance.PhraseValue  = dto.PhraseValue;
                instance.DateModified = DateTime.Now;

                var saveQuery = service.Save(instance);

                result.AttachResult(instance.RetrieveData <LanguagePhraseData>());
                result.Merge(saveQuery);
            }

            return(result);
        }