Esempio n. 1
0
        public async Task <UserOwnedQuestionModel> GetUserOwnedQuestion(string id)
        {
            var exp = UserOwnedQuestionModel.BuildModel();

            return(await _context.UserOwnedQuestions.AsExpandable().Where(x => x.Id == id)
                   .Select(z => exp.Invoke(z))
                   .FirstOrDefaultAsync());
        }
Esempio n. 2
0
        public async Task <IEnumerable <UserOwnedQuestionModel> > GetUserOwnedQuestions(string userId)
        {
            var exp = UserOwnedQuestionModel.BuildModel();

            return(await _context.UserOwnedQuestions.AsExpandable()
                   .Where(x => x.QuizzardUserId == userId && x.ArchivedOn == null)
                   .Select(x => exp.Invoke(x))
                   .ToListAsync());
        }
Esempio n. 3
0
        public async Task <bool> EditUserOwnedQuestion(UserOwnedQuestionModel model)
        {
            var exp = UserOwnedQuestionModel.BuildModel();

            try
            {
                var toChange = await _context.UserOwnedQuestions.Where(x => x.Id == model.Id)
                               .FirstOrDefaultAsync();

                if (toChange != null)
                {
                    toChange.QuestionText = model.QuestionText;
                    toChange.UserOwnedAnswers.Clear();
                    foreach (var answer in model.Answers)
                    {
                        toChange.UserOwnedAnswers.Add(new UserOwnedAnswer()
                        {
                            AnswerText          = answer.AnswerText,
                            Correctness         = answer.Correctness,
                            Id                  = answer.Id ?? Guid.NewGuid().ToString(),
                            UserOwnedQuestionId = model.Id
                        });
                    }
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }


            return(true);
        }