using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using DataAccess;
using DTO;

namespace BusinessLayer
{
    public class AttendanceManager : BLBase
    {
        public AbsentDTO GetAbsent(int UserId, DateTime Date)
        {
            GetAbsent_Result Result = context.GetAbsent(null, Date, UserId).FirstOrDefault();

            AbsentDTO absent = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetAbsent_Result, AbsentDTO>();
                absent = Mapper.Map<GetAbsent_Result, AbsentDTO>(Result);
            }

            return absent;
        }

        public void InsertAbsent(DateTime Date, int UserId)
        {
            context.InsertUpdateAbsent(null, Date, UserId);
        }

        public void DeleteAbsent(DateTime Date, int UserId)
        {
            Absent absent = context.Absents.Where(c => c.Date == Date && c.Site_User_Id == UserId).FirstOrDefault();
            if (absent != null)
            {
                context.Absents.Remove(absent);
                context.SaveChanges();
            }
        }
    }
}
