Beispiel #1
0
        public ActionResult SponsorDashboard(BattleType BattleType, int BattleId)
        {
            var battle = _videoBattleService.GetById(BattleId);

            if (battle == null)
            {
                return(InvokeHttp404());
            }
            //only battle owner or sponsor can vew dashboard
            var sponsors = _sponsorService.GetSponsors(_workContext.CurrentCustomer.Id, BattleId, BattleType, null);

            if (!sponsors.Any() && battle.ChallengerId != _workContext.CurrentCustomer.Id)
            {
                return(InvokeHttp404());
            }

            //TODO: Include picture battles when ready
            var model = new SponsorsRequestModel()
            {
                BattleType        = BattleType,
                BattleId          = BattleId,
                SponsorshipStatus = SponsorshipStatus.Pending,
                BattleName        = battle.Name,
                BattleUrl         = Url.RouteUrl("VideoBattlePage", new { SeName = battle.GetSeName(_workContext.WorkingLanguage.Id, true, false) })
            };

            return(View("mobSocial/Sponsor/SponsorDashboard", model));
        }
Beispiel #2
0
        public ActionResult GetSponsors(SponsorsRequestModel Model)
        {
            //first we check if it's the battle owner or a sponsor calling this method?
            //for that we need to query the battle first
            //todo: get picture battle when ready
            var battle = Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null;

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

            //lets query the sponsor
            var sponsors = battle.ChallengerId == _workContext.CurrentCustomer.Id
                ? _sponsorService.GetSponsorsGrouped(null, Model.BattleId, Model.BattleType, Model.SponsorshipStatus)                             //battle owner
                : _sponsorService.GetSponsorsGrouped(_workContext.CurrentCustomer.Id, Model.BattleId, Model.BattleType, Model.SponsorshipStatus); //sponsor or somebody else?

            //to list
            var model = sponsors.Select(s => s.ToPublicModel(_workContext, _customerService, _pictureService, _sponsorService, _priceFormatter, _mediaSettings)).OrderBy(x => x.SponsorData.DisplayOrder).ToList();

            return(Json(new {
                Success = true,
                Sponsors = model,
                IsChallenger = battle.ChallengerId == _workContext.CurrentCustomer.Id,
                IsSponsor = model.Any(x => x.CustomerId == _workContext.CurrentCustomer.Id),
                BattleName = battle.Name,
                BattleUrl = battle.GetSeName(_workContext.WorkingLanguage.Id)
            }));
        }
Beispiel #3
0
        public ActionResult SponsorDashboard(BattleType BattleType, int BattleId)
        {
            var model = new SponsorsRequestModel()
            {
                BattleType        = BattleType,
                BattleId          = BattleId,
                SponsorshipStatus = SponsorshipStatus.Pending,
            };

            return(View("mobSocial/Sponsor/SponsorDashboard", model));
        }
        public IHttpActionResult GetSponsors([FromUri] SponsorsRequestModel requestModel)
        {
            //first we check if it's the battle owner or a sponsor calling this method?
            //for that we need to query the battle first
            //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" }));
            }

            //lets query the sponsor
            var sponsors = battle.ChallengerId == ApplicationContext.Current.CurrentUser.Id
                ? _sponsorService.GetSponsorsGrouped(null, requestModel.BattleId, requestModel.BattleType, requestModel.SponsorshipStatus)                                       //battle owner
                : _sponsorService.GetSponsorsGrouped(ApplicationContext.Current.CurrentUser.Id, requestModel.BattleId, requestModel.BattleType, requestModel.SponsorshipStatus); //sponsor or somebody else?

            //to list
            var model = sponsors.Select(s => s.ToPublicModel(_userService, _mediaService, _sponsorService, _formatterService, _mediaSettings)).OrderBy(x => x.SponsorData.DisplayOrder).ToList();

            var allPrizes             = _videoBattlePrizeService.GetBattlePrizes(requestModel.BattleId);
            var totalWinningPositions = allPrizes.Count(x => !x.IsSponsored);

            //and do we have any existing saved prizes which are sponsored
            foreach (var m in model)
            {
                m.SponsoredProductPrizes = new List <VideoBattlePrizeModel>();
                var sponsoredPrizes = allPrizes.Where(x => x.IsSponsored && m.CustomerId == x.SponsorCustomerId);
                foreach (var prize in sponsoredPrizes)
                {
                    var prizeModel = new VideoBattlePrizeModel()
                    {
                        PrizeType         = prize.PrizeType,
                        PrizeOther        = prize.PrizeOther,
                        WinnerPosition    = prize.WinnerPosition,
                        Id                = prize.Id,
                        IsSponsored       = prize.IsSponsored,
                        VideoBattleId     = battle.Id,
                        SponsorCustomerId = prize.SponsorCustomerId
                    };
                    m.SponsoredProductPrizes.Add(prizeModel);
                }
                var totalSponsoredPrizes = sponsoredPrizes.Count();
                //if not all winning positions have been covered, add the remaining
                for (var index = totalSponsoredPrizes + 1; index <= totalWinningPositions; index++)
                {
                    m.SponsoredProductPrizes.Add(new VideoBattlePrizeModel()
                    {
                        Id                = 0,
                        PrizeType         = BattlePrizeType.Other,
                        WinnerPosition    = index,
                        IsSponsored       = true,
                        PrizeOther        = "",
                        VideoBattleId     = battle.Id,
                        SponsorCustomerId = m.CustomerId
                    });
                }
            }

            return(Json(new {
                Success = true,
                Sponsors = model,
                IsChallenger = battle.ChallengerId == ApplicationContext.Current.CurrentUser.Id,
                IsSponsor = model.Any(x => x.CustomerId == ApplicationContext.Current.CurrentUser.Id),
                BattleName = battle.Name,
                BattleUrl = Url.Route("VideoBattlePage", new RouteValueDictionary()
                {
                    { "SeName", battle.GetPermalink() }
                }),
                TotalWinningPositions = totalWinningPositions
            }));
        }