Beispiel #1
0
        public IEnumerable <PegawaiModel> ListData()
        {
            List <PegawaiModel> result = null;
            var sSql = @"
                SELECT
                    aa.PegawaiID, aa.PegawaiName
                FROM
                    Pegawai aa ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            result = new List <PegawaiModel>();
                            while (dr.Read())
                            {
                                var item = new PegawaiModel
                                {
                                    PegawaiID   = dr["PegawaiID"].ToString(),
                                    PegawaiName = dr["PegawaiName"].ToString()
                                };
                                result.Add(item);
                            }
                        }
                    }
                }
            return(result);
        }
Beispiel #2
0
        public PegawaiModel GetData(string id)
        {
            PegawaiModel result = null;
            var          sSql   = @"
                SELECT
                    aa.PegawaiName
                FROM
                    Pegawai aa
                WHERE
                    aa.PegawaiID = @PegawaiID ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@PegawaiID", id);
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            dr.Read();
                            result = new PegawaiModel
                            {
                                PegawaiID   = id,
                                PegawaiName = dr["PegawaiName"].ToString()
                            };
                        }
                    }
                }
            return(result);
        }
Beispiel #3
0
        public PihakKeduaModel Save(PegawaiModel pegawai)
        {
            PihakKeduaModel result = new PihakKeduaModel
            {
                PihakKeduaID   = pegawai.PegawaiID,
                PihakKeduaName = pegawai.PegawaiName
            };

            return(_Save(result));
        }
        public void Save()
        {
            var pegawai = new PegawaiModel
            {
                PegawaiID   = _view.PegawaiID,
                PegawaiName = _view.PegawaiName,
                Alamat      = _view.Alamat,
                NoTelp      = _view.NoTelp
            };

            var result = _pegawaiBL.Save(pegawai);
        }
Beispiel #5
0
        public void Insert(PegawaiModel model)
        {
            var sSql = @"
                INSERT INTO
                    Pegawai (
                        PegawaiID, PegawaiName)
                VALUES (
                        @PegawaiID, @PegawaiName) ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@PegawaiID", model.PegawaiID);
                    cmd.AddParam("@PegawaiName", model.PegawaiName);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Beispiel #6
0
        public void Update(PegawaiModel model)
        {
            var sSql = @"
                UPDATE
                    Pegawai 
                SET
                    PegawaiName = @PegawaiName
                WHERE
                    PegawaiID = @PegawaiID ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@PegawaiID", model.PegawaiID);
                    cmd.AddParam("@PegawaiName", model.PegawaiName);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Beispiel #7
0
        public PegawaiModel Save(PegawaiModel pegawai)
        {
            if (pegawai == null)
            {
                throw new ArgumentNullException(nameof(pegawai));
            }

            if (pegawai.PegawaiName.Trim() == "")
            {
                throw new ArgumentException("Pegawai Name kosong");
            }

            using (var trans = TransHelper.NewScope())
            {
                if (pegawai.PegawaiID.Trim() == "")
                {
                    pegawai.PegawaiID = GenNewID();
                }

                //  simapn (hapus >> simpan)
                _pegawaiDal.Delete(pegawai.PegawaiID);
                _pegawaiDal.Insert(pegawai);

                //  update pihak kedua
                _pihakKeduaDal.Delete(pegawai.PegawaiID);
                var pihakKedua = new PihakKeduaModel
                {
                    PihakKeduaID   = pegawai.PegawaiID,
                    PihakKeduaName = pegawai.PegawaiName
                };
                _pihakKeduaDal.Insert(pihakKedua);

                trans.Complete();
            }

            return(pegawai);
        }