public bool DeleteData(T data)
 {
     using (var db = new QuizContext())
     {
         db.Set <T>().Attach(data);
         db.Set <T>().Remove(data);
         db.SaveChanges();
         return(true);
     }
 }
 public IList <T> GetDataList()
 {
     using (var db = new QuizContext())
     {
         return(db.Set <T>().ToList());
     }
 }
 public T GetData(int dataId)
 {
     using (var db = new QuizContext())
     {
         return((T)Convert.ChangeType(db.Set <T>().Find(dataId), typeof(T)));
     }
 }
 public bool AddData(T data)
 {
     using (var db = new QuizContext())
     {
         db.Set <T>().Add(data);
         db.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 5
0
        public async Task <T> CreateAsync(T model)
        {
            await _context.Set <T>().AddAsync(model);

            await _context.SaveChangesAsync();

            return(model);
        }
Exemplo n.º 6
0
        public async Task Answer([FromBody] Model.QuestionAnswer answer)
        {
            var answeredOption = await _quizContext.Set <QuestionOption>()
                                 .FirstOrDefaultAsync(x => x.Id == answer.Option);

            if (answeredOption != null)
            {
                answeredOption.Result = answer.Result;
                await _quizContext.SaveChangesAsync();
            }
        }
Exemplo n.º 7
0
        public IEnumerable <Quiz> Get()
        {
            var userId = HttpContext.User.Claims.First().Value;

            return(_context.Set <Quiz>().Where(u => u.OwnerId == new Guid(userId)));
        }
Exemplo n.º 8
0
 public IEnumerable <Question> Get()
 {
     return(_context.Set <Question>());
 }
Exemplo n.º 9
0
 public void Add(T item)
 {
     db.Set <T>().Add(item);
     Save();
 }
Exemplo n.º 10
0
 public virtual async Task <T> GetById(string id)
 {
     return(await Db.Set <T>().FindAsync(id));
 }
Exemplo n.º 11
0
 public async Task AddAsync(TEntity entity)
 {
     await _context.Set <TEntity>().AddAsync(entity);
 }