//[EnableCors(origins: "*", headers: "*", methods: "*")]
        public IHttpActionResult LayThongTinCaNhan([FromBody] TestNhanData data)
        {
            if (data.CMND != null && data.CMND != "")
            {
                var obj = db.Employees.Where(w => w.CMND == data.CMND).Select(s => new { RowID = s.RowID, Fullname = s.Fullname, CMND = s.CMND, Phone = s.Phone, Address = s.Birthday }).FirstOrDefault();



                return(Ok(obj));
            }
            else
            {
                return(BadRequest("Tham số CMND truyền vào rỗng"));
            }
        }
        //[EnableCors(origins: "*", headers: "*", methods: "*")]
        public IHttpActionResult ChiTietNhanVien([FromBody] TestNhanData data)
        {
            int month   = Int32.Parse(data.Month.Split('-')[1]);
            int year    = Int32.Parse(data.Month.Split('-')[0]);
            var nowTime = DateTime.Now;

            var dayInMonth = DateTime.DaysInMonth(2020, month);

            var fromDate = new DateTime(nowTime.Year, month, 1);
            var toDate   = new DateTime(nowTime.Year, month, dayInMonth);


            //var totalHour = db.Attendance_Header.Where(w => w.Employee.CMND == data.CMND && w.AttendanceShortDate >= fromDate && w.AttendanceShortDate <= toDate).Sum(s => s != null ? s.TotalWorkingHours : 0);


            var rowIDEmployee = db.Employees.Where(w => w.CMND == data.CMND).Select(s => s.RowID).FirstOrDefault();


            //ViewBag.TotalHourThisMonth = Math.Round(totalHour, 1);



            //lấy danh sách tất cả ngày trong 1 tháng

            List <DateTime>        listDatetimes     = new List <DateTime>();
            List <ChiTietChamCong> listGioVaoSomNhat = new List <ChiTietChamCong>();
            List <ChiTietChamCong> listGioRaSomNhat  = new List <ChiTietChamCong>();


            for (int i = 1; i <= dayInMonth; i++)
            {
                DateTime d = new DateTime(year, month, i);
                DateTime fromDynamicDate = new DateTime(d.Year, d.Month, d.Day, 0, 0, 0);
                DateTime toDynamicDate   = new DateTime(d.Year, d.Month, d.Day, 23, 59, 59);


                listDatetimes.Add(d);



                //lấy các giờ vào các ngày !
                var listGioVao1Ngay = db.Attendance_Detail.Where(w => w.RowIDEmployee == rowIDEmployee && w.Type == "IN" && w.CreatedDate.Value >= fromDynamicDate && w.CreatedDate <= toDynamicDate).ToList();


                if (listGioVao1Ngay.Count == 0)
                {
                    //continue;
                }


                var listGioRa1Ngay = db.Attendance_Detail.Where(w => w.RowIDEmployee == rowIDEmployee && w.Type == "OUT" && w.CreatedDate.Value >= fromDynamicDate && w.CreatedDate <= toDynamicDate).ToList();


                if (listGioRa1Ngay.Count == 0)
                {
                    //continue;
                }


                var gioVaoSomNhat = listGioVao1Ngay.FirstOrDefault();

                var gioRaSomNhat = listGioRa1Ngay.FirstOrDefault();


                listGioVaoSomNhat.Add(new ChiTietChamCong()
                {
                    RowIDEmployeeEdited = (gioVaoSomNhat != null && gioVaoSomNhat.RowIDEmployeeEdited.HasValue ? gioVaoSomNhat.RowIDEmployeeEdited.Value : gioRaSomNhat != null && gioRaSomNhat.RowIDEmployeeEdited.HasValue ? gioRaSomNhat.RowIDEmployeeEdited.Value : 0)
                    ,
                    GioVaoSomNhat = (gioVaoSomNhat != null ? gioVaoSomNhat.CreatedDate : null),
                    GioRaSomNhat  = (gioRaSomNhat != null ? gioRaSomNhat.CreatedDate : null),
                    LyDo          = (gioVaoSomNhat != null ? gioVaoSomNhat.AttendanceReason.Name.ToString() : ""),
                    Loai          = "GioVaoSomNhat"
                });
            }


            List <ChiTietChamCong> listTam = new List <ChiTietChamCong>();


            foreach (var item in listDatetimes)
            {
                listTam.Add(new ChiTietChamCong {
                    NgayGio = item, GioVaoSomNhat = null, GioRaSomNhat = null, Loai = "Rong", LyDo = ""
                });
            }



            foreach (var chitiet in listTam)
            {
                var fromDateSom = new DateTime(chitiet.NgayGio.Year, chitiet.NgayGio.Month, chitiet.NgayGio.Day, 00, 00, 00);
                var toDateTre   = new DateTime(chitiet.NgayGio.Year, chitiet.NgayGio.Month, chitiet.NgayGio.Day, 23, 59, 59);



                foreach (var item in listGioVaoSomNhat)
                {
                    if ((item.GioVaoSomNhat >= fromDateSom && item.GioVaoSomNhat <= toDateTre) || (item.GioRaSomNhat >= fromDateSom && item.GioRaSomNhat <= toDateTre))
                    {
                        chitiet.GioVaoSomNhat       = item.GioVaoSomNhat;
                        chitiet.GioRaSomNhat        = item.GioRaSomNhat;
                        chitiet.RowIDEmployeeEdited = item.RowIDEmployeeEdited;
                        chitiet.LyDo = item.LyDo;
                        chitiet.Loai = item.Loai;
                    }
                }
            }



            //ViewBag.listGioVaoSomNhat = listGioVaoSomNhat.Distinct().ToList();
            //ViewBag.listGioVaoTreNhat = listGioVaoTreNhat.Distinct().ToList();
            //ViewBag.listGioRaSomNhat = listGioRaSomNhat.Distinct().ToList();
            //ViewBag.listGioRaSomNhat = listGioRaSomNhat.Distinct().ToList();



            //ViewBag.listDatetimes = listDatetimes;



            //List<List<ChiTietChamCong>> complexChiTietChamCong = new List<List<ChiTietChamCong>>();
            //complexChiTietChamCong.Add(listGioVaoSomNhat.Distinct().ToList());
            //complexChiTietChamCong.Add(listGioVaoTreNhat.Distinct().ToList());
            //complexChiTietChamCong.Add(listGioRaSomNhat.Distinct().ToList());
            //complexChiTietChamCong.Add(listGioRaSomNhat.Distinct().ToList())



            //var listCombined = listGioVaoSomNhat.Concat(listGioVaoTreNhat).Concat(listGioRaSomNhat).Concat(listGioRaSomNhat).ToList();



            return(Ok(listTam.ToList()));
        }