示例#1
0
        public bool Create(ExamDTO examDTO, Guid userId)
        {
            try
            {
                Exam exam = new Exam
                {
                    Id          = Guid.NewGuid(),
                    Password    = RandomString(8),
                    OwnerId     = userId,
                    Time        = examDTO.Time,
                    Name        = examDTO.Name,
                    BankId      = examDTO.BankId,
                    StartTime   = examDTO.StartTime,
                    EndTime     = examDTO.EndTime,
                    Description = examDTO.Description
                };
                DbContext.Exams.Add(exam);

                examDTO.QuestionId.ForEach(x => DbContext.ExamQuestions.Add(new ExamQuestion
                {
                    QuestionId = x,
                    ExamId     = exam.Id,
                }));

                DbContext.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        //创建一个用户
        public bool CreateUser(string account, string password, string nikeName, string status)
        {
            var    isUser       = _onlineTestContext.User.Where(u => u.Account.Equals(account)).ToList();
            string validataCode = System.Guid.NewGuid().ToString();

            if (isUser.Count != 0)
            {
                return(false);
            }
            else
            {
                User user = new User()
                {
                    Account          = account,
                    Password         = password,
                    NikeName         = nikeName,
                    Status           = status,
                    CreateTime       = DateTime.Now,
                    VerificationCode = validataCode,
                    IsVerification   = -1
                };
                _onlineTestContext.User.Add(user);
                _onlineTestContext.SaveChanges();
                return(SendEMail(account, validataCode));
            }
        }
示例#3
0
 public bool Create(QuestionBank newBank)
 {
     try
     {
         DbContext.QuestionBanks.Add(newBank);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Update(Question updatedQuestion)
 {
     try
     {
         DbContext.Questions.Update(updatedQuestion);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Create(Score score)
 {
     try
     {
         DbContext.Scores.Add(score);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
 public bool Create(List <Answer> newAnswers)
 {
     try
     {
         foreach (Answer answer in newAnswers)
         {
             DbContext.Answers.Add(answer);
         }
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#7
0
 public T Edit <T>(T entity) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
         return(entity);
     }
 }
示例#8
0
 public T Delete <T>(T entity) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         DbSet <T> dbSet = context.Set <T>();
         dbSet.Remove(entity);
         context.SaveChanges();
         return(entity);
     }
 }
示例#9
0
        private readonly int DefaultNum = 0;  //默认数量
        public bool CreateArticle(int uId, string title, string content, string label)
        {
            Article article = new Article()
            {
                UserId     = uId,
                Title      = title,
                Content    = content,
                CreateTime = DateTime.Now,
                Label      = label,
                PraiseNum  = DefaultNum, //赞
                TrampleNum = DefaultNum, //踩
                CommentNum = DefaultNum,
                IsPublish  = false,
                IsDelete   = false,
            };

            _onlineTestContext.Article.Add(article);
            _onlineTestContext.SaveChanges();
            return(true);
        }
示例#10
0
 public bool EditAll <T>(List <T> entityList) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         try
         {
             foreach (var entity in entityList)
             {
                 context.Entry(entity).State = EntityState.Modified;
             }
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
 public bool Create(UserDTO userDTO)
 {
     try
     {
         User user = new User
         {
             Id          = Guid.NewGuid(),
             Username    = userDTO.Username,
             Password    = userDTO.Password,
             DateCreated = DateTime.Now
         };
         DbContext.Users.Add(user);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#12
0
 public bool AddAll <T>(List <T> entityList) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         try
         {
             DbSet <T> dbSet = context.Set <T>();
             foreach (var entity in entityList)
             {
                 dbSet.Add(entity);
             }
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
示例#13
0
        private static readonly object locker = new object();   //锁
        public bool CreateSubject(string name)
        {
            Subject subject = _onlineTestContext.Subject.SingleOrDefault(s => s.Name.Equals(name));

            if (subject != null)
            {
                return(false);
            }
            else
            {
                Subject newSubject = new Subject()
                {
                    Name          = name,
                    QuestionCount = DefaultQueCount
                };
                _onlineTestContext.Subject.Add(newSubject);
                _onlineTestContext.SaveChanges();
                return(true);
            }
        }