private static ComparisonRuleExample GetOrCreateComparisonRuleExample(long comparisonRuleId, long sentenceTranslationId, string description, int order, StudyLanguageContext c) { ComparisonRuleExample comparisonRuleExample = c.ComparisonRuleExample.FirstOrDefault( e => e.ComparisonRuleId == comparisonRuleId && e.SentenceTranslationId == sentenceTranslationId); if (comparisonRuleExample == null) { comparisonRuleExample = new ComparisonRuleExample { ComparisonRuleId = comparisonRuleId, SentenceTranslationId = sentenceTranslationId }; c.ComparisonRuleExample.Add(comparisonRuleExample); } comparisonRuleExample.Description = description; comparisonRuleExample.Order = order; c.SaveChanges(); return(comparisonRuleExample); }
private static ComparisonItem GetOrCreateComparisonItem(ComparisonItemForUser comparisonItemForUser, long groupComparisonId, int order, StudyLanguageContext c) { ComparisonItem comparisonItem = c.ComparisonItem.FirstOrDefault( e => e.GroupComparisonId == groupComparisonId && e.Title == comparisonItemForUser.Title); if (comparisonItem == null) { comparisonItem = new ComparisonItem { GroupComparisonId = groupComparisonId, Title = comparisonItemForUser.Title }; c.ComparisonItem.Add(comparisonItem); } comparisonItem.TitleTranslation = comparisonItemForUser.TitleTranslated; comparisonItem.Description = comparisonItemForUser.Description; comparisonItem.Order = order; c.SaveChanges(); return(comparisonItem); }
private RepresentationForUser GetOrCreateRepresentation(RepresentationForUser representationForUser, StudyLanguageContext c) { Size size = representationForUser.Size; Representation representation = c.Representation.FirstOrDefault( e => e.Title == representationForUser.Title && e.LanguageId == _languageId); if (representation == null) { representation = new Representation { Title = representationForUser.Title, IsVisible = true, LanguageId = _languageId }; c.Representation.Add(representation); } representation.Image = representationForUser.Image; representation.Width = size.Width; representation.Height = size.Height; representation.WidthPercent = representationForUser.WidthPercent; representation.LastModified = DateTime.Now; c.SaveChanges(); return(IdValidator.IsValid(representation.Id) ? new RepresentationForUser(representation) : null); }
private static RepresentationArea GetOrCreateArea(StudyLanguageContext c, long representationId, long wordTranslationId, RepresentationAreaForUser areaForUser) { RepresentationArea representationArea = c.RepresentationArea .FirstOrDefault(e => e.RepresentationId == representationId && e.WordTranslationId == wordTranslationId); if (representationArea == null) { representationArea = new RepresentationArea { RepresentationId = representationId, WordTranslationId = wordTranslationId }; c.RepresentationArea.Add(representationArea); } representationArea.LeftUpperX = areaForUser.LeftUpperCorner.X; representationArea.LeftUpperY = areaForUser.LeftUpperCorner.Y; representationArea.RightBottomX = areaForUser.RightBottomCorner.X; representationArea.RightBottomY = areaForUser.RightBottomCorner.Y; c.SaveChanges(); return(representationArea); }
private Data.Video.Video GetOrCreateVideo(VideoForUser videoForUser, byte[] image, int?rating, byte videoType, StudyLanguageContext c) { string title = videoForUser.Title; string htmlCode = videoForUser.HtmlCode; Data.Video.Video video = c.Video.FirstOrDefault( e => (e.Title == title || e.HtmlCode == htmlCode) && e.LanguageId == _languageId && e.Type == videoType); if (video == null) { video = new Data.Video.Video { IsVisible = true, Rating = rating, LanguageId = _languageId, Type = videoType }; c.Video.Add(video); } video.Title = title; video.HtmlCode = htmlCode; video.Image = image; video.LastModified = DateTime.Now; c.SaveChanges(); return(video); }
private static void DeleteRules(StudyLanguageContext c, long itemId, List <long> rulesIds) { IQueryable <ComparisonRule> rulesToDelete = c.ComparisonRule.Where(e => e.ComparisonItemId == itemId && !rulesIds.Contains(e.Id)); foreach (ComparisonRule ruleToDelete in rulesToDelete) { c.ComparisonRule.Remove(ruleToDelete); } c.SaveChanges(); }
private static void DeleteItems(StudyLanguageContext c, long comparisonId, List <long> itemsIds) { IQueryable <ComparisonItem> itemsToDelete = c.ComparisonItem.Where(e => e.GroupComparisonId == comparisonId && !itemsIds.Contains(e.Id)); foreach (ComparisonItem itemToDelete in itemsToDelete) { c.ComparisonItem.Remove(itemToDelete); } c.SaveChanges(); }
private static void DeleteRuleExamples(StudyLanguageContext c, long ruleId, List <long> examplesIds) { IQueryable <ComparisonRuleExample> examplesToDelete = c.ComparisonRuleExample.Where( e => e.ComparisonRuleId == ruleId && !examplesIds.Contains(e.Id)); foreach (ComparisonRuleExample exampleToDelete in examplesToDelete) { c.ComparisonRuleExample.Remove(exampleToDelete); } c.SaveChanges(); }
private static WordTranslation Create(byte[] image, int?rating, StudyLanguageContext context, Word sourceWord, Word translationWord) { WordTranslation wordTranslation = context.WordTranslation.Add(new WordTranslation { WordId1 = sourceWord.Id, WordId2 = translationWord.Id, Image = image, Rating = rating }); context.WordTranslation.Add(wordTranslation); context.SaveChanges(); return(wordTranslation); }
private GroupComparison GetOrCreateGroupComparison(ComparisonForUser comparisonForUser, StudyLanguageContext c) { GroupComparison groupComparison = c.GroupComparison.FirstOrDefault(e => e.Title == comparisonForUser.Title && e.LanguageId == _languageId); if (groupComparison == null) { groupComparison = new GroupComparison { Title = comparisonForUser.Title, LanguageId = _languageId }; c.GroupComparison.Add(groupComparison); } groupComparison.AdditionalInfo = comparisonForUser.GetAdditionalInfo(); groupComparison.Description = comparisonForUser.Description; groupComparison.LastModified = DateTime.Now; c.SaveChanges(); return(groupComparison); }
private static void DeleteOldVisualWords(StudyLanguageContext c, RepresentationForUser representationForUser) { var areasIds = new HashSet <long>(representationForUser.Areas.Select(e => e.Id)); bool needRemove = false; List <RepresentationArea> areas = c.RepresentationArea.Where(e => e.RepresentationId == representationForUser.Id).ToList(); foreach (RepresentationArea area in areas) { if (areasIds.Contains(area.Id)) { continue; } c.RepresentationArea.Remove(area); needRemove = true; } if (needRemove) { c.SaveChanges(); } }
private static ComparisonRule GetOrCreateComparisonRule(ComparisonRuleForUser comparisonRuleForUser, long comparisonItemId, int order, StudyLanguageContext c) { ComparisonRule comparisonRule = c.ComparisonRule.FirstOrDefault( e => e.ComparisonItemId == comparisonItemId && e.Description == comparisonRuleForUser.Description); if (comparisonRule == null) { comparisonRule = new ComparisonRule { ComparisonItemId = comparisonItemId, Description = comparisonRuleForUser.Description }; c.ComparisonRule.Add(comparisonRule); } comparisonRule.Order = order; c.SaveChanges(); return(comparisonRule); }