public async Task <ActionResult <Identitas> > PostIdentitas(Identitas identitas)
        {
            _context.Identitas.Add(identitas);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetIdentitas", new { id = identitas.Id }, identitas));
        }
        public async Task <IActionResult> PutIdentitas(long id, Identitas identitas)
        {
            if (id != identitas.Id)
            {
                return(BadRequest());
            }

            _context.Entry(identitas).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IdentitasExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        private void FillToListView(Identitas idt)
        {
            ListViewItem item = new ListViewItem(idt.Nomor_Identitas.Trim());

            item.SubItems.Add(idt.Jenis_Identitas);
            item.SubItems.Add(string.Format("{0:dd/MM/yyyy}", idt.Masa_Berlaku));

            lvwIdentitas.Items.Add(item);
        }
Esempio n. 4
0
        /*
         * public List<Identitas> getInfoIdentitas()
         * {
         *  List<Identitas> dftIdentitas = new List<Identitas>();
         *
         *  strSql = "SELECT * FROM identitas";
         *
         *  using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn))
         *  {
         *      using (NpgsqlDataReader dtr = cmd.ExecuteReader())
         *      {
         *          while (dtr.Read())
         *          {
         *              dftIdentitas.Add(MappingRowTOObject(dtr));
         *          }
         *      }
         *
         *      return dftIdentitas;
         *  }
         * }
         */

        //Extra Method
        private Identitas MappingRowTOObject(NpgsqlDataReader dtr)
        {
            Identitas idt = new Identitas();

            idt.Nomor_Identitas = dtr["nomor_identitas"] is DBNull ? string.Empty : dtr["nomor_identitas"].ToString();
            idt.Nik             = dtr["nik"] is DBNull ? string.Empty : dtr["nik"].ToString();
            idt.Jenis_Identitas = dtr["jenis_identitas"] is DBNull ? string.Empty : dtr["jenis_identitas"].ToString();
            idt.Masa_Berlaku    = dtr["masa_berlaku"] is DBNull ? DateTime.MinValue : DateTime.Parse(dtr["masa_berlaku"].ToString());

            return(idt);
        }
Esempio n. 5
0
        public int Update(Identitas idt)
        {
            strSql = "UPDATE identitas SET jenis_identitas = @1, masa_berlaku = @2 WHERE nomor_identitas = @3";

            using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn))
            {
                cmd.Parameters.AddWithValue("@1", idt.Jenis_Identitas);
                cmd.Parameters.AddWithValue("@2", idt.Masa_Berlaku);
                cmd.Parameters.AddWithValue("@3", idt.Nomor_Identitas);

                return(cmd.ExecuteNonQuery());
            }
        }
Esempio n. 6
0
        //CRUD Operation
        public int Save(Identitas idt)
        {
            strSql = "INSERT INTO identitas (nomor_identitas, jenis_identitas, masa_berlaku, nik) VALUES (@1, @2, @3, @4)";

            using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn))
            {
                cmd.Parameters.AddWithValue("@1", idt.Nomor_Identitas);
                cmd.Parameters.AddWithValue("@2", idt.Jenis_Identitas);
                cmd.Parameters.AddWithValue("@3", idt.Masa_Berlaku);
                cmd.Parameters.AddWithValue("@4", idt.Nik);

                return(cmd.ExecuteNonQuery());
            }
        }
Esempio n. 7
0
        public Identitas getInfoIdentitasByNoIdentitas(string nomor_identitas)
        {
            Identitas idt = null;

            strSql = "SELECT * FROM identitas WHERE nomor_identitas = @1";

            using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn))
            {
                cmd.Parameters.AddWithValue("@1", nomor_identitas);

                using (NpgsqlDataReader dtr = cmd.ExecuteReader())
                {
                    if (dtr.Read())
                    {
                        idt = MappingRowTOObject(dtr);
                    }
                }

                return(idt);
            }
        }
Esempio n. 8
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtJenisIdentitas.Text == "" || txtNoIdentitas.Text == "" || txtMasaBerlaku.Text == "")
                {
                    lblMsgStringM("Isi seluruh field yang disediakan !", Color.Yellow);
                }
                else
                {
                    Identitas idtC = idtDAO.getInfoIdentitasByNoIdentitas(txtNoIdentitas.Text); //Untuk mengecek record no identitas

                    Identitas idt = new Identitas();

                    idt.Nik             = txtNik.Text;
                    idt.Nomor_Identitas = txtNoIdentitas.Text.Trim();
                    idt.Jenis_Identitas = txtJenisIdentitas.Text.Trim();
                    idt.Masa_Berlaku    = DateTime.ParseExact(txtMasaBerlaku.Text.Trim(), "dd/MM/yyyy", null);

                    if (idtC == null)    //Record belum ada -> Simpan
                    {
                        //MessageBox.Show(txtNoIdentitas.Text + " ?");
                        //MessageBox.Show(txtNoIdentitas.Text.Trim() + " ?");
                        //MessageBox.Show(idt.Nomor_Identitas + " ?");

                        result = idtDAO.Save(idt);

                        if (result > 0) //Operasi Save berhasil
                        {
                            lblMsgStringM("Data berhasil disimpan.", Color.Green);

                            loadDataToListView();

                            //Change information views in main form
                            string[] data = new string[] { idt.Nomor_Identitas, idt.Jenis_Identitas, string.Format("{0:dd/MM/yyyy}", idt.Masa_Berlaku) };
                            refreshMainFormView(data, init);
                        }
                        else
                        {
                            lblMsgStringM("Data gagal disimpan !", Color.Yellow);
                        }
                    }
                    else    //Record sudah ada -> Ubah
                    {
                        //MessageBox.Show("Anda yakin akan mengubah Informasi Identitas dengan No. Identitas : " + txtNoIdentitas.Text + " ?");
                        result = idtDAO.Update(idt);

                        if (result > 0) //Operasi Update berhasil
                        {
                            lblMsgStringM("Data berhasil di-update.", Color.Green);

                            loadDataToListView();

                            //Change informations viewing in main form
                            string[] data = new string[] { idt.Nomor_Identitas, idt.Jenis_Identitas, string.Format("{0:dd/MM/yyyy}", idt.Masa_Berlaku) };
                            refreshMainFormView(data, init);
                        }
                        else    //Operasi Update gagal
                        {
                            lblMsgStringM("Data gagal di-update.", Color.Red);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorDBox(ex.Message, "btnSimpan_Click()");
            }
        }