public static LanguageData ToData(LanguageDto dto, LearnLanguagesContext context) { //CREATE DATA OBJECT var languageData = context.LanguageDatas.CreateObject(); //ASSIGN SIMPLE PROPERTIES languageData.Id = dto.Id; languageData.Text = dto.Text; languageData.UserDataId = dto.UserId; //POPULATE USERDATA var results = (from u in context.UserDatas where u.Id == dto.UserId select u); if (results.Count() == 1) { var userData = results.First(); //MAKE SURE USERNAMES MATCH if (userData.Username != dto.Username) throw new ArgumentException("languageDto dto"); languageData.UserData = results.First(); } else if (results.Count() == 0) throw new Exceptions.UsernameAndUserIdDoNotMatchException(dto.Username, dto.UserId); else throw new Exceptions.VeryBadException( string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero)); //RETURN return languageData; }
/// <summary> /// Adds the TranslationDto to the context, loading UserData and PhraseDatas into the newly /// created PhraseData. Does NOT save changes to the context. /// </summary> /// <param name="dto"></param> /// <param name="learnLanguagesContext"></param> /// <returns></returns> public static TranslationData AddToContext(TranslationDto dto, LearnLanguagesContext context) { //CREATE NEW TRANSLATIONDATA var newTranslationData = context.TranslationDatas.CreateObject(); //ASSIGN USER INFO newTranslationData.UserDataId = dto.UserId; //var userResults = (from user in context.UserDatas // where user.Id == dto.UserId // select user); //if (userResults.Count() == 1) // newTranslationData.UserData = userResults.First(); //else if (userResults.Count() == 0) // throw new Exceptions.IdNotFoundException(dto.UserId); //else //{ // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); //} //GET AND ADD PHRASEDATAS TO TRANSLATIONDATA if (dto.PhraseIds != null) { foreach (var id in dto.PhraseIds) { var results = (from phrase in context.PhraseDatas where phrase.Id == id select phrase); if (results.Count() == 1) { var phraseData = results.First(); newTranslationData.PhraseDatas.Add(phraseData); } else if (results.Count() == 0) throw new Exceptions.IdNotFoundException(id); else { var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } } } //ADD TRANSLATIONDATA TO CONTEXT context.TranslationDatas.AddObject(newTranslationData); return newTranslationData; }
/// <summary> /// Adds the lineDto to the context, loading UserData and PhraseData into the newly /// created LineData. Does NOT save changes to the context. /// </summary> public static LineData AddToContext(LineDto dto, LearnLanguagesContext context) { //only creates, does not add to linedatas //var beforeCount = context.LineDatas.Count(); var newLineData = context.LineDatas.CreateObject(); //var afterCount = context.LineDatas.Count(); //assign properties newLineData.LineNumber = dto.LineNumber; newLineData.PhraseDataId = dto.PhraseId; newLineData.UserDataId = dto.UserId; context.LineDatas.AddObject(newLineData); return newLineData; }
/// <summary> /// Adds the phraseDto to the context, loading UserData and LanguageData into the newly /// created PhraseData. Does NOT save changes to the context. /// </summary> public static PhraseData AddToContext(PhraseDto dto, LearnLanguagesContext context) { //only creates, does not add to phrasedatas //var beforeCount = context.PhraseDatas.Count(); var newPhraseData = context.PhraseDatas.CreateObject(); //var afterCount = context.PhraseDatas.Count(); //assign properties newPhraseData.Text = dto.Text; newPhraseData.LanguageDataId = dto.LanguageId; newPhraseData.UserDataId = dto.UserId; context.PhraseDatas.AddObject(newPhraseData); return newPhraseData; }
private void Initialize() { var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; var isBackground = System.Threading.Thread.CurrentThread.IsBackground; var isPool = System.Threading.Thread.CurrentThread.IsThreadPoolThread; using (LearnLanguagesContext context = new LearnLanguagesContext()) { bool databaseExists = context.DatabaseExists(); bool deleteAll = bool.Parse(EfResources.DeleteAllExistingDataAndStartNewSeedData); //if (context.DatabaseExists() && bool.Parse(EfResources.DeleteAllExistingDataAndStartNewSeedData)) if (databaseExists && deleteAll) context.DeleteDatabase(); if (!context.DatabaseExists()) { context.CreateDatabase(); context.Connection.Open(); SeedContext(context); context.SaveChanges(); } } }
public static void LoadDataFromDto(ref PhraseBeliefData data, PhraseBeliefDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //PHRASE data.PhraseDataId = dto.PhraseId; data.PhraseData = EfHelper.GetPhraseData(dto.PhraseId, context); //SCALAR data.ReviewMethodId = dto.ReviewMethodId; data.Strength = dto.Strength; data.Text = dto.Text; data.TimeStamp = dto.TimeStamp; }
public static void LoadDataFromDto(ref StudyDataData data, StudyDataDto dto, LearnLanguagesContext context) { data.NativeLanguageText = dto.NativeLanguageText; data.Username = dto.Username; }
public static void LoadDataFromDto(ref LineData data, LineDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //PHRASE INFO data.PhraseDataId = dto.PhraseId; data.PhraseData = EfHelper.GetPhraseData(dto.PhraseId, context); //TEXT data.LineNumber = dto.LineNumber; }
/// <summary> /// Loads the information from the dto into the data object. Except... /// Does NOT load dto.Id. /// </summary> /// <param name="data"></param> /// <param name="dto"></param> public static void LoadDataFromDto(ref LanguageData data, LanguageDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //MAKE SURE USERDATA USERNAME MATCHES DTO.USERNAME if (data.UserData.Username != dto.Username) throw new Exceptions.UsernameAndUserIdDoNotMatchException(dto.Username, dto.UserId); //TEXT data.Text = dto.Text; }
public static UserData GetUserData(Guid id, LearnLanguagesContext context) { var results = (from user in context.UserDatas where user.Id == id select user); if (results.Count() == 1) return results.First(); else if (results.Count() == 0) throw new Exceptions.IdNotFoundException(id); else { var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } }
/// <summary> /// Adds the dto to the context. /// /// Does NOT save changes to the context. /// </summary> public static UserData AddToContext(UserDto dto, LearnLanguagesContext context) { //CREATE NEW DATA var data = context.UserDatas.CreateObject(); //LOAD DATA LoadDataFromDto(ref data, dto, context); #region commented out manual loading (i'm trying to replace this with efhelper method loaddatafromdto()) //#region ASSIGN SCALARS //data.Username = dto.Username; //data.Salt = dto.Salt; //data.SaltedHashedPasswordValue = dto.SaltedHashedPasswordValue; //#endregion //#region ASSIGN COLLECTIONS ////ADD LINE DATAS FROM DTO.LINEIDS //if (dto.LineIds != null) //{ // foreach (var id in dto.LineIds) // { // var results = (from line in context.LineDatas // where line.Id == id // select line); // if (results.Count() == 1) // { // var lineData = results.First(); // data.LineDatas.Add(lineData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} ////ADD PHRASE BELIEF DATAS FROM DTO.PHRASE BELIEF IDS //if (dto.PhraseBeliefIds != null) //{ // foreach (var id in dto.PhraseBeliefIds) // { // var results = (from belief in context.PhraseBeliefDatas // where belief.Id == id // select belief); // if (results.Count() == 1) // { // var beliefData = results.First(); // data.PhraseBeliefDatas.Add(beliefData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} ////ADD PHRASE DATAS FROM DTO.PHRASE IDS //if (dto.PhraseIds != null) //{ // foreach (var id in dto.PhraseIds) // { // var results = (from phrase in context.PhraseDatas // where phrase.Id == id // select phrase); // if (results.Count() == 1) // { // var phraseData = results.First(); // data.PhraseDatas.Add(phraseData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} ////ADD ROLE DATAS FROM DTO.ROLE IDS //if (dto.RoleIds != null) //{ // foreach (var id in dto.RoleIds) // { // var results = (from role in context.RoleDatas // where role.Id == id // select role); // if (results.Count() == 1) // { // var roleData = results.First(); // data.RoleDatas.Add(roleData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} ////ADD TRANSLATION DATAS FROM DTO.TRANSLATION IDS //if (dto.TranslationIds != null) //{ // foreach (var id in dto.TranslationIds) // { // var results = (from translation in context.TranslationDatas // where translation.Id == id // select translation); // if (results.Count() == 1) // { // var translationData = results.First(); // data.TranslationDatas.Add(translationData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} ////ADD MLT DATAS FROM DTO.MLT IDS //if (dto.MultiLineTextIds != null) //{ // foreach (var id in dto.MultiLineTextIds) // { // var results = (from mlt in context.MultiLineTextDatas // where mlt.Id == id // select mlt); // if (results.Count() == 1) // { // var mltData = results.First(); // data.MultiLineTextDatas.Add(mltData); // } // else if (results.Count() == 0) // throw new Exceptions.IdNotFoundException(id); // else // { // var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, // DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); // throw new Exceptions.VeryBadException(errorMsg); // } // } //} //#endregion #endregion //ADD DATA TO CONTEXT context.UserDatas.AddObject(data); return data; }
/// <summary> /// Adds the dto to the context, loading UserData and LineDatas into the newly /// created PhraseBeliefData. Does NOT save changes to the context. /// </summary> public static MultiLineTextData AddToContext(MultiLineTextDto dto, LearnLanguagesContext context) { //CREATE NEW TRANSLATIONDATA var data = context.MultiLineTextDatas.CreateObject(); //SCALARS data.Title = dto.Title; data.AdditionalMetadata = dto.AdditionalMetadata; //ASSIGN USER INFO data.UserDataId = dto.UserId; //ADD LINE DATAS FROM DTO.LINEIDS if (dto.LineIds != null) { foreach (var id in dto.LineIds) { var results = (from line in context.LineDatas where line.Id == id select line); if (results.Count() == 1) { var lineData = results.First(); data.LineDatas.Add(lineData); } else if (results.Count() == 0) throw new Exceptions.IdNotFoundException(id); else { var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } } } //ADD DATA TO CONTEXT context.MultiLineTextDatas.AddObject(data); return data; }
/// <summary> /// Adds the PhraseBeliefDto to the context, loading UserData and PhraseDatas into the newly /// created PhraseBeliefData. Does NOT save changes to the context. /// </summary> public static PhraseBeliefData AddToContext(PhraseBeliefDto dto, LearnLanguagesContext context) { //CREATE THE NEW OBJECT var data = context.PhraseBeliefDatas.CreateObject(); //ASSIGN PROPERTIES data.PhraseDataId = dto.PhraseId; data.ReviewMethodId = dto.ReviewMethodId; data.Strength = dto.Strength; data.BelieverId = dto.BelieverId; data.Text = dto.Text; data.TimeStamp = dto.TimeStamp; data.UserDataId = dto.UserId; //ADD OBJECT TO CONTEXT context.PhraseBeliefDatas.AddObject(data); //RETURN OBJECT return data; }
/// <summary> /// Adds the StudyDataDto to the context, loading UserData and PhraseDatas into the newly /// created PhraseData. Does NOT save changes to the context. /// </summary> public static StudyDataData AddToContext(StudyDataDto dto, LearnLanguagesContext context) { //CREATE THE NEW OBJECT var newStudyDataData = context.StudyDataDatas.CreateObject(); //ASSIGN PROPERTIES newStudyDataData.NativeLanguageText = dto.NativeLanguageText; newStudyDataData.Username = dto.Username; //ADD OBJECT TO CONTEXT context.StudyDataDatas.AddObject(newStudyDataData); //RETURN OBJECT return newStudyDataData; }
private static PhraseData GetPhraseData(Guid phraseId, LearnLanguagesContext context) { var currentUserId = ((CustomIdentity)Csla.ApplicationContext.User.Identity).UserId; var results = from phraseData in context.PhraseDatas where phraseData.Id == phraseId && phraseData.UserDataId == currentUserId select phraseData; if (results.Count() == 1) return results.First(); else if (results.Count() == 0) throw new Exceptions.IdNotFoundException(phraseId); else { var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } }
public static void LoadDataFromDto(ref MultiLineTextData data, MultiLineTextDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //LINE IDS foreach (var id in dto.LineIds) { LineData lineData = EfHelper.GetLineData(id, context); data.LineDatas.Add(lineData); } //SCALAR data.Title = dto.Title; data.AdditionalMetadata = dto.AdditionalMetadata; }
public static void LoadDataFromDto(ref UserData userData, UserDto dto, LearnLanguagesContext context) { //SCALAR userData.Username = dto.Username; userData.Salt = dto.Salt; userData.SaltedHashedPasswordValue = dto.SaltedHashedPasswordValue; //NAVIGATION PROPERTIES //Guid navPropId = default(Guid); ICollection<Guid> ids = null; //LANGUAGES ids = dto.LanguageIds; foreach (var id in ids) { var data = EfHelper.GetLanguageData(id, context); userData.LanguageDatas.Add(data); } //LINES ids = dto.LineIds; foreach (var id in ids) { var data = EfHelper.GetLineData(id, context); userData.LineDatas.Add(data); } //MultiLineText ids = dto.MultiLineTextIds; foreach (var id in ids) { var data = EfHelper.GetMultiLineTextData(id, context); userData.MultiLineTextDatas.Add(data); } //PHRASE BELIEF ids = dto.PhraseBeliefIds; foreach (var id in ids) { var data = EfHelper.GetPhraseBeliefData(id, context); userData.PhraseBeliefDatas.Add(data); } //PHRASE ids = dto.PhraseIds; foreach (var id in ids) { var data = EfHelper.GetPhraseData(id, context); userData.PhraseDatas.Add(data); } //ROLE ids = dto.RoleIds; foreach (var id in ids) { var data = EfHelper.GetRoleData(id, context); userData.RoleDatas.Add(data); } //TRANSLATION ids = dto.TranslationIds; foreach (var id in ids) { var data = EfHelper.GetTranslationData(id, context); userData.TranslationDatas.Add(data); } }
public static int GenerateNewUniqueSalt(LearnLanguagesContext context) { var salt = -1; bool saltAlreadyExists = true; Random r = new Random(DateTime.Now.Millisecond * DateTime.Now.Minute * DateTime.Now.Month); int maxSaltTries = int.Parse(DalResources.MaxTriesGenerateSalt); int tries = 0; do { salt = r.Next(int.Parse(DataAccess.DalResources.MaxSaltValue)); saltAlreadyExists = (from userData in context.UserDatas where userData.Salt == salt select userData).Count() > 0; tries++; if (tries > maxSaltTries) throw new DataAccess.Exceptions.GeneralDataAccessException("MaxTries for generating salt reached."); } while (saltAlreadyExists); return salt; }
public static MultiLineTextData GetMultiLineTextData(Guid id, LearnLanguagesContext context) { var currentUserId = Business.BusinessHelper.GetCurrentUserId(); var results = from mltData in context.MultiLineTextDatas where mltData.Id == id && mltData.UserDataId == currentUserId select mltData; if (results.Count() == 1) return results.First(); else if (results.Count() == 0) throw new Exceptions.IdNotFoundException(id); else { var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } }
/// <summary> /// Loads the information from the dto into the data object. Except... /// Does NOT load dto.Id. /// </summary> /// <param name="data"></param> /// <param name="dto"></param> public static void LoadDataFromDto(ref TranslationData data, TranslationDto dto, LearnLanguagesContext context) { //COPY USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); var currentPhraseIds = (from phrase in data.PhraseDatas select phrase.Id); //COPY PHRASEID INFO //ADD NEW PHRASEDATAS IN THE DTO foreach (var id in dto.PhraseIds) { if (!currentPhraseIds.Contains(id)) { PhraseData phraseData = EfHelper.GetPhraseData(id, context); data.PhraseDatas.Add(phraseData); } } //REMOVE PHRASEDATAS THAT ARE NOT IN DTO ANYMORE foreach (var phraseId in currentPhraseIds) { if (!dto.PhraseIds.Contains(phraseId)) { var dataToRemove = (from phraseData in data.PhraseDatas where phraseData.Id == phraseId select phraseData).First(); data.PhraseDatas.Remove(dataToRemove); } } }
private void SeedContext(LearnLanguagesContext context) { //ROLES foreach (var roleDto in SeedData.Ton.Roles) { var roleData = EfHelper.ToData(roleDto); context.RoleDatas.AddObject(roleData); context.SaveChanges(); //UPDATE SEED DATA THAT REFERENCES THE ID OF THIS DATA var affectedUsers = (from userDto in SeedData.Ton.Users where userDto.RoleIds.Contains(roleDto.Id) select userDto).ToList(); foreach (var affectedUser in affectedUsers) { affectedUser.RoleIds.Remove(roleDto.Id); affectedUser.RoleIds.Add(roleData.Id); } roleDto.Id = roleData.Id; } //USERS foreach (var userDto in SeedData.Ton.Users) { //var userData = EfHelper.ToData(userDto, false); var userData = context.UserDatas.CreateObject(); userData.Id = userDto.Id; userData.Username = userDto.Username; userData.Salt = userDto.Salt; userData.SaltedHashedPasswordValue = userDto.SaltedHashedPasswordValue; //manually add roles (cannot use dal.getroles because we are seeding //the data and initializing the context that would use) foreach (var roleId in userDto.RoleIds) { var userRoleData = (from roleData in context.RoleDatas where roleData.Id == roleId select roleData).First(); if (userRoleData == null) throw new Exceptions.SeedDataException(); userData.RoleDatas.Add(userRoleData); } context.UserDatas.AddObject(userData); context.SaveChanges(); #region UPDATE AFFECTED SEED DATA THAT REFERENCES THE ID OF THIS USER var affectedLanguages = (from languageDto in SeedData.Ton.Languages where languageDto.UserId == userDto.Id select languageDto); foreach (var affectedLanguage in affectedLanguages) { affectedLanguage.UserId = userData.Id; } var affectedPhrases = (from phraseDto in SeedData.Ton.Phrases where phraseDto.UserId == userDto.Id select phraseDto); foreach (var affectedPhrase in affectedPhrases) { affectedPhrase.UserId = userData.Id; } var affectedTranslations = (from translationDto in SeedData.Ton.Translations where translationDto.UserId == userDto.Id select translationDto); foreach (var affectedTranslation in affectedTranslations) { affectedTranslation.UserId = userData.Id; } var affectedLines = (from lineDto in SeedData.Ton.Lines where lineDto.UserId == userDto.Id select lineDto); foreach (var affectedLine in affectedLines) { affectedLine.UserId = userData.Id; } var affectedMultiLineTexts = (from multiLineTextDto in SeedData.Ton.MultiLineTexts where multiLineTextDto.UserId == userDto.Id select multiLineTextDto); foreach (var affectedMultiLineText in affectedMultiLineTexts) { affectedMultiLineText.UserId = userData.Id; } var affectedPhraseBeliefs = (from phraseBeliefDto in SeedData.Ton.PhraseBeliefs where phraseBeliefDto.UserId == userDto.Id select phraseBeliefDto); foreach (var affectedPhraseBelief in affectedPhraseBeliefs) { affectedPhraseBelief.UserId = userData.Id; } userDto.Id = userData.Id; #endregion } //LANGUAGES foreach (var langDto in SeedData.Ton.Languages) { var langData = EfHelper.ToData(langDto, context); context.LanguageDatas.AddObject(langData); context.SaveChanges(); //UPDATE SEED DATA PHRASES WITH NEW LANGUAGE ID var affectedPhrases = (from phraseDto in SeedData.Ton.Phrases where phraseDto.LanguageId == langDto.Id select phraseDto).ToList(); foreach (var phraseDto in affectedPhrases) { phraseDto.LanguageId = langData.Id;//new Id } langDto.Id = langData.Id; } //PHRASES foreach (var phraseDto in SeedData.Ton.Phrases) { var phraseData = EfHelper.AddToContext(phraseDto, context); //var phraseData = EfHelper.ToData(phraseDto); //context.PhraseDatas.AddObject(phraseData); context.SaveChanges(); //UPDATE SEED DATA THAT REFERENCES THE ID OF THIS DATA var affectedUsers = (from userDto in SeedData.Ton.Users where userDto.PhraseIds.Contains(phraseDto.Id) select userDto);//.ToList(); foreach (var affectedUser in affectedUsers) { affectedUser.PhraseIds.Remove(phraseDto.Id); affectedUser.PhraseIds.Add(phraseData.Id); } var affectedTranslations = (from translationDto in SeedData.Ton.Translations where translationDto.PhraseIds.Contains(phraseDto.Id) select translationDto); foreach (var affectedTranslation in affectedTranslations) { affectedTranslation.PhraseIds.Remove(phraseDto.Id); affectedTranslation.PhraseIds.Add(phraseData.Id); } var affectedLines = (from lineDto in SeedData.Ton.Lines where lineDto.PhraseId == phraseDto.Id select lineDto); foreach (var affectedLine in affectedLines) { affectedLine.PhraseId = phraseData.Id; } phraseDto.Id = phraseData.Id; } //TRANSLATIONS foreach (var translationDto in SeedData.Ton.Translations) { var translationData = EfHelper.AddToContext(translationDto, context); context.SaveChanges(); //UPDATE USERS var affectedUsers = (from userDto in SeedData.Ton.Users where userDto.TranslationIds.Contains(translationDto.Id) select userDto).ToList(); foreach (var affectedUser in affectedUsers) { affectedUser.PhraseIds.Remove(translationDto.Id); affectedUser.PhraseIds.Add(translationData.Id); } translationDto.Id = translationData.Id; } //LINES foreach (var lineDto in SeedData.Ton.Lines) { var lineData = EfHelper.AddToContext(lineDto, context); context.SaveChanges(); //UPDATE USERS var affectedUsers = (from userDto in SeedData.Ton.Users where userDto.LineIds.Contains(lineDto.Id) select userDto).ToList(); foreach (var affectedUser in affectedUsers) { affectedUser.LineIds.Remove(lineDto.Id); affectedUser.LineIds.Add(lineDto.Id); } lineDto.Id = lineData.Id; } //STUDY DATAS foreach (var studyDataDto in SeedData.Ton.StudyDatas) { var studyDataData = EfHelper.AddToContext(studyDataDto, context); context.SaveChanges(); ////UPDATE USERS //var affectedUsers = (from userDto in SeedData.Ton.Users // where userDto.TranslationIds.Contains(studyDataDto.Id) // select userDto).ToList(); //foreach (var affectedUser in affectedUsers) //{ // affectedUser.PhraseIds.Remove(studyDataDto.Id); // affectedUser.PhraseIds.Add(studyDataDto.Id); //} studyDataDto.Id = studyDataData.Id; } }
/// <summary> /// Loads the information from the dto into the data object. Except... /// Does NOT load dto.Id. /// </summary> /// <param name="data"></param> /// <param name="dto"></param> public static void LoadDataFromDto(ref PhraseData data, PhraseDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //LANGUAGE INFO data.LanguageDataId = dto.LanguageId; data.LanguageData = EfHelper.GetLanguageData(dto.LanguageId, context); //TEXT data.Text = dto.Text; //TRANSLATIONDATAS data.TranslationDatas.Load(); }