using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using SPWA.DataAccess.Data.MJDbContext;
using SPWA.DataAccess.Data.Models;

namespace SPWA.DataAccess.Data.QuestionServices
{
    public class QuestionServices
    {


        private readonly MJContext _context;
        public QuestionServices(MJContext context)
        {
            _context = context;
        }


        public Task <List<Question>> GetQuestionAsync(string strCurrentUser)
        {
            List<Question> ColQuestion = new List<Question>();
            ColQuestion = (from question in _context.Question select question).ToList();
            return Task.FromResult(ColQuestion);
        }

        public Task<Question> CreateQuestionAsync(Question objQuestion)
        {
            _context.Question.Add(objQuestion);
            _context.SaveChanges();
            return Task.FromResult(objQuestion);
        }


        public Task<bool> UpdateQuestionAsync(Question objQuestion)
        {
            var ExistingQuestion =
                _context.Question
                .Where(x => x.QuestionID == objQuestion.QuestionID)
                .FirstOrDefault();
            if (ExistingQuestion != null)
            {
                ExistingQuestion.value =
                    objQuestion.value;
                ExistingQuestion.text =
                    objQuestion.text;
                ExistingQuestion.Default =
                    objQuestion.Default;
                ExistingQuestion.display =
                    objQuestion.display;
               

                _context.SaveChanges();
            }
            else
            {
                return Task.FromResult(false);
            }
            return Task.FromResult(true);
        }



    }
}
