Ejemplo n.º 1
0
        /// <summary>
        /// 是否在答题区间内
        /// </summary>
        /// <param name="model">(1、狭路相逢 2、一比高下 3、狭路相逢)</param>
        /// <returns></returns>
        private async Task <bool> GetProblemInCountdown(UserProblemScore model)
        {
            bool result  = false;
            var  process = await _examContext.ExamProcesss
                           .Where(x => x.ModuleType == model.ProblemType)
                           .FirstOrDefaultAsync();

            if (process != null)
            {
                var baseSetting = await _examContext.BaseExamSettings.SingleOrDefaultAsync();

                int tTimeSpan = 0;
                switch (model.ProblemType)
                {
                case (int)eProblemType.争分夺秒:
                    tTimeSpan = baseSetting.TypeTimeSpan1;
                    result    = model.ProblemSubType == process.SubType;
                    break;

                case (int)eProblemType.一比高下:
                    tTimeSpan = baseSetting.TypeTimeSpan2;
                    result    = model.QuestionNumber == process.Number;
                    break;

                case (int)eProblemType.狭路相逢:
                    tTimeSpan = baseSetting.TypeTimeSpan3 + baseSetting.PartTimeSpan;
                    result    = model.QuestionNumber == process.Number;
                    break;
                }
                if (result)
                {
                    TimeSpan tSpan = DateTime.Now - process.AddTime;
                    if (tTimeSpan > 0 && tSpan.TotalSeconds > 0 &&
                        tTimeSpan + 5 > Convert.ToInt32(tSpan.TotalSeconds))
                    {
                        result = tTimeSpan - Convert.ToInt32(tSpan.TotalSeconds) + 5 > 0;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <bool> Issue()
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                List <UserProblemScore> list         = new List <UserProblemScore>();
                List <UserExamScore>    userExamList = new List <UserExamScore>();
                connection.Open();
                var users = await connection.QueryAsync <User>(@"
                            select * from [dbo].[User] where UserName!='admin' 
                                and ID not in(select distinct UserID from [dbo].[UserExamScore])");

                var problems = await connection.QueryAsync <Problem>(@"
                            select * from [dbo].[Problem]");

                foreach (var user in users)
                {
                    var userExam = new UserExamScore();
                    userExam.ID     = Guid.NewGuid();
                    userExam.UserID = user.ID;
                    userExamList.Add(userExam);
                    foreach (var problem in problems)
                    {
                        var userProblemScore = new UserProblemScore();
                        userProblemScore.ID              = Guid.NewGuid();
                        userProblemScore.UserID          = user.ID;
                        userProblemScore.ProblemID       = problem.ID;
                        userProblemScore.ProblemName     = problem.ProblemName;
                        userProblemScore.ProblemType     = problem.ProblemType;
                        userProblemScore.ProblemFeatures = problem.ProblemFeatures;
                        userProblemScore.ProblemScore    = problem.Score;
                        userProblemScore.Answer          = problem.Answer;
                        userProblemScore.ProblemSubType  = problem.ProblemSubType;
                        userProblemScore.QuestionNumber  = problem.QuestionNumber;
                        list.Add(userProblemScore);
                    }
                }
                IDbTransaction transaction = connection.BeginTransaction();
                try
                {
                    await connection.ExecuteAsync(@"
                    insert into [dbo].[UserExamScore]([ID],[UserID],IsOver) values(@ID,@UserID,0)
                        ", userExamList, transaction);

                    await connection.ExecuteAsync(@"
                    insert into [dbo].[UserProblemScore]([ID],[ProblemID],[ProblemName]
                    ,[ProblemFeatures] ,[Answer],[ProblemScore]
                    ,[ProblemType],[ProblemSubType],[QuestionNumber],[UserID],[IsSubmitOver]) 
                    values(@ID,@ProblemID,@ProblemName,@ProblemFeatures,@Answer,@ProblemScore
                        ,@ProblemType,@ProblemSubType,@QuestionNumber,@UserID,0)
                        ", list, transaction);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    //出现异常,事务Rollback
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
                return(true);
            }
        }