public JsonResult AddApp(AppointmentAddDto data, List <LabTestDto> labTests)
        {
            var result = _cashierService.Add(data, labTests);

            return(Json(new
            {
                success = result
            }));
        }
        //ten ten
        public bool Add(AppointmentAddDto data, List <LabTestDto> labTests)
        {
            var rs       = false;
            var appRepo  = RepositoryHelper.GetRepository <IAppointmentRepository>(UnitOfWork);
            var accRepo  = RepositoryHelper.GetRepository <IAccountRepository>(UnitOfWork);
            var paRepo   = RepositoryHelper.GetRepository <IPatientRepository>(UnitOfWork);
            var sgRepo   = RepositoryHelper.GetRepository <ISampleGettingRepository>(UnitOfWork);
            var slotRepo = RepositoryHelper.GetRepository <ISlotRepository>(UnitOfWork);

            try
            {
                //tao account
                var account = accRepo.GetAll().FirstOrDefault(p => p.PhoneNumber == data.Phone);
                if (account == null)
                {
                    accRepo.Create(new Account
                    {
                        PhoneNumber = data.Phone,
                        FullName    = data.Name,
                        IsDeleted   = false,
                    });
                }
                UnitOfWork.SaveChanges();
                //tao patient
                var     accId   = accRepo.GetAll().FirstOrDefault(p => p.PhoneNumber == data.Phone).AccountId;
                Patient patient = null;
                patient = new Patient();

                patient.AccountId = accId;
                patient.Gender    = data.Gender;
                //IdentityCardNumber = data.IdentityCardNumber,
                patient.DateOfBirth = data.DateOfBirth;
                patient.HomeAddress = data.Address;
                patient.FullName    = data.Name;
                patient.PhoneNumber = data.Phone;
                patient.IsDeleted   = false;
                paRepo.Create(patient);

                UnitOfWork.SaveChanges();
                patient.PatientCode = "BN" + patient.PatientId;

                //tao cuoc hen
                //var paId = paRepo.GetFirst(p => p.PhoneNumber == data.Phone).PatientId;//lấy Id bệnh nhân  dựa vào phone
                var appCode = CreateAppReturnCode(new Appointment //tạo app
                {
                    PatientId = patient.PatientId,
                    Status    = "NEW",
                    IsOnline  = false,
                    //Date = DateTime.Now.Date,
                    IsDeleted = false
                });
                UnitOfWork.SaveChanges();

                //xep lich hen cho tung loai xet nghiem
                var appId = appRepo.GetFirst(p => p.AppointmentCode == appCode).AppointmentId;//
                if (data.Mau == true)
                {
                    //tim slot va ban trong
                    var slotAndTable = GetEmptyTableAndSlot(1);
                    //neu con ban va slot trong thi moi tao lich hen
                    if (slotAndTable != null)
                    {
                        var sg = new SampleGetting //xong tạo sg ở đây
                        {
                            GettingDate   = DateTime.Now.Date,
                            AppointmentId = appId,
                            SampleId      = 1,
                            SlotId        = slotAndTable.slotId,
                            TableId       = slotAndTable.tableId,
                            IsDeleted     = false
                        };
                        sg.LabTestings = new List <LabTesting>();
                        foreach (var lt in labTests)
                        {
                            if (lt.SampleId == 1) // 1: Mau
                            {
                                var labTesting = new LabTesting();
                                labTesting.LabTestId = lt.LabTestId;
                                sg.LabTestings.Add(labTesting);
                            }
                        }
                        //tao lich hen loai xet nghiem mau
                        sgRepo.Create(sg);
                        //var ID = sgRepo.GetFirst(p => p.SampleGettingId == sgId).SampleGettingId;
                        rs = true;
                    }
                }
                if (data.NuocTieu == true)
                {
                    //tim slot va ban trong
                    var slotAndTable = GetEmptyTableAndSlot(1);
                    //neu con ban va slot trong thi moi tao lich hen
                    if (slotAndTable != null)
                    {
                        var sg = new SampleGetting //xong tạo sg ở đây
                        {
                            GettingDate   = DateTime.Now.Date,
                            AppointmentId = appId,
                            SampleId      = 2,
                            SlotId        = slotAndTable.slotId,
                            TableId       = slotAndTable.tableId,
                            IsDeleted     = false
                        };
                        sg.LabTestings = new List <LabTesting>();
                        foreach (var lt in labTests)
                        {
                            if (lt.SampleId == 2)
                            {
                                var labTesting = new LabTesting();
                                labTesting.LabTestId = lt.LabTestId;
                                sg.LabTestings.Add(labTesting);
                            }
                        }
                        //tao lich hen loai xet nghiem mau
                        sgRepo.Create(sg);
                        //var ID = sgRepo.GetFirst(p => p.SampleGettingId == sgId).SampleGettingId;
                        rs = true;
                    }
                }
                if (data.Phan == true)
                {
                    var slotAndTable = GetEmptyTableAndSlot(2);
                    if (slotAndTable != null)
                    {
                        var sg = new SampleGetting //xong tạo sg ở đây
                        {
                            GettingDate   = DateTime.Now.Date,
                            AppointmentId = appId,
                            SampleId      = 4,
                            SlotId        = slotAndTable.slotId,
                            TableId       = slotAndTable.tableId,
                            IsDeleted     = false
                        };
                        sg.LabTestings = new List <LabTesting>();
                        foreach (var lt in labTests)
                        {
                            if (lt.SampleId == 4)
                            {
                                var labTesting = new LabTesting();
                                labTesting.LabTestId = lt.LabTestId;
                                sg.LabTestings.Add(labTesting);
                            }
                        }
                        //tao lich hen loai xet nghiem phan
                        sgRepo.Create(sg);
                        rs = true;
                    }
                }
                if (data.TeBaoHoc == true)
                {
                    //tim slot va ban trong
                    var slotAndTable = GetEmptyTableAndSlot(3);
                    //neu con ban va slot trong thi moi tao lich hen
                    if (slotAndTable != null)
                    {
                        var sg = new SampleGetting //xong tạo sg ở đây
                        {
                            GettingDate   = DateTime.Now.Date,
                            AppointmentId = appId,
                            SampleId      = 3,
                            SlotId        = slotAndTable.slotId,
                            TableId       = slotAndTable.tableId,
                            IsDeleted     = false
                        };
                        sg.LabTestings = new List <LabTesting>();
                        foreach (var lt in labTests)
                        {
                            if (lt.SampleId == 3) // 1: Mau
                            {
                                var labTesting = new LabTesting();
                                labTesting.LabTestId = lt.LabTestId;
                                sg.LabTestings.Add(labTesting);
                            }
                        }
                        //tao lich hen loai xet nghiem mau
                        sgRepo.Create(sg);
                        //var ID = sgRepo.GetFirst(p => p.SampleGettingId == sgId).SampleGettingId;
                        rs = true;
                    }
                }
                if (data.Dich == true)
                {
                    var slotAndTable = GetEmptyTableAndSlot(4);
                    if (slotAndTable != null)
                    {
                        var sg = new SampleGetting //xong tạo sg ở đây
                        {
                            GettingDate   = DateTime.Now.Date,
                            AppointmentId = appId,
                            SampleId      = 5,
                            SlotId        = slotAndTable.slotId,
                            TableId       = slotAndTable.tableId,
                            IsDeleted     = false
                        };
                        sg.LabTestings = new List <LabTesting>();
                        foreach (var lt in labTests)
                        {
                            if (lt.SampleId == 5)
                            {
                                var labTesting = new LabTesting();
                                labTesting.LabTestId = lt.LabTestId;
                                sg.LabTestings.Add(labTesting);
                            }
                        }
                        //tao lich hen loai xet nghiem dich
                        sgRepo.Create(sg);
                        rs = true;
                    }
                }

                UnitOfWork.SaveChanges();
            }
            catch (Exception ex) { return(false); }
            return(rs);
        }