//void saveRating(SecurityInfo SecurityInfo, Service.V2.Model.IRatingable ratingable, Profile profile, BodyArchitect.Model.IRatingable globalObject) //{ // var session = Session; // var ratingObject = (from rating in session.Query<RatingUserValue>() // where rating.ProfileId == profile.Id && rating.RatedObjectId == globalObject.GlobalId // select rating).SingleOrDefault(); // if (ratingable.UserRating != null)// && (ratingObject == null || ratingObject != null && ratingObject.Rating != ratingable.UserRating.Value)) // { // if (ratingObject == null) // { // ratingObject = new RatingUserValue(); // ratingObject.ProfileId = profile.Id; // ratingObject.RatedObjectId = globalObject.GlobalId; // } // ratingObject.LoginData = SecurityInfo.LoginData; // ratingObject.Rating = ratingable.UserRating.Value; // ratingObject.ShortComment = ratingable.UserShortComment; // ratingObject.VotedDate = Configuration.TimerService.UtcNow; // session.SaveOrUpdate(ratingObject); // ProfileStatisticsUpdater.UpdateVotings(session, profile); // //session.SaveOrUpdate(globalObject); // //var res = (from t in session.Query<RatingUserValue>() where t.RatedObjectId == globalObject.GlobalId select t).Average(t => t.Rating); // var res = session.QueryOver<RatingUserValue>().Where(t => t.RatedObjectId == globalObject.GlobalId). // SelectList(t => t.SelectAvg(r => r.Rating)).SingleOrDefault<double>(); // globalObject.Rating = (float)res; // ratingable.Rating = (float)res; // session.SaveOrUpdate(globalObject); // } //} //public SuplementDTO VoteSupplement(SuplementDTO supplement) //{ // Log.WriteWarning("VoteSupplement: Username={0},globalId={1}", SecurityInfo.SessionData.Profile.UserName, supplement.GlobalId); // var session = Session; // using (var tx = session.BeginTransaction()) // { // var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id); // var planFromDb = session.Get<Suplement>(supplement.GlobalId); // saveRating(SecurityInfo, supplement, dbProfile, planFromDb); // tx.Commit(); // try // { // //send message only when someone else vote // //if (planFromDb.Profile != null && planFromDb.Profile != dbProfile) // //{ // // if (planFromDb.Profile.Settings.NotificationExerciseVoted) // // { // // string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, exercise.UserRating); // // MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification); // // messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.ExerciseVoted); // // } // //} // } // catch (Exception ex) // { // ExceptionHandler.Default.Process(ex); // } // session.Refresh(planFromDb); // Mapper.Map(planFromDb, supplement); // return supplement; // } //} //public SupplementCycleDefinitionDTO VoteSupplementCycleDefinition(SupplementCycleDefinitionDTO definition) //{ // Log.WriteWarning("VoteSupplementCycleDefinition: Username={0},globalId={1}", SecurityInfo.SessionData.Profile.UserName, definition.GlobalId); // var session = Session; // using (var tx = session.BeginTransaction()) // { // var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id); // var planFromDb = session.Get<SupplementCycleDefinition>(definition.GlobalId); // saveRating(SecurityInfo, definition, dbProfile, planFromDb); // tx.Commit(); // try // { // //send message only when someone else vote // if (planFromDb.Profile != null && planFromDb.Profile != dbProfile) // { // if (planFromDb.Profile.Settings.NotificationWorkoutPlanVoted) // { // string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, definition.UserRating); // MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification); // messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.SupplementCycleDefinitionVoted); // } // } // } // catch (Exception ex) // { // ExceptionHandler.Default.Process(ex); // } // session.Refresh(planFromDb); // Mapper.Map(planFromDb, definition); // return definition; // } //} public PagedResult <CommentEntryDTO> GetComments(Guid globalId, PartialRetrievingInfo retrievingInfo) { Log.WriteWarning("GetComments: Username={0},globalId={1}", SecurityInfo.SessionData.Profile.UserName, globalId); var session = Session; //var res = (from rv in session.Query<RatingUserValue>() // from user in session.Query<Profile>() // where rv.RatedObjectId == globalId && rv.ProfileId == user.Id // orderby rv.VotedDate descending // select new { RatingValue = rv, Profile = user }); //int count = res.Count(); //TODO: I split this on two queries because of Fetch and Count problem. var resCount = (from rv in session.Query <RatingUserValue>() from user in session.Query <Profile>() where rv.RatedObjectId == globalId && rv.ProfileId == user.GlobalId orderby rv.VotedDate descending select new { RatingValue = rv }); int count = resCount.Count(); var res = (from rv in session.Query <RatingUserValue>().Fetch(x => x.LoginData).ThenFetch(x => x.ApiKey) from user in session.Query <Profile>() where rv.RatedObjectId == globalId && rv.ProfileId == user.GlobalId orderby rv.VotedDate descending select new { RatingValue = rv, Profile = user }); res = res.Skip(retrievingInfo.PageIndex * retrievingInfo.PageSize).Take(retrievingInfo.PageSize); List <CommentEntryDTO> comments = new List <CommentEntryDTO>(); foreach (var item in res.ToList()) { CommentEntryDTO comment = new CommentEntryDTO(); comment.User = Mapper.Map <Profile, UserDTO>(item.Profile); comment.Rating = item.RatingValue.Rating; comment.ShortComment = item.RatingValue.ShortComment; comment.VotedDate = item.RatingValue.VotedDate; if (item.RatingValue.LoginData != null && item.RatingValue.LoginData.ApiKey != null) { comment.ApplicationName = item.RatingValue.LoginData.ApiKey.ApplicationName; } comments.Add(comment); } PagedResult <CommentEntryDTO> result = new PagedResult <CommentEntryDTO>(comments, count, retrievingInfo.PageIndex); return(result); }
public VoteViewModel(CommentEntryDTO entry) { this.Entry = entry; }