public ActionResult Index(string SeName, VideoViewMode ViewMode = VideoViewMode.Regular)
        {
            var model = new VideoBattleIndexModel()
            {
                SeName   = SeName,
                ViewMode = ViewMode
            };

            return(View(ViewMode == VideoViewMode.TheaterMode ? "mobSocial/VideoBattle/Single.TheaterView" : "mobSocial/VideoBattle/Single", model));
        }
        public IHttpActionResult Get(int id, VideoViewMode viewMode = VideoViewMode.Regular)
        {
            //let's get the video battle by it's slug
            var videoBattle = _videoBattleService.Get(id);

            //does the video battle exist?
            if (videoBattle == null)
            {
                VerboseReporter.ReportError("Video Battle doesn't exist", "get_battle");
                return RespondFailure();
            }

            var videoBattleId = videoBattle.Id;
            IList<VideoBattleParticipant> participants = null;

            //it's quite possible that battle is about to open/close and we are waiting for scheduler to open/close the battle...we should lock it then
            //so that nobody can do anything with it now.
            if ((videoBattle.VotingStartDate <= DateTime.UtcNow && videoBattle.VideoBattleStatus == BattleStatus.Pending) ||
                (videoBattle.VotingEndDate <= DateTime.UtcNow && videoBattle.VideoBattleStatus == BattleStatus.Open))
            {
                videoBattle.VideoBattleStatus = BattleStatus.Locked;
                _videoBattleService.Update(videoBattle);
            }

            //only open video battles can be viewed or ofcourse if I am the owner, I should be able to see it open or closed right?
            var canOpen = videoBattle.VideoBattleStatus != BattleStatus.Pending
                          || CanEdit(videoBattle)
                          || (videoBattle.ParticipationType != BattleParticipationType.InviteOnly);

            //still can't open, let's see if it's a participant accessting the page
            if (!canOpen)
            {
                participants = _videoBattleParticipantService.GetVideoBattleParticipants(videoBattleId, null);
                canOpen = participants.Count(x => x.ParticipantId == ApplicationContext.Current.CurrentUser.Id) > 0;
            }
            if (!canOpen)
            {
                VerboseReporter.ReportError("Video Battle doesn't exist", "get_video_battle");
                return RespondFailure();
            }

            //get all the participants who have been invited, accepted etc. to the battle
            if (participants == null)
                participants = _videoBattleParticipantService.GetVideoBattleParticipants(videoBattleId, null);

            //let's exclude participants who haven't accepted the challenge
            if (videoBattle.VideoBattleStatus != BattleStatus.Pending)
            {
                participants =
                    participants.Where(x => x.ParticipantStatus != BattleParticipantStatus.ChallengeDenied).ToList();
            }

            //lets get the videos associated with battle
            var battleVideos = _videoBattleVideoService.GetBattleVideos(videoBattleId);

            var challengerVideo = battleVideos.FirstOrDefault(x => x.ParticipantId == videoBattle.ChallengerId);
            var challenger = _userService.Get(videoBattle.ChallengerId);

            var challengerVideoModel = new VideoParticipantPublicModel() {
                ParticipantName = challenger.GetPropertyValueAs(PropertyNames.DisplayName, challenger.UserName),
                Id = challenger.Id,
                CanEdit = ApplicationContext.Current.CurrentUser.Id == videoBattle.ChallengerId,
                SeName = challenger.GetPermalink()?.ToString(),
                ParticipantProfileImageUrl =
                    _pictureService.GetPictureUrl(challenger.GetPropertyValueAs<int>(PropertyNames.DefaultPictureId),
                        PictureSizeNames.OriginalProfileImage)
            };

            if (challengerVideo != null &&
                (videoBattle.VideoBattleStatus != BattleStatus.Pending ||
                 challenger.Id == ApplicationContext.Current.CurrentUser.Id))
            {
                challengerVideoModel.VideoPath = challengerVideo.VideoPath;
                // challengerVideoModel.ThumbnailPath = _mobSocialSettings.ShowVideoThumbnailsForBattles ? challengerVideo.ThumbnailPath : "";
                challengerVideoModel.MimeType = challengerVideo.MimeType;
                challengerVideoModel.VideoId = challengerVideo.Id;
                //video is marked watched if 1. participant is viewing his own video 2. he has viewed the video
                challengerVideoModel.VideoWatched = challengerVideo.ParticipantId ==
                                                    ApplicationContext.Current.CurrentUser.Id ||
                                                    _watchedVideoService.IsVideoWatched(
                                                        ApplicationContext.Current.CurrentUser.Id, challengerVideo.Id,
                                                        VideoType.BattleVideo);
            }

            var model = new VideoBattlePublicModel {
                Name = videoBattle.Name,
                Description = videoBattle.Description,
                VotingStartDate = videoBattle.VotingStartDate,
                VotingEndDate = videoBattle.VotingEndDate,
                DateCreated = videoBattle.DateCreated,
                DateUpdated = videoBattle.DateUpdated,
                VideoBattleStatus = videoBattle.VideoBattleStatus,
                BattleParticipationType = videoBattle.ParticipationType,
                VideoBattleVoteType = videoBattle.VideoBattleVoteType,
                Id = videoBattleId,
                RemainingSeconds = videoBattle.GetRemainingSeconds(),
                MaximumParticipantCount = videoBattle.MaximumParticipantCount,
                IsUserLoggedIn = ApplicationContext.Current.CurrentUser.IsRegistered(),
                LoggedInUserId = ApplicationContext.Current.CurrentUser.Id,
                IsVotingPayable = videoBattle.IsVotingPayable,
                CanVoterIncreaseVotingCharge = videoBattle.CanVoterIncreaseVotingCharge,
                MinimumVotingCharge = videoBattle.MinimumVotingCharge,
                ChallengerName = challenger.GetPropertyValueAs<string>(PropertyNames.DisplayName),
                ChallengerSeName = challenger.GetPermalink().ToString(),
                ChallengerProfileImageUrl = challengerVideoModel.ParticipantProfileImageUrl,
                IsSponsorshipSupported = videoBattle.IsSponsorshipSupported,
                MinimumSponsorshipAmount = videoBattle.MinimumSponsorshipAmount,
                VideoBattleSeName = videoBattle.GetPermalink().ToString()
            };

            //add challenger as participant
            model.Participants.Add(challengerVideoModel);

            //and now challengees
            foreach (var participant in participants)
            {
                var challengee = _userService.Get(participant.ParticipantId);
                var cModel = new VideoParticipantPublicModel() {
                    ParticipantName = challengee.GetPropertyValueAs<string>(PropertyNames.DisplayName),
                    SeName = challengee.GetPermalink().ToString(),
                    ParticipantProfileImageUrl =
                        _pictureService.GetPictureUrl(
                            challengee.GetPropertyValueAs<int>(PropertyNames.DefaultPictureId),
                            PictureSizeNames.OriginalProfileImage),
                    Id = challengee.Id,
                    CanEdit = ApplicationContext.Current.CurrentUser.Id == participant.ParticipantId,
                    VideoBattleParticipantStatus = participant.ParticipantStatus,
                    Remarks = participant.Remarks
                };

                //find if the participant has uploaded video? only those who have accepted challege would be shown 'with videos'
                if (participant.ParticipantStatus == BattleParticipantStatus.ChallengeAccepted &&
                    ((videoBattle.VideoBattleStatus != BattleStatus.Pending &&
                      videoBattle.VideoBattleStatus != BattleStatus.Locked) ||
                     participant.ParticipantId == ApplicationContext.Current.CurrentUser.Id))
                {
                    var video = battleVideos.FirstOrDefault(x => x.ParticipantId == participant.ParticipantId);
                    if (video != null)
                    {
                        cModel.VideoPath = video.VideoPath;
                        cModel.MimeType = video.MimeType;
                        //   cModel.ThumbnailPath = _mobSocialSettings.ShowVideoThumbnailsForBattles ? video.ThumbnailPath : "";
                        cModel.VideoId = video.Id;
                        //video is marked watched if 1. participant is viewing his own video 2. he has viewed the video
                        cModel.VideoWatched = video.ParticipantId == ApplicationContext.Current.CurrentUser.Id ||
                                              _watchedVideoService.IsVideoWatched(
                                                  ApplicationContext.Current.CurrentUser.Id, video.Id,
                                                  VideoType.BattleVideo);
                    }
                }
                model.Participants.Add(cModel);
            }

            //let's find if the logged in user has voted for this battle.
            //also we gather various voting stats till now for battle videos
            //voting info for logged in user
            var videoBattleVotes = _videoBattleVoteService.GetVideoBattleVotes(videoBattleId, null);
            var videoBattleCurrentUserVotes =
                videoBattleVotes.Where(x => x.UserId == ApplicationContext.Current.CurrentUser.Id);

            foreach (var participant in model.Participants)
            {
                //first the global voting status for this participant
                var votesForParticipant =
                    videoBattleVotes.Where(
                        x => x.ParticipantId == participant.Id && x.VoteStatus == BattleVoteStatus.Voted);

                //total votes
                var forParticipant = votesForParticipant as IList<VideoBattleVote> ?? votesForParticipant.ToList();
                if (forParticipant.Count > 0)
                {
                    participant.TotalVoters = forParticipant.Count();

                    //accumulate all vote count
                    model.TotalVotes += participant.TotalVoters;

                    //we store 1 for like 0 for dislike
                    participant.RatingCountLike =
                        forParticipant.Count(x => x.VoteValue == 1);

                    participant.RatingCountDislike =
                        forParticipant.Count(x => x.VoteValue == 0);

                    //average rating is the average of all the vote values
                    participant.AverageRating = forParticipant.Average(x => (decimal)x.VoteValue);
                }

                //now vote of logged in user
                var currentUserVote =
                    videoBattleCurrentUserVotes.FirstOrDefault(
                        x => x.ParticipantId == participant.Id && x.VoteStatus == BattleVoteStatus.Voted);
                if (currentUserVote != null)
                {
                    //stores the value of vote for logged in user if any
                    participant.CurrentUserVote = new VideoBattleVotePublicModel {
                        VoteValue = currentUserVote.VoteValue
                    };
                }
                else
                {
                    participant.CurrentUserVote = null;
                }
            }

            //and who is the winner or leader?
            VideoParticipantPublicModel winnerOrLeader = null;
            switch (videoBattle.VideoBattleVoteType)
            {
                case BattleVoteType.SelectOneWinner:
                    //one with max vote count is winner/leader
                    winnerOrLeader = model.Participants.OrderByDescending(x => x.TotalVoters).First();

                    break;
                case BattleVoteType.LikeDislike:
                    //one with more likes is winner/leader
                    winnerOrLeader = model.Participants.OrderByDescending(x => x.RatingCountLike).First();
                    break;
                case BattleVoteType.Rating:
                    //one with max average rating is winner/leader
                    winnerOrLeader = model.Participants.OrderByDescending(x => x.AverageRating).First();
                    break;
            }
            if (winnerOrLeader != null && videoBattleVotes.Count > 0)
            {
                winnerOrLeader.IsLeading = true;
                if (videoBattle.VideoBattleStatus == BattleStatus.Complete)
                {
                    winnerOrLeader.IsWinner = true;
                }
            }
            //because we use same interface to inviting participants and voters, its necessary that we show the invite box to participants (who have accepted) as well
            //ofcourse with Invite Voters title
            model.IsParticipant =
                model.Participants.Select(x => x.Id).Contains(ApplicationContext.Current.CurrentUser.Id);
            model.IsEditable = CanEdit(videoBattle);
            model.ViewMode = viewMode;

            //the featured image will be used to display the image on social networks. depending on the status of battle, we either show a default image or
            //the image of the leader as the featured image
            model.VideoBattleFeaturedImageUrl = _battleSettings.DefaultVideosFeaturedImageUrl;
            if (model.VideoBattleStatus != BattleStatus.Pending)
            {
                if (winnerOrLeader?.ThumbnailPath != null)
                {
                    model.VideoBattleFeaturedImageUrl = winnerOrLeader.ThumbnailPath;
                }
            }
            //and because the image path starts with ~ (a relative path), we need to convert this to url based on store url
            model.VideoBattleFeaturedImageUrl = model.VideoBattleFeaturedImageUrl;

            var coverId = videoBattle.GetPropertyValueAs<int>(PropertyNames.DefaultCoverId);
            //cover image
            if (coverId != 0)
                model.VideoBattleCoverImageUrl = _pictureService.GetPictureUrl(coverId);

            //now the sponsors, is it supported? let's find out who are the sponsors
            model.IsSponsorshipSupported = videoBattle.IsSponsorshipSupported;
            var sponsors = _sponsorService.GetSponsorsGrouped(null, videoBattle.Id, BattleType.Video, null);

            var sModel =
                sponsors.Select(
                    s => s.ToPublicModel(_userService, _pictureService, _sponsorService, _formatterService,
                            _mediaSettings)).OrderBy(x => x.SponsorData.DisplayOrder).ToList();
            model.Sponsors = sModel.Where(x => x.SponsorshipStatus == SponsorshipStatus.Accepted).ToList();

            //and is the logged in user a sponsor?
            model.CurrentSponsor = sModel.FirstOrDefault(x => x.CustomerId == ApplicationContext.Current.CurrentUser.Id);
            model.IsSponsor = model.CurrentSponsor != null;

            //prizes
            var allPrizes = _videoBattlePrizeService.GetBattlePrizes(videoBattle.Id);
            model.ConsolidatedPrizesDisplay = videoBattle.GetConsolidatedPrizesString(allPrizes.ToList(), null,
                _sponsorService, _settingService, _paymentProcessingService,
                _formatterService, _creditService, _battleSettings);

            //following or not
            model.IsFollowing =
                _followService.GetCustomerFollow<VideoBattle>(ApplicationContext.Current.CurrentUser.Id, videoBattleId) != null ? 1 : 0;
            //and howmany are following
            model.TotalFollowerCount = _followService.GetFollowerCount<VideoBattle>(videoBattleId);

            return RespondSuccess(model);
        }