示例#1
0
        public async Task <int> Create(ContestCreateModel model, int currentUserId)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Contest data = _db.Contests.Add(new Contest
            {
                Name         = model.Name,
                Public       = model.Public,
                Duration     = model.Duration,
                CreateTime   = DateTime.Now,
                CreateUserId = currentUserId,
                Questions    = model.GetQuestionIds().Select((x, i) => new ContestQuestion
                {
                    QuestionId = x,
                    Rank       = i + 1,
                }).ToList(),
                Users = model.GetUserIds()?.Select(x => new ContestUser
                {
                    UserId = x,
                }).ToList(),
            });
            await _db.SaveChangesAsync();

            return(data.Id);
        }
示例#2
0
        public async Task <ActionResult> CreateConfirmed(ContestCreateModel model)
        {
            await model.Validate(_db, ModelState);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            int id = await _manager.Create(model, GetCurrentUserId());

            return(RedirectToAction(nameof(Details), new { id = id }));
        }