//[Authorize(Roles  = "Admin")]
        public async Task <IActionResult> Put([FromBody] DetailPasien DetailPasien)
        {
            try
            {
                await _DetailPasien.UpdateAsync(DetailPasien);

                return(Ok("Data berhasil diupdate"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task UpdateAsync(Pengguna obj)
        {
            try
            {
                //harus dapetin role dari user
                var getdatapengguna = await getpenggunausername(obj.Username);

                if (getdatapengguna.rolename == null)
                {
                    await _UserRole.AddUserToRoleAsync(obj.Username, obj.rolename);
                }
                else
                {
                    await _UserRole.RemoveuserRole(getdatapengguna.Username, getdatapengguna.rolename);

                    await _UserRole.AddUserToRoleAsync(obj.Username, obj.rolename);
                }
                if (getdatapengguna.rolename == null)
                {
                    await _UserRole.AddUserToRoleAsync(obj.Username, obj.rolename);
                }
                if (obj.rolename == "Perawat")
                {
                    if (getdatapengguna.IdPasien != null)
                    {
                        obj.IdPasien = null;
                    }
                    if (await _prosentase.getbyusername(obj.Username) == null)
                    {
                        await _prosentase.Deletebyusername(obj.Username);
                    }
                    var detailpasien = await _detailPasien.getusername(obj.Username);

                    DetailPegawai pegawai = new DetailPegawai();

                    var pegawaii = await _detailPegawai.getusername(obj.Username, obj.TenantID);

                    if (pegawaii == null)

                    {
                        pegawai.Username    = obj.Username;
                        pegawai.Jabatan     = "Perawat";
                        pegawai.TanggalJoin = DateTime.Today;
                        await _detailPegawai.CreateAsync(pegawai);
                    }
                    else
                    {
                        pegawai.Username    = obj.Username;
                        pegawai.Jabatan     = "Perawat";
                        pegawai.TanggalJoin = DateTime.Today;
                        await _detailPegawai.UpdateAsync(pegawai);
                    }
                    // create data pegawai
                }
                if (obj.rolename == "Dokter")
                {
                    if (getdatapengguna.IdPasien != null)
                    {
                        obj.IdPasien = null;
                    }
                    if (getdatapengguna.Prosentase == 0)
                    {
                        obj.Prosentase = 30;
                    }

                    var detailpasien = await _detailPasien.getusername(obj.Username);

                    //if (detailpasien != null)
                    //{
                    //    await _detailPasien.DeleteByuser(obj.Username);
                    //}
                    //tidak akan di delete karena bergantung pada detailidpasien pada bagian transaksi
                    DetailPegawai pegawai = new DetailPegawai();

                    var pegawaii = await _detailPegawai.getusername(obj.Username, getdatapengguna.TenantID);

                    if (pegawaii == null)

                    {
                        pegawai.Username    = obj.Username;
                        pegawai.Jabatan     = "Dokter";
                        pegawai.TanggalJoin = DateTime.Today;
                        await _detailPegawai.CreateAsync(pegawai);
                    }
                    else
                    {
                        pegawai.Username    = obj.Username;
                        pegawai.Jabatan     = "Dokter";
                        pegawai.TanggalJoin = DateTime.Today;
                        await _detailPegawai.UpdateAsync(pegawai);
                    }

                    var dt_prosen = await _context.Prosentase.Where(r => r.Username == getdatapengguna.Username && r.TenantID == getdatapengguna.TenantID).ToListAsync();

                    if (dt_prosen == null)
                    {
                        var dt_jenisTindakan = await _context.JenisTindakan.Where(r => r.TenantID == getdatapengguna.TenantID).Include(r => r.Prosentase).ToListAsync();



                        foreach (var dt_jenis in dt_jenisTindakan)
                        {
                            // create data pegawai
                            Prosentase prosen = new Prosentase();
                            prosen.Username        = obj.Username;
                            prosen.IdJenisTindakan = dt_jenis.IdJenisTindakan;
                            prosen.Prosen          = obj.Prosentase;
                            prosen.TenantID        = getdatapengguna.TenantID;
                            prosen.DetailPegawaiID = pegawaii.DetailPegawaiID;
                            await _prosentase.CreateAsync(prosen);
                        }
                    }
                }
                else if (obj.rolename == "Pasien")
                {
                    //kasi contraint klo ada data pasien nya g usah di delete tapi di update
                    // klo g ada dia create
                    DetailPasien detpasien = new DetailPasien();
                    var          detailpas = await _detailPasien.getusername(obj.Username);

                    if (detailpas == null)
                    {
                        obj.IdPasien         = "pasien" + obj.Username;
                        detpasien.IdPasien   = obj.IdPasien;
                        detpasien.Username   = obj.Username;
                        detpasien.Registrasi = DateTime.Today;
                        await _detailPasien.CreateAsync(detpasien);
                    }
                    else
                    {
                        obj.IdPasien         = "pasien" + obj.Username;
                        detpasien.IdPasien   = obj.IdPasien;
                        detpasien.Username   = obj.Username;
                        detpasien.Registrasi = DateTime.Today;
                        await _detailPasien.UpdateAsync(detpasien);
                    }
                }
                Users user = new Users();
                user.Username = obj.Username;
                user.Email    = obj.Email;
                await _userService.Updateuser(user);
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message} {ex.InnerException.Message}");
            }

            var data = await getpenggunausername(obj.Username);

            if (data != null)
            {
                try
                {
                    data.IdPasien   = obj.IdPasien;
                    data.Alamat     = obj.Alamat;
                    data.Nama       = obj.Nama;
                    data.Gender     = obj.Gender;
                    data.Umur       = obj.Umur;
                    data.Kota       = obj.Kota;
                    data.NoTelpon   = obj.NoTelpon;
                    data.NoHP       = obj.NoHP;
                    data.Email      = obj.Email;
                    data.rolename   = obj.rolename;
                    data.Prosentase = obj.Prosentase;
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} {ex.InnerException.Message}");
                }
            }
            else
            {
                throw new Exception("Data tidak ditemukan");
            }
        }