Exemplo n.º 1
0
    public static bool SendBacktoSameCourse(string testday, string username)
    {
        using (dbExtranetEntitiesWord db = new dbExtranetEntitiesWord())
        {
            using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                try
                {
                    var removeusertest = db.Beg_WordUserTest.Where(x => x.Username == username && x.Day == testday).ToList();
                    db.Beg_WordUserTest.RemoveRange(removeusertest);
                    db.SaveChanges();
                    trans.Commit();

                    return false;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }
        }

    }
Exemplo n.º 2
0
    public static void AnswerGiven(int testid, string username, int begid)
    {
        using (dbExtranetEntitiesWord db = new dbExtranetEntitiesWord())
        {
            using (var trans = db.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                try
                {
                    var getquestioninfo = db.Beg_WordTest.SingleOrDefault(x => x.Id == testid);
                    var getAnstext = db.Beg_Word.SingleOrDefault(x => x.Id == begid);
                    var testgiven = new Beg_WordUserTest()
                    {
                        BegWordId = getquestioninfo.BegWordId,
                        Username = username,
                        BegWordTestId = testid,
                        Day = getquestioninfo.Day,
                        Question = getquestioninfo.Question,
                        QuestionNumber = getquestioninfo.QuestionNumber,
                        Answer = getAnstext.Word

                    };
                    db.Beg_WordUserTest.Add(testgiven);
                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }

            }
        }
    }