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); } }
public async Task <T> CreateAsync(T model) { await _context.Set <T>().AddAsync(model); await _context.SaveChangesAsync(); return(model); }
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(); } }
public IEnumerable <Quiz> Get() { var userId = HttpContext.User.Claims.First().Value; return(_context.Set <Quiz>().Where(u => u.OwnerId == new Guid(userId))); }
public IEnumerable <Question> Get() { return(_context.Set <Question>()); }
public void Add(T item) { db.Set <T>().Add(item); Save(); }
public virtual async Task <T> GetById(string id) { return(await Db.Set <T>().FindAsync(id)); }
public async Task AddAsync(TEntity entity) { await _context.Set <TEntity>().AddAsync(entity); }