Exemplo n.º 1
0
        /// <summary>
        /// Returns remaining seconds of a battle for opening the battle (if it's pending) or completing the battle (if it's locked)
        /// </summary>
        /// <returns></returns>
        public static int GetRemainingSeconds(this VideoBattle videoBattle)
        {
            var now     = DateTime.UtcNow;
            var endDate = DateTime.UtcNow;

            if (videoBattle.VideoBattleStatus == VideoBattleStatus.Pending && videoBattle.VotingStartDate > now)
            {
                endDate = videoBattle.VotingStartDate;
            }
            else if (videoBattle.VideoBattleStatus == VideoBattleStatus.Open)
            {
                endDate = videoBattle.VotingEndDate;
            }
            var diffDate   = endDate.Subtract(now);
            var maxSeconds = Convert.ToInt32(diffDate.TotalSeconds);

            return(maxSeconds);
        }
Exemplo n.º 2
0
        public int SendXDaysToBattleEndNotificationToFollower(User receiver, VideoBattle videoBattle, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.xDaysToBattleStartNotification", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //find the remaining days to end of battle
            var timeSpan        = (int)Math.Ceiling(videoBattle.VotingEndDate.Subtract(DateTime.UtcNow).TotalDays);
            var formattedString = timeSpan > 1 ? string.Format("in {0} days", timeSpan) : "tomorrow";
            //tokens
            var tokens = new List <Token>
            {
                new Token("Battle.Title", videoBattle.Name, true),
                new Token("Battle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)), true),
                new Token("Battle.EndDaysString", formattedString, true)
            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, receiver);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = receiver.Email;
            var toName  = receiver.GetFullName().ToTitleCase();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Exemplo n.º 3
0
        public int SendVideoBattleJoinNotification(User challenger, User challengee, VideoBattle videoBattle, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.VideoBattleJoinNotification", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)), true),
                new Token("Challenger.Name", challengee.GetFullName(), true)
            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, challengee);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = challenger.Email;
            var toName  = challenger.GetFullName().ToTitleCase();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Exemplo n.º 4
0
        public int SendVideoBattleCompleteNotification(User customer, VideoBattle videoBattle, NotificationRecipientType recipientType, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate(recipientType == NotificationRecipientType.Participant ? "MobSocial.VideoBattleCompleteNotificationToParticipants" : "MobSocial.VideoBattleCompleteNotificationToVoters", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattles/VideoBattle/{1}", store.Url, videoBattle.Id), true),
            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, customer);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = customer.Email;
            var toName  = customer.GetFullName().ToTitleCase();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Exemplo n.º 5
0
 public int SendSomeoneChallengedYouForABattleNotification(User challenger, User challengee, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 6
0
 public void SendXDaysToBattleStartNotificationToParticipant(User receiver, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 7
0
 public void SendSponsorAppliedNotificationToBattleOwner(User owner, User sponsor, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 8
0
 public void SendVideoBattleDisqualifiedNotification(User challenger, User challengee, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 9
0
 public void SendVideoBattleCompleteNotification(User user, VideoBattle videoBattle, NotificationRecipientType recipientTypeUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 10
0
        public IHttpActionResult SaveVideoBattle(VideoBattleModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                VerboseReporter.ReportError("Missing required parameters or invalid data submitted", "save_video_battle");
                return RespondFailure();
            }

            //lets check if it's a new video battle or an edit is being performed
            VideoBattle videoBattle = null;
            if (model.Id == 0)
            {
                videoBattle = new VideoBattle {
                    ChallengerId = ApplicationContext.Current.CurrentUser.Id,
                    DateCreated = DateTime.UtcNow
                };
            }
            else
            {
                videoBattle = _videoBattleService.Get(model.Id);
            }

            videoBattle.DateUpdated = DateTime.UtcNow;
            videoBattle.Description = model.Description;
            videoBattle.VideoBattleStatus = BattleStatus.Pending;
            videoBattle.VideoBattleType = BattleType.Video;
            videoBattle.VideoBattleVoteType = BattleVoteType.SelectOneWinner; // Model.VideoBattleVoteType;
            videoBattle.Name = model.Name;
            videoBattle.MaximumParticipantCount = (int)Math.Round((decimal)model.MaximumParticipantCount);
            videoBattle.IsVotingPayable = model.MinimumVotingCharge > 0 && model.IsVotingPayable;
            videoBattle.CanVoterIncreaseVotingCharge = model.CanVoterIncreaseVotingCharge;
            videoBattle.MinimumVotingCharge = model.MinimumVotingCharge;
            videoBattle.ParticipantPercentagePerVote = model.ParticipantPercentagePerVote;
            videoBattle.IsSponsorshipSupported = model.IsSponsorshipSupported;
            videoBattle.MinimumSponsorshipAmount = model.MinimumSponsorshipAmount;
            videoBattle.SponsoredCashDistributionType = model.SponsoredCashDistributionType;
            videoBattle.AutomaticallyPostEventsToTimeline = model.AutomaticallyPostEventsToTimeline;
            if (model.Id == 0)
            {
                videoBattle.VotingStartDate = model.VotingStartDate.ToUniversalTime();
                videoBattle.VotingEndDate = model.VotingEndDate.ToUniversalTime();
                _videoBattleService.Insert(videoBattle);

                //post to timeline if required
                if (model.AutomaticallyPostEventsToTimeline)
                    _timelineAutoPublisher.Publish(videoBattle, TimelineAutoPostTypeNames.VideoBattle.Publish,
                        ApplicationContext.Current.CurrentUser.Id);
            }
            else
            {
                //its an update...if there is any participant who has accepted the challenge then acceptance date and voting date can only be extended and not shrinked
                if (model.VotingStartDate.ToUniversalTime() < videoBattle.VotingStartDate ||
                    model.VotingEndDate.ToUniversalTime() < videoBattle.VotingEndDate)
                {
                    //so this is the case. lets see if we have any participants who have accepted the challenge
                    var participants = _videoBattleParticipantService.GetVideoBattleParticipants(model.Id,
                        BattleParticipantStatus.ChallengeAccepted);
                    if (participants.Count > 0)
                    {
                        //nop, somebody has accepted the challenge. date can only be exended
                        VerboseReporter.ReportError("Acceptance and Voting dates can only be extended now, because a participant has accepted the challenge", "save_video_battle");
                        return RespondFailure();
                    }
                }
                videoBattle.VotingStartDate = model.VotingStartDate.ToUniversalTime();
                videoBattle.VotingEndDate = model.VotingEndDate.ToUniversalTime();
                if (CanEdit(videoBattle))
                    _videoBattleService.Update(videoBattle);
                else
                {
                    VerboseReporter.ReportError("Unauthorized", "save_video_battle");
                    return RespondFailure();
                }
            }
            return RespondSuccess(new {
                Id = videoBattle.Id,
                SeName = videoBattle.GetPermalink()
            });
        }
        public static string GetConsolidatedPrizesString(this VideoBattle battle,
                                                         List <VideoBattlePrize> allPrizes,
                                                         int?winnerPosition,
                                                         ISponsorService sponsorService,
                                                         ISettingService settingService,
                                                         IPaymentProcessingService paymentProcessingService,
                                                         IFormatterService formatterService,
                                                         ICreditService creditService,
                                                         BattleSettings battleSettings)
        {
            var battleOwnerPrizes = allPrizes.Where(x => !x.IsSponsored && (!winnerPosition.HasValue || x.WinnerPosition == winnerPosition.Value));
            var sponsoredPrizes   = allPrizes.Where(x => x.IsSponsored && (!winnerPosition.HasValue || x.WinnerPosition == winnerPosition.Value));

            var videoBattlePrizes      = battleOwnerPrizes as VideoBattlePrize[] ?? battleOwnerPrizes.ToArray();
            var totalPrizesAmountFixed = videoBattlePrizes.Where(x => x.PrizeType == BattlePrizeType.FixedAmount).Sum(x => x.PrizeAmount);

            var totalPrizesAmountPercentage = 0m;

            if (videoBattlePrizes.Any(x => x.PrizeType == BattlePrizeType.PercentageAmount))
            {
                var contextKeyName = string.Format(CreditContextKeyNames.BattleVote, battle.Id);
                //get spent credits for battle votes
                var credits = creditService.GetCredits(contextKeyName, null, CreditTransactionType.Spent);

                var orderSum    = credits.Sum(x => x.CreditCount);
                var netOrderSum = paymentProcessingService.GetNetAmountAfterPaymentProcessing(orderSum);

                var totalWinners = videoBattlePrizes.Count();

                //total voting amount from percentage
                totalPrizesAmountPercentage = netOrderSum -
                                              totalWinners * netOrderSum * battle.ParticipantPercentagePerVote / 100;
            }

            var sponsorships = sponsorService.GetSponsorsGrouped(null, battle.Id, BattleType.Video,
                                                                 SponsorshipStatus.Accepted);

            var sponsorshipAmount = sponsorships.Sum(x => x.SponsorshipAmount);

            //amount after payment processing
            var netSponsorshipAmount = paymentProcessingService.GetNetAmountAfterPaymentProcessing(sponsorshipAmount);

            var siteOwnerShare = netSponsorshipAmount * battleSettings.SiteOwnerVideoBattleSponsorshipPercentage / 100;

            //it may be possible that battle host himself is sponsor, he won't be getting commissions for that :)
            var battleHostAsSponsorAmount =
                sponsorships.Where(x => x.UserId == battle.ChallengerId).Sum(x => x.SponsorshipAmount);


            var battleHostShare = (netSponsorshipAmount - battleHostAsSponsorAmount) * battleSettings.BattleHostVideoBattleSponsorshipPercentage / 100;

            //amount available for winners
            var winnerPrizePool = netSponsorshipAmount - siteOwnerShare - battleHostShare;

            if (winnerPosition.HasValue)
            {
                winnerPrizePool = PrizeDistributionHelper.GetPrizeDistributionPercentage(winnerPosition.Value,
                                                                                         allPrizes.Count(x => !x.IsSponsored), settingService) * winnerPrizePool;
            }

            var totalAmount = Math.Round(totalPrizesAmountFixed + totalPrizesAmountPercentage + winnerPrizePool);

            var totalPrizeString = totalAmount > 0 ? formatterService.FormatCurrency(totalAmount, ApplicationContext.Current.ActiveCurrency) : "";


            if (allPrizes.Any(x => x.PrizeType == BattlePrizeType.FixedProduct || x.PrizeType == BattlePrizeType.Other))
            {
                if (!winnerPosition.HasValue)
                {
                    totalPrizeString += "+";
                }
                else
                {
                    //now append each product as prize with it's name to the prize string
                    foreach (var prize in videoBattlePrizes.Where(x => x.PrizeType == BattlePrizeType.FixedProduct || x.PrizeType == BattlePrizeType.Other))
                    {
                        if (prize.PrizeType == BattlePrizeType.FixedProduct)
                        {
                            //todo: do something for fixed product
                        }
                        else
                        {
                            totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther;
                        }
                    }
                    //and sponsored products
                    foreach (var prize in sponsoredPrizes.Where(x => x.PrizeType == BattlePrizeType.Other))
                    {
                        totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther + "*";
                    }
                }
            }

            return(totalPrizeString);
        }
        public int SendSomeoneChallengedYouForABattleNotification(Customer challenger, string challengeeEmail, string challengeeName, VideoBattle videoBattle,
            int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.SomeoneChallengedYouForBattleNotification", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List<Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)) , true),
                new Token("Challenger.FirstName", challenger.GetFullName() , true)

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, challenger);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = challengeeEmail;
            var toName = challengeeName;

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
        public int SendSponsorshipStatusChangeNotification(Customer receiver, SponsorshipStatus sponsorshipStatus, VideoBattle videoBattle, int languageId,
                                                           int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.SponsorshipStatusChangeNotification", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>
            {
                new Token("Battle.Title", videoBattle.Name, true),
                new Token("Battle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)), true),
                new Token("Sponsorship.Status", sponsorshipStatus.ToString(), true)
            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddCustomerTokens(tokens, receiver);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = receiver.Email;
            var toName  = receiver.GetFullName().ToTitleCase();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Exemplo n.º 14
0
 bool CanInvite(VideoBattle videoBattle)
 {
     if (videoBattle == null)
         return false;
     return videoBattle.VideoBattleStatus != BattleStatus.Complete
            && videoBattle.VideoBattleStatus != BattleStatus.Closed
            &&
            ((ApplicationContext.Current.CurrentUser.Id == videoBattle.ChallengerId &&
              videoBattle.ParticipationType == BattleParticipationType.InviteOnly) //page owner
             || videoBattle.ParticipationType == BattleParticipationType.Open
             || ApplicationContext.Current.CurrentUser.IsAdministrator()); //administrator
 }
Exemplo n.º 15
0
 bool CanEdit(VideoBattle videoBattle)
 {
     if (videoBattle == null)
         return false;
     return (ApplicationContext.Current.CurrentUser.Id == videoBattle.ChallengerId //page owner
             || videoBattle.Id == 0 //new battle
             || ApplicationContext.Current.CurrentUser.IsAdministrator()); //administrator
 }
Exemplo n.º 16
0
 bool CanDelete(VideoBattle videoBattle)
 {
     if (videoBattle == null)
         return false;
     return ApplicationContext.Current.CurrentUser.Id == videoBattle.ChallengerId //page owner
            || ApplicationContext.Current.CurrentUser.IsAdministrator(); //administrator
 }
        public int SendXDaysToBattleStartNotificationToParticipant(User receiver, VideoBattle videoBattle, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.xDaysToBattleStartNotification", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //find the remaining days to start of battle
            var timeSpan = (int)Math.Ceiling(videoBattle.VotingStartDate.Subtract(DateTime.UtcNow).TotalDays);
            var formattedString = timeSpan > 1 ? string.Format("in {0} days", timeSpan) : "tomorrow";
            //tokens
            var tokens = new List<Token>
            {
                new Token("Battle.Title", videoBattle.Name, true),
                new Token("Battle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)), true),
                new Token("Battle.StartDaysString", formattedString , true)

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, receiver);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = receiver.Email;
            var toName = receiver.GetFullName().ToTitleCase();

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
Exemplo n.º 18
0
        public int SendVotingReminderNotification(User sender, string receiverEmail, string receiverName, VideoBattle videoBattle, int languageId,
                                                  int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);


            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.SomeoneInvitedYouToVoteNotification", store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }


            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattles/VideoBattle/{1}", store.Url, videoBattle.Id), true),
                new Token("Inviter.Name", sender.GetFullName(), true)
            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, sender);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);


            var toEmail = receiverEmail;
            var toName  = receiverName;

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Exemplo n.º 19
0
 public int SendSomeoneChallengedYouForABattleNotification(User challenger, User challengee, VideoBattle videoBattle,
                                                           int languageId, int storeId)
 {
     return(SendSomeoneChallengedYouForABattleNotification(challenger, challenger.Email,
                                                           challenger.GetFullName().ToTitleCase(), videoBattle, languageId, storeId));
 }
Exemplo n.º 20
0
 public int SendVotingReminderNotification(User sender, User receiver, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 21
0
 public int SendVotingReminderNotification(User sender, User receiver, VideoBattle videoBattle, int languageId, int storeId)
 {
     return(SendVotingReminderNotification(sender, receiver.Email, receiver.GetFullName().ToTitleCase(), videoBattle,
                                           languageId, storeId));
 }
Exemplo n.º 22
0
 public int SendVideoBattleSignupAcceptedNotification(User challenger, User challengee, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
 public int SendSomeoneChallengedYouForABattleNotification(User challenger, User challengee, VideoBattle videoBattle,
     int languageId, int storeId)
 {
     return SendSomeoneChallengedYouForABattleNotification(challenger, challenger.Email,
         challenger.GetFullName().ToTitleCase(), videoBattle, languageId, storeId);
 }
        public int SendSponsorshipStatusChangeNotification(User receiver, SponsorshipStatus sponsorshipStatus, VideoBattle videoBattle, int languageId,
            int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.SponsorshipStatusChangeNotification", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List<Token>
            {
                new Token("Battle.Title", videoBattle.Name, true),
                new Token("Battle.Url", string.Format("{0}/VideoBattle/{1}", store.Url, videoBattle.GetSeName(_workContext.WorkingLanguage.Id, true, false)), true),
                new Token("Sponsorship.Status", sponsorshipStatus.ToString() , true)

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, receiver);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = receiver.Email;
            var toName = receiver.GetFullName().ToTitleCase();

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
Exemplo n.º 25
0
 public void SendSomeoneChallengedYouForABattleNotification(User challenger, string challengeeEmail, string challengeeName,
                                                            VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
        public int SendVideoBattleCompleteNotification(User customer, VideoBattle videoBattle, NotificationRecipientType recipientType, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate(recipientType == NotificationRecipientType.Participant ? "MobSocial.VideoBattleCompleteNotificationToParticipants" : "MobSocial.VideoBattleCompleteNotificationToVoters", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List<Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattles/VideoBattle/{1}", store.Url, videoBattle.Id) , true),

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, customer);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = customer.Email;
            var toName = customer.GetFullName().ToTitleCase();

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
Exemplo n.º 27
0
 public void SendVotingReminderNotification(User sender, string receiverEmail, string receiverName, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
        public int SendVideoBattleSignupNotification(User challenger, User challengee, VideoBattle videoBattle, int languageId, int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.VideoBattleSignupNotification", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List<Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattles/VideoBattle/{1}", store.Url, videoBattle.Id) , true),
                new Token("Challenger.Name", challengee.GetFullName() , true)

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, challengee);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = challenger.Email;
            var toName = challenger.GetFullName().ToTitleCase();

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
Exemplo n.º 29
0
 public void SendVideoBattleOpenNotification(User receiver, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
 public int SendVotingReminderNotification(User sender, User receiver, VideoBattle videoBattle, int languageId, int storeId)
 {
     return SendVotingReminderNotification(sender, receiver.Email, receiver.GetFullName().ToTitleCase(), videoBattle,
         languageId, storeId);
 }
Exemplo n.º 31
0
 public void SendSponsorshipStatusChangeNotification(User receiver, SponsorshipStatus sponsorshipStatus,
                                                     VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
        public int SendVotingReminderNotification(User sender, string receiverEmail, string receiverName, VideoBattle videoBattle, int languageId,
            int storeId)
        {
            var store = _storeService.GetStoreById(storeId) ?? _storeContext.CurrentStore;

            languageId = EnsureLanguageIsActive(languageId, store.Id);

            var messageTemplate = GetLocalizedActiveMessageTemplate("MobSocial.SomeoneInvitedYouToVoteNotification", store.Id);
            if (messageTemplate == null)
                return 0;

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List<Token>
            {
                new Token("VideoBattle.Title", videoBattle.Name, true),
                new Token("VideoBattle.Url", string.Format("{0}/VideoBattles/VideoBattle/{1}", store.Url, videoBattle.Id) , true),
                new Token("Inviter.Name", sender.GetFullName() , true)

            };

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddUserTokens(tokens, sender);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = receiverEmail;
            var toName = receiverName;

            return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
        }
Exemplo n.º 33
0
 public void SendXDaysToBattleEndNotificationToFollower(User receiver, VideoBattle videoBattleUser)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 34
0
        public static string GetConsolidatedPrizesString(this VideoBattle Battle,
                                                         List <VideoBattlePrize> allPrizes,
                                                         int?WinnerPosition,
                                                         IWorkContext _workContext,
                                                         IProductService _productService,
                                                         ISponsorService _sponsorService,
                                                         IVoterPassService _voterPassService,
                                                         IVideoBattlePrizeService _videoBattlePrizeService,
                                                         IPriceFormatter _priceFormatter,
                                                         ISettingService _settingService,
                                                         IPaymentProcessingService _paymentProcessingService,
                                                         mobSocialSettings _mobSocialSettings)
        {
            var battleOwnerPrizes = allPrizes.Where(x => !x.IsSponsored && (!WinnerPosition.HasValue || x.WinnerPosition == WinnerPosition.Value));
            var sponsoredPrizes   = allPrizes.Where(x => x.IsSponsored && (!WinnerPosition.HasValue || x.WinnerPosition == WinnerPosition.Value));

            var totalPrizesAmountFixed =
                battleOwnerPrizes.Where(x => x.PrizeType == VideoBattlePrizeType.FixedAmount).Sum(x => x.PrizeAmount);

            var totalPrizesAmountPercentage = 0m;

            if (battleOwnerPrizes.Any(x => x.PrizeType == VideoBattlePrizeType.PercentageAmount))
            {
                var orders      = _voterPassService.GetAllVoterPassOrders(BattleType.Video, Battle.Id, PassStatus.Used);
                var orderSum    = orders.Sum(x => x.OrderTotal);
                var netOrderSum = _paymentProcessingService.GetNetAmountAfterPaymentProcessing(orderSum);

                var totalWinners = battleOwnerPrizes.Count();

                //total voting amount from percentage
                totalPrizesAmountPercentage = netOrderSum -
                                              totalWinners * netOrderSum * Battle.ParticipantPercentagePerVote / 100;
            }

            var sponsorships = _sponsorService.GetSponsorsGrouped(null, Battle.Id, BattleType.Video,
                                                                  SponsorshipStatus.Accepted);

            var sponsorshipAmount = sponsorships.Sum(x => x.SponsorshipAmount);

            //amount after payment processing
            var netSponsorshipAmount = _paymentProcessingService.GetNetAmountAfterPaymentProcessing(sponsorshipAmount);

            var siteOwnerShare = netSponsorshipAmount * _mobSocialSettings.SiteOwnerSponsorshipPercentage / 100;

            //it may be possible that battle host himself is sponsor, he won't be getting commissions for that :)
            var battleHostAsSponsorAmount =
                sponsorships.Where(x => x.CustomerId == Battle.ChallengerId).Sum(x => x.SponsorshipAmount);


            var battleHostShare = (netSponsorshipAmount - battleHostAsSponsorAmount) * _mobSocialSettings.BattleHostSponsorshipPercentage / 100;

            //amount available for winners
            var winnerPrizePool = netSponsorshipAmount - siteOwnerShare - battleHostShare;

            if (WinnerPosition.HasValue)
            {
                winnerPrizePool = PrizeDistributionHelper.GetPrizeDistributionPercentage(WinnerPosition.Value,
                                                                                         allPrizes.Count(x => !x.IsSponsored), _settingService) * winnerPrizePool;
            }

            var totalAmount = Math.Round(totalPrizesAmountFixed + totalPrizesAmountPercentage + winnerPrizePool);

            var totalPrizeString = totalAmount > 0 ? _priceFormatter.FormatPrice(totalAmount, true, _workContext.WorkingCurrency) : "";


            if (allPrizes.Any(
                    x => x.PrizeType == VideoBattlePrizeType.FixedProduct || x.PrizeType == VideoBattlePrizeType.Other))
            {
                if (!WinnerPosition.HasValue)
                {
                    totalPrizeString += "+";
                }
                else
                {
                    //now append each product as prize with it's name to the prize string
                    foreach (var prize in battleOwnerPrizes.Where(x => x.PrizeType == VideoBattlePrizeType.FixedProduct || x.PrizeType == VideoBattlePrizeType.Other))
                    {
                        if (prize.PrizeType == VideoBattlePrizeType.FixedProduct)
                        {
                            var product = _productService.GetProductById(prize.PrizeProductId);
                            if (product != null)
                            {
                                totalPrizeString += (totalPrizeString != "" ? " + " : "") + product.Name;
                            }
                            else
                            {
                                totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeProductId;
                            }
                        }
                        else
                        {
                            totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther;
                        }
                    }
                    //and sponsored products
                    foreach (var prize in sponsoredPrizes.Where(x => x.PrizeType == VideoBattlePrizeType.Other))
                    {
                        totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther + "*";
                    }
                }
            }

            return(totalPrizeString);
        }