/// <summary> /// Creates a new translation, making child-copies of the phrasesCriteria.Phrases and adding these /// children to translation.Phrases. /// </summary> /// <param name="phrasesCriteria">collection of PhraseEdits, do not have to be marked as children.</param> public static async Task <TranslationCreator> CreateNewAsync( Criteria.ListOfPhrasesCriteria phrasesCriteria) { var result = await DataPortal.CreateAsync <TranslationCreator>(phrasesCriteria); return(result); }
public void DataPortal_Create(Criteria.ListOfPhrasesCriteria phrasesCriteria) { //INITIALIZE TRANSLATION CREATOR RetrieverId = Guid.NewGuid(); Translation = TranslationEdit.NewTranslationEdit(); //WILL USE THIS TO POPULATE THE TRANSLATION List <PhraseEdit> phrasesToUse = new List <PhraseEdit>(phrasesCriteria.Phrases); //FILL TRANSLATION.PHRASES WITH EMPTY PHRASES for (int i = 0; i < phrasesToUse.Count; i++) { Translation.Phrases.AddNew(); } //RETRIEVE ANY ALREADY-EXISTING PHRASES IN DB var retriever = PhrasesByTextAndLanguageRetriever.CreateNew(phrasesCriteria); for (int i = 0; i < phrasesToUse.Count; i++) { var phraseToAdd = phrasesToUse[i]; //IF THE RETRIEVEDPHRASES CONTAINS TO THE KEY (WHICH IT SHOULD) //AND THE RETRIEVER FOUND AN ALREADY EXISTING PHRASE IN DB, //THEN REPLACE PHRASETOADD WITH THAT DB PHRASE if (retriever.RetrievedPhrases.ContainsKey(phraseToAdd.Id) && retriever.RetrievedPhrases[phraseToAdd.Id] != null) { phraseToAdd = retriever.RetrievedPhrases[phraseToAdd.Id]; } var translationChildPhrase = Translation.Phrases[i]; var dto = phraseToAdd.CreateDto(); translationChildPhrase.LoadFromDtoBypassPropertyChecks(dto); } }
/// <summary> /// Retrieves PhraseEdits from the DB that match the PhraseEdits given in the criteria. /// It stores these retrieved phrases in a dictionary, with the given phrase.Id in the criteria /// as the keys and the retrieved phrases as the values. /// /// For any phrase in criteria given that is not found in DB, the retrieved phrase will be null. /// /// THIS IS NOT OPTIMIZED, AND IT DOES MOST OF THE WORK ON THE SERVER SIDE. I MIGHT SHOULD TURN THIS INTO A COMMAND OBJECT /// AND HAVE THIS DONE ON THE CLIENT SIDE, ESPECIALLY SINCE CURRENTLY IT IS JUST USING PHRASELIST.GETALL() AND THEN /// WORKING OFF OF THAT ANYWAY. /// </summary> /// <param name="criteria">phrases to be retrieved from DB</param> public static PhrasesByTextAndLanguageRetriever CreateNew(Criteria.ListOfPhrasesCriteria criteria) { return(DataPortal.Create <PhrasesByTextAndLanguageRetriever>(criteria)); }
/// <summary> /// Retrieves PhraseEdits from the DB that match the PhraseEdits given in the criteria. /// It stores these retrieved phrases in a dictionary, with the given phrase.Id in the criteria /// as the keys and the retrieved phrases as the values. /// /// For any phrase in criteria given that is not found in DB, the retrieved phrase will be null. /// /// THIS IS NOT OPTIMIZED, AND IT DOES MOST OF THE WORK ON THE SERVER SIDE. I MIGHT SHOULD TURN THIS INTO A COMMAND OBJECT /// AND HAVE THIS DONE ON THE CLIENT SIDE, ESPECIALLY SINCE CURRENTLY IT IS JUST USING PHRASELIST.GETALL() AND THEN /// WORKING OFF OF THAT ANYWAY. /// </summary> /// <param name="criteria">phrases to be retrieved from DB</param> public static async Task <PhrasesByTextAndLanguageRetriever> CreateNewAsync(Criteria.ListOfPhrasesCriteria criteria) { var result = await DataPortal.CreateAsync <PhrasesByTextAndLanguageRetriever>(criteria); return(result); }
public void DataPortal_Create(Criteria.ListOfPhrasesCriteria criteria) { //WE ARE GOING TO GET ALL THE PHRASES //WE WILL THEN ITERATE THROUGH OUR CRITERIA PHRASES, POPULATING OUR //RETRIEVED PHRASES //INITIALIZE RetrieverId = Guid.NewGuid(); if (RetrievedPhrases == null) { RetrievedPhrases = new MobileDictionary <Guid, PhraseEdit>(); } ////GET ALL PHRASES (FOR THIS USER ONLY) //PhraseList allPhrases = PhraseList.GetAll(); //KEY = TEXT, VALUE = PHRASELIST CONTAINING ALL PHRASES THAT CONTAIN THE KEY TEXT var phraseLists = new Dictionary <string, PhraseList>(); for (int i = 0; i < criteria.Phrases.Count; i++) { var criteriaPhrase = criteria.Phrases[i]; //IF WE'VE ALREADY DONE THIS PHRASE, THEN GO ON TO THE NEXT ONE, SO WE DON'T DUPLICATE WORK if (RetrievedPhrases.ContainsKey(criteriaPhrase.Id)) { continue; } //INITIALIZE RETRIEVED PHRASE PhraseEdit retrievedPhrase = null; //GET ALL PHRASES THAT CONTAIN THIS PHRASE, IN ANY LANGUAGE var allPhrasesContainingPhrase = PhraseList.GetAllContainingText(criteriaPhrase.Text); //IF WE FOUND A PHRASE/MULTIPLE PHRASES, THEN WE WANT THE ONE THAT MATCHES OUR //CRITERIA PHRASE IN TEXT AND LANGUAGE if (allPhrasesContainingPhrase.Count > 0) { retrievedPhrase = (from phrase in allPhrasesContainingPhrase where phrase.Text == criteriaPhrase.Text && phrase.Language.Text == criteriaPhrase.Language.Text select phrase).FirstOrDefault(); } if (retrievedPhrase != null && retrievedPhrase.IsChild) { //WE ONLY WANT NON-CHILD VERSIONS OF PHRASE var nonChildVersion = PhraseEdit.GetPhraseEdit(retrievedPhrase.Id); RetrievedPhrases.Add(criteriaPhrase.Id, nonChildVersion); } else if (retrievedPhrase != null && !retrievedPhrase.IsChild) { //PHRASE IS ALREADY NOT A CHILD, SO ADD IT RetrievedPhrases.Add(criteriaPhrase.Id, retrievedPhrase); } else { //NO RETRIEVED PHRASE, SO ADD NULL FOR THIS CRITERIAPHRASE.ID RetrievedPhrases.Add(criteriaPhrase.Id, null); } } }