Ejemplo n.º 1
0
        public async Task <IActionResult> AddUserToRole([FromBody] User user)
        {
            try
            {
                await _userRoleService.AddUserToRoleAsync(user.Username, user.rolename);

                return(Ok("User yang telah di masukan ke role ini Berhasil"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        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 != "Pasien")
                {
                    if (getdatapengguna.IdPasien != null)
                    {
                        obj.IdPasien = null;
                    }
                    var detailpasien = await _detailPasien.getusername(obj.Username);

                    if (detailpasien != null)
                    {
                        await _detailPasien.DeleteByuser(obj.Username);
                    }

                    DetailPegawai pegawai = new DetailPegawai();

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

                    if (pegawaii == null)

                    {
                        pegawai.Username    = obj.Username;
                        pegawai.Jabatan     = obj.rolename;
                        pegawai.TanggalJoin = DateTime.Today;
                        await _detailPegawai.CreateAsync(pegawai);
                    }
                    // create data pegawai
                }
                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);
                    }
                }
                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 getusername(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;

                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} {ex.InnerException.Message}");
                }
            }
            else
            {
                throw new Exception("Data tidak ditemukan");
            }
        }
Ejemplo n.º 3
0
        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");
            }
        }