Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = model.UserName, Email = model.Email
                };
                using (var tran = TransactionInRequest.BeginTransaction())
                {
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent : false);

                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var callbackUrl = Url.Action("ConfirmUser", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        await UserManager.SendEmailAsync(user.Id, "确认你的账户",
                                                         "请通过单击 <a href=\"" + callbackUrl + "\">此处</a>来确认你的帐号");

                        tran.Complete();

                        return(this.RedirectToAction <HomeController>(x => x.Index())
                               .WithInfo("已经向你的邮箱" + user.Email + "发送了验证邮件,请前往并点击该邮件中的链接以验证您的帐户。"));
                    }

                    AddErrors(result);
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task Save(QuestionGroupEditModel questionGroup)
        {
            using (var tran = TransactionInRequest.BeginTransaction())
            {
                var entity = Mapper.Map <QuestionGroup>(questionGroup);
                await _db.QuestionGroupItems.Where(x => x.QuestionGroupId == entity.Id).DeleteAsync();

                _db.Entry(entity).State = EntityState.Modified;

                foreach (var item in entity.Questions)
                {
                    _db.Entry(item).State = EntityState.Added;
                }
                await _db.SaveChangesAsync();

                tran.Complete();
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> DataDelete(int questionId, int id)
        {
            using (var tran = TransactionInRequest.BeginTransaction())
            {
                var owns = await _manager.IsUserOwnsQuestion(questionId);

                if (!owns)
                {
                    return(NonOwnerReturn(questionId));
                }

                await _manager.DeleteData(id);

                tran.Complete();
            }

            return(RedirectToAction("Data", new { id = questionId }));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> ReJudge(int id)
        {
            using (var tran = TransactionInRequest.BeginTransaction())
            {
                var creator = await _db.Questions
                              .Where(x => x.Id == id)
                              .Select(x => x.CreateUserId)
                              .FirstAsync();

                if (!User.IsUserOrRole(creator, SystemRoles.QuestionAdmin))
                {
                    return(RedirectToAction("Details", new { id = id })
                           .WithError("只有创建者才能重新评测该题目。"));
                }

                await _db.Solutions
                .Where(x => x.QuestionId == id)
                .Select(x => x.Id)
                .ForEachAsync(x => SolutionHub.PushChange(x, SolutionState.Queuing, 0, 0.0f));

                await _db.Solutions
                .Where(x => x.QuestionId == id)
                .UpdateAsync(x => new Solution {
                    State = SolutionState.Queuing
                });

                await _db.SolutionLocks
                .Where(x => x.Solution.QuestionId == id)
                .DeleteAsync();

                var solutions = _db.Solutions
                                .Where(x => x.QuestionId == id)
                                .ProjectTo <SolutionPushModel>();

                await solutions.ForEachAsync(JudgeHub.Judge);

                tran.Complete();
            }

            return(RedirectToAction("Details", new { id = id })
                   .WithSuccess("该题目重新评测已经开始。"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> DataSave(int questionId, int?id, string input, string output, int time, float memory, bool isSample)
        {
            // 此处Save表示可以添加或者更新,但不能删除(删除使用DataDelete)。
            // id == null: 添加;
            // id != null: 更新。
            using (var tran = TransactionInRequest.BeginTransaction())
            {
                var owns = await _manager.IsUserOwnsQuestion(questionId);

                if (!owns)
                {
                    return(NonOwnerReturn(questionId));
                }

                await _manager.SaveData(questionId, id, input, output, time, memory, isSample);

                tran.Complete();
            }

            return(RedirectToAction("Data", new { id = questionId }));
        }