Наследование: mobSocial.WebApi.Configuration.Mvc.Models.RootEntityModel
        public IHttpActionResult Edit(int videoBattleId = 0)
        {
            var videoBattle = videoBattleId != 0 ? _videoBattleService.Get(videoBattleId) : new VideoBattle();

            //can the user actually edit the battle?
            if (!CanEdit(videoBattle))
            {
                VerboseReporter.ReportError("Video Battle doesn't exist", "edit_battle");
                return RespondFailure();
            }

            var model = new VideoBattleModel() {
                VotingStartDate =
                    videoBattleId == 0 ? DateTime.UtcNow.AddDays(10) : videoBattle.VotingStartDate.ToLocalTime(),
                //10 days
                ChallengerId = videoBattle.ChallengerId,
                DateCreated = videoBattleId == 0 ? DateTime.UtcNow : videoBattle.DateCreated,
                DateUpdated = videoBattleId == 0 ? DateTime.UtcNow : videoBattle.DateUpdated,
                VotingEndDate =
                    videoBattleId == 0 ? DateTime.UtcNow.AddDays(20) : videoBattle.VotingEndDate.ToLocalTime(),
                //20 days
                Description = videoBattle.Description,
                Name = videoBattle.Name,
                Id = videoBattle.Id,
                VideoBattleStatus = videoBattle.VideoBattleStatus,
                VideoBattleParticipationType = videoBattleId == 0 ? BattleParticipationType.Open : videoBattle.ParticipationType,
                VideoBattleVoteType = videoBattle.VideoBattleVoteType,
                MaximumParticipantCount = videoBattleId == 0 ? 10 : videoBattle.MaximumParticipantCount,
                MinimumVotingCharge =
                    videoBattleId == 0
                        ? _battleSettings.DefaultVotingChargeForPaidVoting
                        : videoBattle.MinimumVotingCharge,
                IsVotingPayable = videoBattle.IsVotingPayable,
                CanVoterIncreaseVotingCharge = videoBattle.CanVoterIncreaseVotingCharge,
                ParticipantPercentagePerVote = videoBattle.ParticipantPercentagePerVote,
                IsSponsorshipSupported = videoBattle.IsSponsorshipSupported,
                MinimumSponsorshipAmount = videoBattle.MinimumSponsorshipAmount,
                SponsoredCashDistributionType = videoBattle.SponsoredCashDistributionType,
                AutomaticallyPostEventsToTimeline = videoBattle.AutomaticallyPostEventsToTimeline
            };

            //let's get prizes associated with this battle. prizes can only be added to saved battles
            if (model.Id != 0)
            {
                var prizes = _videoBattlePrizeService.GetBattlePrizes(model.Id).Where(x => !x.IsSponsored);
                foreach (var prize in prizes)
                {
                    model.Prizes.Add(new VideoBattlePrizeModel() {
                        Id = prize.Id,
                        VideoBattleId = prize.VideoBattleId,
                        PrizeType = prize.PrizeType,
                        WinnerId = prize.WinnerId,
                        PrizeAmount = prize.PrizeAmount,
                        Description = prize.Description,
                        PrizeOther = prize.PrizeOther,
                        PrizePercentage = prize.PrizePercentage,
                        WinnerPosition = prize.WinnerPosition,
                        PrizeProductId = prize.PrizeProductId
                    });
                }
            }
            return RespondSuccess(model);
        }
        public void SaveVideoBattle_fails_for_invalid_model()
        {
            using (var battleController = ResolveController<VideoBattleController>())
            {
                var videoBattleModel = new VideoBattleModel();
                battleController.Validate(videoBattleModel);

                var response = battleController.SaveVideoBattle(videoBattleModel);
                Assert.IsFalse(response.GetValue<bool>("Success"));
            }
        }
        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()
            });
        }