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

namespace BusinessLayer
{
    public class VisitManager : BLBase
    {
        public IList<ActiveContactCustomerLocationDTO> GetActiveContactCustomerLocation(int UserId, int? Search_UserId)
        {
            IList<GetActiveContactCustomerLocation_Result> Result = null;

            if (Search_UserId == null)
                Result = context.GetActiveContactCustomerLocation(UserId).ToList();
            else
                Result = context.GetActiveContactCustomerLocation(UserId).Where(c => c.Site_User_Id == Search_UserId).ToList();

            IList<ActiveContactCustomerLocationDTO> ContCustLoc = null;
            if (Result != null)
            {
                Mapper.CreateMap<GetActiveContactCustomerLocation_Result, ActiveContactCustomerLocationDTO>();
                ContCustLoc = Mapper.Map<IList<GetActiveContactCustomerLocation_Result>, IList<ActiveContactCustomerLocationDTO>>(Result);
            }

            return ContCustLoc;
        }

        public void InsertVisit(VisitDTO Visit)
        {
            context.InsertVisit(Visit.Customer_Id,
                                 Visit.Customer_Name,
                                 Visit.Customer_Name_BL,
                                 Visit.Location_Id,
                                 Visit.Contact_Id,
                                 Visit.Contact_Name,
                                 Visit.Contact_Name_BL,
                                 Visit.Department,
                                 Visit.Department_BL,
                                 Visit.Mobile,
                                 Visit.Site_User_Id,
                                 Visit.Date,
                                 Visit.Objective,
                                 Visit.Time_In,
                                 Visit.Time_Out,
                                 Visit.Time_w_Merchandiser,
                                 Visit.Collection,
                                 Visit.Secondary_Sales,
                                 Visit.Sales_LPO_Received,
                                 Visit.Discount,
                                 Visit.Sales_Return,
                                 Visit.Remarks,
                                 Visit.Updated_By);
        }

        public void UpdateVisit(VisitDTO Visit)
        {
            context.UpdateVisit( Visit.DSR_Id,
                                 Visit.Customer_Id,
                                 Visit.Customer_Name,
                                 Visit.Customer_Name_BL,
                                 Visit.Location_Id,
                                 Visit.Contact_Id,
                                 Visit.Contact_Name,
                                 Visit.Contact_Name_BL,
                                 Visit.Department,
                                 Visit.Department_BL,
                                 Visit.Mobile,
                                 Visit.Site_User_Id,
                                 Visit.Date,
                                 Visit.Objective,
                                 Visit.Time_In,
                                 Visit.Time_Out,
                                 Visit.Time_w_Merchandiser,
                                 Visit.Collection,
                                 Visit.Secondary_Sales,
                                 Visit.Sales_LPO_Received,
                                 Visit.Discount,
                                 Visit.Sales_Return,
                                 Visit.Remarks,
                                 Visit.Updated_By);
        }
    }
}
