public LikeMatching GetMostFrequentLikeMatchingByRecommendation(Recommendation pRecommendation) { using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { return pRecommendation.MostLikeMatching; } }
public List<LikeMatching> GetLikeMatchingsByRecommendation(Recommendation pRecommendation) { using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { return pRecommendation.LikeMatchings.ToList(); } }
public void DeleteRecommendation(Recommendation pRecommendation) { using (TransactionScope lScope = new TransactionScope()) using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { lContainer.Recommendations.DeleteObject(pRecommendation); lContainer.SaveChanges(); lScope.Complete(); } }
private void FixupRecommendation(Recommendation previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.LikeMatchings.Contains(this)) { previousValue.LikeMatchings.Remove(this); } if (Recommendation != null) { if (!Recommendation.LikeMatchings.Contains(this)) { Recommendation.LikeMatchings.Add(this); } RecommendationId = Recommendation.Id; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Recommendation") && (ChangeTracker.OriginalValues["Recommendation"] == Recommendation)) { ChangeTracker.OriginalValues.Remove("Recommendation"); } else { ChangeTracker.RecordOriginalValue("Recommendation", previousValue); } if (Recommendation != null && !Recommendation.ChangeTracker.ChangeTrackingEnabled) { Recommendation.StartTracking(); } } }
internal void FixupVideoStoreEntityModel_RecommendationLikeMatching1_RecommendationKeys(Recommendation value, bool forceRemove) { const string IdKeyName = "Navigate(VideoStoreEntityModel.RecommendationLikeMatching1.Recommendation).Id"; if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.ExtendedProperties.ContainsKey(IdKeyName)) { if (forceRemove || !Equals(ChangeTracker.ExtendedProperties[IdKeyName], value == null ? null : (object)value.Id)) { ChangeTracker.RecordOriginalValue(IdKeyName, ChangeTracker.ExtendedProperties[IdKeyName]); if (value == null) { ChangeTracker.ExtendedProperties.Remove(IdKeyName); } else { ChangeTracker.ExtendedProperties[IdKeyName] = value.Id; } } } }
public void UpdateRecommendation(Recommendation pRecommendation) { using (TransactionScope lScope = new TransactionScope()) using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { lContainer.Recommendations.Attach(pRecommendation); lContainer.ObjectStateManager.ChangeObjectState(pRecommendation, System.Data.EntityState.Modified); lContainer.SaveChanges(); lScope.Complete(); } }
public void UserLikeAnMedia(int pUserId, int pMediaId) { if (pUserId == null || pMediaId == null) { return; } using (TransactionScope lScope = new TransactionScope()) using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { lContainer.ContextOptions.LazyLoadingEnabled = false; var pUser = lContainer.Users.Include("Medium").FirstOrDefault(lUser => lUser.Id == pUserId); var pMedia = lContainer.Media.Include("Recommendation").Where(lMedia => lMedia.Id == pMediaId).FirstOrDefault(); if (pUser == null || pMedia == null) { return; } //get the List of the medias which are liked by this user List<Media> LikedMedium = pUser.Medium.ToList(); foreach( Media tMedia in LikedMedium ){ if (tMedia.Id == pMedia.Id) { return; } } // when no one has liked this Media before, create a recommendation model attached to this media if (pMedia.Recommendation == null) { Recommendation newRec = new Recommendation(); newRec.Medium = pMedia; newRec.MostLikeMatching = null; lContainer.Recommendations.AddObject(newRec); lContainer.SaveChanges(); } var pRecommendation = new Recommendation(); var curRecommendation = pMedia.Recommendation;// the recommendation of the new liked Media List<LikeMatching> pLikeMatchings = new List<LikeMatching>(); //iterate the media list & update all the LikeMatchings foreach (Media tMedia in LikedMedium) { // update LikeWatching list attached to every of the Recommendation of this media pRecommendation = lContainer.Recommendations.Include("LikeMatchings") .Where( (lRecommendation) => lRecommendation.Medium.Id == tMedia.Id ).FirstOrDefault(); //pLikeMatchings = pRecommendation.LikeMatchings.ToList(); pLikeMatchings = lContainer.LikeMatchings.Include("Medium").Where(lLikeMatching => lLikeMatching.Recommendation.Id == pRecommendation.Id).ToList(); LikeMatching MatchingToUpdate = GetLikeMatchingMediaIn(pMedia,pLikeMatchings); if( MatchingToUpdate != null ){ // if this media is in the previous LikeMatching list of //this recommendation, increment the count by 1 MatchingToUpdate.count++; lContainer.LikeMatchings.Attach(MatchingToUpdate); lContainer.ObjectStateManager.ChangeObjectState(MatchingToUpdate, System.Data.EntityState.Modified); } else{//add this media to the LikeMatching List of this Recommendation and set the count as 1 MatchingToUpdate = new LikeMatching(); MatchingToUpdate.Recommendation = pRecommendation; MatchingToUpdate.Medium = pMedia; MatchingToUpdate.count = 1; lContainer.LikeMatchings.AddObject(MatchingToUpdate); lContainer.SaveChanges(); } // recalculate the most frequently liked media of this Recomendtaion pRecommendation.MostLikeMatching = (from LikingItem in pRecommendation.LikeMatchings orderby LikingItem.count descending select LikingItem).FirstOrDefault(); lContainer.Recommendations.Attach(pRecommendation); lContainer.ObjectStateManager.ChangeObjectState(pRecommendation, System.Data.EntityState.Modified); //lContainer.SaveChanges(); //update the LikeMatching list for the new liked media List<LikeMatching> tLikeMatchings = lContainer.LikeMatchings.Include("Medium").Where(lLikeMatching => lLikeMatching.Recommendation.Id == curRecommendation.Id).ToList(); MatchingToUpdate = (from LikeItem in tLikeMatchings where LikeItem.Medium.Id == tMedia.Id select LikeItem).FirstOrDefault(); if (MatchingToUpdate != null) { // if this media is in the previous LikeMatching list of // this recommendation, increment the count by 1 MatchingToUpdate.count++; lContainer.LikeMatchings.Attach(MatchingToUpdate); lContainer.ObjectStateManager.ChangeObjectState(MatchingToUpdate, System.Data.EntityState.Modified); } else { // add this media to the LikeMatching List of this Recommendation and set the count as 1 MatchingToUpdate = new LikeMatching(); MatchingToUpdate.Recommendation = curRecommendation; MatchingToUpdate.Medium = tMedia; MatchingToUpdate.count = 1; lContainer.LikeMatchings.AddObject(MatchingToUpdate); lContainer.SaveChanges(); } } // recalculate the most frequently liked media of this Recomendtaion curRecommendation.MostLikeMatching = (from LikingItem in curRecommendation.LikeMatchings orderby LikingItem.count descending select LikingItem).FirstOrDefault(); lContainer.Recommendations.Attach(curRecommendation); lContainer.ObjectStateManager.ChangeObjectState(curRecommendation, System.Data.EntityState.Modified); //put the media in this user's Media-like list pUser.Medium.Add(pMedia); lContainer.Users.Attach(pUser); lContainer.ObjectStateManager.ChangeObjectState(pUser, System.Data.EntityState.Modified); lContainer.SaveChanges(); lScope.Complete(); } }
private void FixupRecommendation(Recommendation previousValue) { if (IsDeserializing) { return; } if (previousValue != null && ReferenceEquals(previousValue.Medium, this)) { previousValue.Medium = null; } if (Recommendation != null) { Recommendation.Medium = this; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Recommendation") && (ChangeTracker.OriginalValues["Recommendation"] == Recommendation)) { ChangeTracker.OriginalValues.Remove("Recommendation"); } else { ChangeTracker.RecordOriginalValue("Recommendation", previousValue); } if (Recommendation != null && !Recommendation.ChangeTracker.ChangeTrackingEnabled) { Recommendation.StartTracking(); } } }