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.CourseQuestionServices
{
    public class CourseQuestionServices
    {


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


        public Task <List<CourseQuestions>> GetCourseQuestionAsync(string strCurrentUser)
        {
            List<CourseQuestions> ColCourseQuestions = new List<CourseQuestions>();
            ColCourseQuestions = (from courseQuestions in _context.CourseQuestions select courseQuestions).ToList();
            return Task.FromResult(ColCourseQuestions);
        }

        public Task<CourseQuestions> CreateCourseQuestionsAsync(CourseQuestions objCourseQuestions)
        {
            _context.CourseQuestions.Add(objCourseQuestions);
            _context.SaveChanges();
            return Task.FromResult(objCourseQuestions);
        }


        public Task<bool> UpdateCourseQuestionsAsync(CourseQuestions objCourseQuestions)
        {
            var ExistingCourseQuestions =
                _context.CourseQuestions
                .Where(x => x.CourseQuestionsID == objCourseQuestions.CourseQuestionsID)
                .FirstOrDefault();
            if (ExistingCourseQuestions != null)
            {
                ExistingCourseQuestions.Display =
                    objCourseQuestions.Display;
                ExistingCourseQuestions.Value =
                    objCourseQuestions.Value;
                ExistingCourseQuestions.CourseID =
                    objCourseQuestions.CourseID;
                ExistingCourseQuestions.QuestionID =
                    objCourseQuestions.QuestionID;

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



    }
}
