public static string FormatCurrency(this IFormatterService formatterService, decimal amount, bool includeSymbol = true)
 {
     if (ApplicationEngine.IsAdmin())
     {
         return(formatterService.FormatCurrency(amount, ApplicationEngine.BaseCurrency.CultureCode,
                                                includeSymbol, ApplicationEngine.BaseCurrency.CustomFormat));
     }
     return(formatterService.FormatCurrency(amount, ApplicationEngine.CurrentCurrency.CultureCode, includeSymbol, ApplicationEngine.BaseCurrency.CustomFormat));
 }
Exemplo n.º 2
0
        public static SponsorPublicModel ToPublicModel(this Sponsor sponsor, IUserService userService, IMediaService pictureService, ISponsorService sponsorService, IFormatterService formatterService, MediaSettings mediaSettings)
        {
            var user = userService.Get(sponsor.UserId);
            if (user == null)
                return null;

            //get sponsor data
            var sponsorData = sponsorService.GetSponsorData(sponsor.BattleId, sponsor.BattleType, sponsor.UserId);

            var model = new SponsorPublicModel
            {
                SponsorshipStatus = sponsor.SponsorshipStatus,
                SponsorshipStatusName = sponsor.SponsorshipStatus.ToString(),
                CustomerId = sponsor.UserId,
                SeName = user.GetPermalink().ToString(),
                SponsorName = user.GetPropertyValueAs<string>(PropertyNames.DisplayName),
                SponsorProfileImageUrl =
                    pictureService.GetPictureUrl(user.GetPropertyValueAs<int>(PropertyNames.DefaultPictureId)),
                SponsorshipAmount = sponsor.SponsorshipAmount,
                SponsorshipAmountFormatted = formatterService.FormatCurrency(sponsor.SponsorshipAmount, ApplicationContext.Current.ActiveCurrency),
                SponsorData = sponsorData.ToModel(pictureService),
                SponsorshipType = sponsor.SponsorshipType
            };

            return model;
        }
        public IHttpActionResult GetSponsorTransactions([FromUri] SponsorTransactionRequestModel requestModel)
        {
            //only battle owner or sponsor should be able to see transactions
            //todo: get picture battle when ready
            var battle = requestModel.BattleType == BattleType.Video ? _videoBattleService.Get(requestModel.BattleId) : null;

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Battle doesn't exist" }));
            }


            if (battle.ChallengerId != ApplicationContext.Current.CurrentUser.Id &&
                requestModel.CustomerId != ApplicationContext.Current.CurrentUser.Id)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            var sponsorships = _sponsorService.GetSponsors(requestModel.CustomerId, requestModel.BattleId, BattleType.Video, null);
            var model        = new List <SponsorTransactionModel>();
            var user         = _userService.Get(requestModel.CustomerId);

            foreach (var sponsorship in sponsorships)
            {
                model.Add(new SponsorTransactionModel()
                {
                    OrderId                    = sponsorship.Id,
                    TransactionDate            = DateTimeHelper.GetDateInUserTimeZone(sponsorship.DateCreated, DateTimeKind.Utc, user).ToString(),
                    TransactionAmount          = sponsorship.SponsorshipAmount,
                    TransactionAmountFormatted = _formatterService.FormatCurrency(sponsorship.SponsorshipAmount, ApplicationContext.Current.ActiveCurrency)
                });
            }

            return(Json(new { Success = true, Orders = model }));
        }
Exemplo n.º 4
0
        public static SponsorPublicModel ToPublicModel(this Sponsor sponsor, IUserService userService, IMediaService pictureService, ISponsorService sponsorService, IFormatterService formatterService, MediaSettings mediaSettings)
        {
            var user = userService.Get(sponsor.UserId);

            if (user == null)
            {
                return(null);
            }

            //get sponsor data
            var sponsorData = sponsorService.GetSponsorData(sponsor.BattleId, sponsor.BattleType, sponsor.UserId);

            var model = new SponsorPublicModel
            {
                SponsorshipStatus     = sponsor.SponsorshipStatus,
                SponsorshipStatusName = sponsor.SponsorshipStatus.ToString(),
                CustomerId            = sponsor.UserId,
                SeName                 = user.GetPermalink().ToString(),
                SponsorName            = user.GetPropertyValueAs <string>(PropertyNames.DisplayName),
                SponsorProfileImageUrl =
                    pictureService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId)),
                SponsorshipAmount          = sponsor.SponsorshipAmount,
                SponsorshipAmountFormatted = formatterService.FormatCurrency(sponsor.SponsorshipAmount, ApplicationContext.Current.ActiveCurrency),
                SponsorData     = sponsorData.ToModel(pictureService),
                SponsorshipType = sponsor.SponsorshipType
            };


            return(model);
        }
        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);
        }
Exemplo n.º 6
0
        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;
        }