public int CreateContest(CreateContestBindingModel model, string userId)
        {
            if (this.Data.RewardStrategies.Find(model.RewardStrategyId) == null)
            {
                throw new NotFoundException("Not existing reward strategy");
            }

            if (this.Data.ParticipationStrategies.Find(model.ParticipationStrategyId) == null)
            {
                throw new NotFoundException("Not existing participation strategy");
            }

            if (this.Data.VotingStrategies.Find(model.VotingStrategyId) == null)
            {
                throw new NotFoundException("Not existing voting strategy");
            }

            if (this.Data.DeadlineStrategies.Find(model.DeadlineStrategyId) == null)
            {
                throw new NotFoundException("Not existing deadline strategy");
            }

            var loggedUserId = userId;

            var contest = new Contest
            {
                Title = model.Title,
                Description = model.Description,
                Status = ContestStatus.Active,
                RewardStrategyId = model.RewardStrategyId,
                VotingStrategyId = model.VotingStrategyId,
                ParticipationStrategyId = model.ParticipationStrategyId,
                DeadlineStrategyId = model.DeadlineStrategyId,
                ParticipantsLimit = model.ParticipantsLimit,
                TopNPlaces = model.TopNPlaces,
                SubmissionDeadline = model.SubmissionDeadline,
                IsOpenForSubmissions = true,
                StartDate = DateTime.Now,
                OrganizatorId = loggedUserId,
            };

            this.Data.Contests.Add(contest);
            this.Data.SaveChanges();

            return contest.Id;
        }
        public ActionResult CreateContest(CreateContestBindingModel model)
        {
            if (model == null)
            {
                this.Response.StatusCode = (int) HttpStatusCode.BadRequest;
                return this.Json(new { ErrorMessage = "Missing Data" });
            }

            if (!this.ModelState.IsValid)
            {
                this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return this.Json(this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
            }

            try
            {
                int contestId = this._service.CreateContest(model, this.User.Identity.GetUserId());

                return this.RedirectToAction("PreviewContest", new { id = contestId });
            }
            catch (NotFoundException exception)
            {
                this.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return this.Json(new { ErrorMessage = exception.Message });
            }
        }