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 TargetManager : BLBase
    {
        public IList<TargetDTO> GetTarget(int UserId, int Year)
        {
            IList<GetTarget_Result> Result = context.GetTarget(UserId, null, null, Year, null, null, null).ToList();

            IList<TargetDTO> Target = null;

            if (Result != null)
            {
                Mapper.CreateMap<GetTarget_Result, TargetDTO>();
                Target = Mapper.Map<IList<GetTarget_Result>, IList<TargetDTO>>(Result).ToList();
            }

            return Target;
        }

        public void InsertUpdateTargets(IList<TargetDTO> TargetList)
        {
            foreach (TargetDTO target in TargetList)
            {
                context.InsertUpdateTarget(target.Target_Id,
                                           target.Month,
                                           target.Year,
                                           target.Sales,
                                           target.Collection,
                                           target.Secondary_Sales,
                                           target.Site_User_Id);
            }
        }
    }
}
