public List <EmployeeResponseDetail> ValidateEmployeeExistsOrNot(List <EmployeeRequestDetail> reqDetailList)
        {
            List <EmployeeResponseDetail> resDetailList = new List <EmployeeResponseDetail>();

            var existingEmployeeDic = _employeeManager.GetEmployeesByPan(reqDetailList.Select(i => i.Pan).ToList()).ToDictionary(i => i.Pan);

            foreach (var reqDetail in reqDetailList)
            {
                EmployeeResponseDetail resDetail = new EmployeeResponseDetail();
                resDetail.TransactionId = reqDetail.TransactionId;
                try
                {
                    if (existingEmployeeDic.ContainsKey(reqDetail.Pan) && !string.IsNullOrEmpty(existingEmployeeDic[reqDetail.Pan].Description))
                    {
                        throw new ApiRejectionException(Enums.RejectionCode.RC11, "Employee doesn't exist");
                    }
                    resDetail.TransactionStatus = Enums.ApiStatus.Success.ToString();
                }
                catch (ApiRejectionException ex)
                {
                    resDetail.RejectionDetail   = new Models.RejectionDetail(ex.Code, ex.Message);
                    resDetail.TransactionStatus = Enums.ApiStatus.Rejected.ToString();
                }
                resDetailList.Add(resDetail);
            }
            return(resDetailList);
        }
        public List <EmployeeResponseDetail> ValidateEachTransaction(List <EmployeeRequestDetail> reqDetailList)
        {
            List <EmployeeResponseDetail> responseDetailList = new List <EmployeeResponseDetail>();

            var existingEmployeeDic = _employeeManager.GetEmployeesByPan(reqDetailList.Select(i => i.Pan).ToList()).ToDictionary(i => i.Pan);


            foreach (var reqDetail in reqDetailList)
            {
                EmployeeResponseDetail res = new EmployeeResponseDetail();
                res.TransactionId = reqDetail.TransactionId;

                try
                {
                    if (string.IsNullOrEmpty(reqDetail.FirstName))
                    {
                        throw new ApiRejectionException(Enums.RejectionCode.RC7, "FirstName is mandatory");
                    }

                    if (string.IsNullOrEmpty(reqDetail.Pan))
                    {
                        throw new ApiRejectionException(Enums.RejectionCode.RC8, "Pan is mandatory");
                    }

                    DateTime?dateOfBirth = GetValidDateTime(reqDetail.BirthDate);

                    if (dateOfBirth == null && !string.IsNullOrEmpty(reqDetail.BirthDate))
                    {
                        throw new ApiRejectionException(Enums.RejectionCode.RC9, "Birth Date should be in format dd-MM-yyyy");
                    }

                    if (existingEmployeeDic.ContainsKey(reqDetail.Pan) && string.IsNullOrEmpty(existingEmployeeDic[reqDetail.Pan].Description))
                    {
                        throw new ApiRejectionException(Enums.RejectionCode.RC10, "Employee already exists");
                    }


                    reqDetail.DateOfBirth = dateOfBirth;
                    res.TransactionStatus = Enums.ApiStatus.Success.ToString();
                }
                catch (ApiRejectionException ex)
                {
                    res.TransactionStatus = Enums.ApiStatus.Rejected.ToString();
                    res.RejectionDetail   = new Models.RejectionDetail(ex.Code, ex.Message);
                }
                responseDetailList.Add(res);
            }
            return(responseDetailList);
        }
        //[Route("GetEmployee")]
        public HttpResponseMessage GetEmployee()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string           xmlResponse = string.Empty;
            var              xml         = Request.Content.ReadAsStringAsync().Result;
            EmployeeResponse response    = new EmployeeResponse();
            long?            apiLogId    = null;
            var              request     = new EmployeeRequest();

            try
            {
                request = XmlUtils.Deserialize <EmployeeRequest>(xml);
                ModifyRequest(request);
                response = InitializeResponse(request);

                CreateCache();

                //insert into CoreApiLog
                apiLogId = _apiLogManager.InsertIntoApiLog(new ApiLogViewModel()
                {
                    SysApiId = _api.Id, Request = xml, RequestId = request.RequestId, Token = request.Token
                });


                _apiRequestIdCacheManager.ValidateRequestIdInsertIfNotAndThrowIfExists(_api.Id, request.RequestId);


                _employeeApiValidationManager.AuthorizeEmployeeApiAccess(_api.Id, request.Token);

                _employeeApiValidationManager.ValidateIfTransactionArePresent(request);

                var employeeList = _employeeManager.GetEmployeesByPan(request.EmployeeRequestDetails.Select(i => i.Pan).ToList());

                var empResLst = new List <EmployeeResponseDetail>();
                var empReqDic = request.EmployeeRequestDetails.ToDictionary(i => i.Pan);
                foreach (var employee in employeeList)
                {
                    var empReqObj = empReqDic[employee.Pan];
                    EmployeeResponseDetail empResDetail = new EmployeeResponseDetail();
                    empResDetail.TransactionId = empReqObj.TransactionId;
                    if (!string.IsNullOrEmpty(employee.Description))
                    {
                        empResDetail.RejectionDetail   = new RejectionDetail(RejectionCode.RC6.ToString(), employee.Description);
                        empResDetail.TransactionStatus = ApiStatus.Rejected.ToString();
                    }
                    else
                    {
                        empResDetail.FirstName         = employee.FirstName;
                        empResDetail.LastName          = employee.LastName;
                        empResDetail.Pan               = employee.Pan;
                        empResDetail.BirthDate         = employee.BirthDate.HasValue ? employee.BirthDate.Value.ToString("dd-MM-yyyy") : null;
                        empResDetail.TransactionStatus = ApiStatus.Success.ToString();
                    }

                    empResLst.Add(empResDetail);
                }

                response.EmployeeResponseDetails = empResLst;
                response.RequestStatus           = ApiStatus.Success.ToString();
            }
            catch (ApiRejectionException apiEx)
            {
                _log.Error("Error in GetEmployee ", apiEx);
                PopulateRejectedResponse(response, apiEx.Code, apiEx.Message);
            }
            catch (Exception ex)
            {
                _log.Error("Error in GetEmployee ", ex);

                PopulateRejectedResponse(response, RejectionCode.RC5.ToString(), "Unexpected exception has occured with detail - " + ex.Message);
            }
            finally
            {
                xmlResponse = XmlUtils.Serialize <EmployeeResponse>(response);
                sw.Stop();
                var totalTimeTakenInMs = (long)sw.Elapsed.TotalMilliseconds;
                //update CoreApiLog async
                Task.Run(() => UpdateApiLog(apiLogId.Value, xmlResponse, totalTimeTakenInMs));
            }

            return(new HttpResponseMessage()
            {
                Content = new StringContent(xmlResponse, System.Text.Encoding.UTF8, "application/xml")
            });
        }