public VoteResult Vote(VoteParams voteParams) { Log.WriteWarning("Vote: Username={0},globalId={1},type={2}", SecurityInfo.SessionData.Profile.UserName, voteParams.GlobalId, voteParams.ObjectType); var session = Session; using (var tx = session.BeginSaveTransaction()) { var dbProfile = session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); bool sendMessage = false; ISortable planFromDb = null; if (voteParams.ObjectType == VoteObject.SupplementCycleDefinition) { planFromDb = session.Get <SupplementCycleDefinition>(voteParams.GlobalId); sendMessage = true; } else if (voteParams.ObjectType == VoteObject.Exercise) { planFromDb = session.Get <Exercise>(voteParams.GlobalId); sendMessage = true; } else if (voteParams.ObjectType == VoteObject.WorkoutPlan) { planFromDb = session.Get <TrainingPlan>(voteParams.GlobalId); sendMessage = true; } else if (voteParams.ObjectType == VoteObject.Supplement) { planFromDb = session.Get <Suplement>(voteParams.GlobalId); } ProfileNotification notificationType = planFromDb.Profile != null ? planFromDb.Profile.Settings.NotificationVoted : ProfileNotification.None; VoteResult result = new VoteResult(); result.Rating = saveRating(SecurityInfo, voteParams, dbProfile, planFromDb); try { //send message only when someone else vote if (planFromDb.Profile != null && planFromDb.Profile != dbProfile && sendMessage) { //SendMessage(notificationType, dbProfile, planFromDb.Profile, messageFormat, messageTypeToSend.Value, "VoteEMailSubject", "VoteEMailMessage", DateTime.Now, dbProfile.UserName, planFromDb.Name, voteParams.UserRating); NewSendMessageEx(notificationType, dbProfile, planFromDb.Profile, "VoteEMailSubject", "VoteEMailMessage", DateTime.Now, dbProfile.UserName, planFromDb.Name, voteParams.UserRating); } } catch (Exception ex) { ExceptionHandler.Default.Process(ex); } tx.Commit(); return(result); } }
//protected void SendMessage(ProfileNotification notificationType, Profile sender, Profile receiver, string messageFormat, MessageType messageType, string emailSubject, string emailMessage, params object[] args) //{ // if ((notificationType & ProfileNotification.Message) == ProfileNotification.Message) // { // MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification); // messageService.SendSystemMessage(messageFormat, sender, receiver, messageType); // } // if ((notificationType & ProfileNotification.Email) == ProfileNotification.Email) // { // emailService.SendEMail(receiver, emailSubject, emailMessage, args); // } //} protected void NewSendMessage(ISession session, ProfileNotification notificationType, Profile sender, Profile receiver, string emailSubject, string emailMessage) { if (receiver.Statistics.LastLoginDate != null && receiver.Statistics.LastLoginDate < Configuration.TimerService.UtcNow.AddMonths(-1)) {//not active account (user didn't login for 1 month) so skip sending system messages return; } if ((notificationType & ProfileNotification.Message) == ProfileNotification.Message) { MessageService messageService = new MessageService(session, SecurityInfo, Configuration, pushNotification); messageService.NewSendSystemMessage(emailMessage, emailSubject, sender, receiver); } if ((notificationType & ProfileNotification.Email) == ProfileNotification.Email) { emailService.NewSendEMail(receiver, emailSubject, emailMessage); } }
protected void NewSendMessageEx(ProfileNotification notificationType, Profile sender, Profile receiver, string keySubject, string keyMessage, params object[] args) { if (Configuration == null || pushNotification == null || (receiver.Statistics.LastLoginDate != null && receiver.Statistics.LastLoginDate < Configuration.TimerService.UtcNow.AddMonths(-1))) {//not active account (user didn't login for 1 month) so skip sending system messages return; } var culture = receiver.GetProfileCulture(); var subject = string.Format(LocalizedStrings.ResourceManager.GetString(keySubject, culture), args); var message = string.Format(LocalizedStrings.ResourceManager.GetString(keyMessage, culture), args); if ((notificationType & ProfileNotification.Message) == ProfileNotification.Message) { MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification); messageService.NewSendSystemMessage(message, subject, sender, receiver); } if ((notificationType & ProfileNotification.Email) == ProfileNotification.Email) { emailService.NewSendEMail(receiver, subject, message); } }