/// <summary> /// get all the LRF entities for a target with the specified type /// </summary> /// <param name="targetId"></param> /// <param name="type"></param> /// <returns></returns> public virtual IEnumerable <LikeRateFavEntity> GetAllLrfFor(Guid targetId, LRFType type) { Dictionary <string, object> queryDict = new Dictionary <string, object>(); queryDict.Add("TargetId", targetId); queryDict.Add("Type", type); var query = getNewQueryObject(); query.AppendQuery(queryDict, QueryLogic.And); return(EntityRepository.Find(query)); }
/// <summary> /// get many time is a target been likeed/rated/faved /// </summary> /// <param name="targetId"></param> /// <param name="type"></param> /// <returns></returns> public virtual int GetLRFCount(Guid targetId, LRFType type) { Dictionary <string, object> queryDict = new Dictionary <string, object>(); queryDict.Add("TargetId", targetId); queryDict.Add("Type", type); var query = getNewQueryObject(); query.AppendQuery(queryDict, QueryLogic.And); return(EntityRepository.Find(query).Count()); }
/// <summary> /// get all target ids that LRF by the user, /// </summary> /// <param name="ownerId"></param> /// <param name="type"></param> /// <returns></returns> public virtual IEnumerable <Guid> GetAllMyLRFIds(Guid ownerId, LRFType type) { Dictionary <string, object> queryDict = new Dictionary <string, object>(); queryDict.Add("OwnerId", ownerId); queryDict.Add("Type", type); var query = getNewQueryObject(); query.AppendQuery(queryDict, QueryLogic.And); return(EntityRepository.Find(query).Select(e => e.TargetId)); }
/// <summary> /// return if i like rated faved a target /// </summary> /// <param name="ownerId"></param> /// <param name="targetId"></param> /// <returns></returns> public virtual bool DoILikeRateFav(Guid ownerId, Guid targetId, LRFType type) { Dictionary <string, object> queryDict = new Dictionary <string, object>(); queryDict.Add("OwnerId", ownerId); queryDict.Add("TargetId", targetId); queryDict.Add("Type", type); var query = getNewQueryObject(); query.AppendQuery(queryDict, QueryLogic.And); return(EntityRepository.Find(query).Any()); }
/// <summary> /// clear all my ratings, fav, like, /// </summary> /// <param name="userId"></param> /// <param name="targetId"></param> public virtual void ClearMyLRF(Guid userId, Guid targetId, LRFType type) { Dictionary <string, object> queryDict = new Dictionary <string, object>(); queryDict.Add("OwnerId", userId); queryDict.Add("TargetId", targetId); queryDict.Add("Type", type); var query = getNewQueryObject(); query.AppendQuery(queryDict, QueryLogic.And); EntityRepository.Delete(query); }
/// <summary> /// Toggle a Favorite or Like of a target /// </summary> /// <param name="userId"></param> /// <param name="targetId"></param> /// <param name="type">olny accepte like or favorite</param> /// <returns>the new state for this target</returns> public bool ToggleLikeFav(Guid userId, Guid targetId, LRFType type) { if (type != LRFType.Like && type != LRFType.Favorate) { throw new Exception("olny accepte like or favorite"); } if (DoILikeRateFav(userId, targetId, type)) { ClearMyLRF(userId, targetId, type); return(false); } else { EntityRepository.SaveOne( new LikeRateFavEntity { OwnerId = userId, TargetId = targetId, Type = type }); return(true); } }