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


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


        public Task <List<Evaluation>> GetEvaluationAsync(string strCurrentUser)
        {
            List<Evaluation> ColEvaluation = new List<Evaluation>();
            ColEvaluation = (from evaluation in _context.Evaluation select evaluation).ToList();
            return Task.FromResult(ColEvaluation);
        }

        public Task<Evaluation> CreateEvaluationAsync(Evaluation objEvaluation)
        {
            _context.Evaluation.Add(objEvaluation);
            _context.SaveChanges();
            return Task.FromResult(objEvaluation);
        }


        public Task<bool> UpdateEvaluationAsync(Evaluation objEvaluation)
        {
            var ExistingEvaluation =
                _context.Evaluation
                .Where(x => x.EvaluationID == objEvaluation.EvaluationID)
                .FirstOrDefault();
            if (ExistingEvaluation != null)
            {
                ExistingEvaluation.EvalType =
                    objEvaluation.EvalType;
                ExistingEvaluation.Sprint =
                    objEvaluation.Sprint;
                ExistingEvaluation.StudentId =
                    objEvaluation.StudentId;
                ExistingEvaluation.QAnswers =
                    objEvaluation.QAnswers;
                

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



    }
}
