示例#1
0
        static void Main(string[] args)
        {
            ClubBola clubbola;  //Abstract Class//

            clubbola = new Pemain();
            clubbola.Posisi();

            Console.WriteLine();
            clubbola = new Captain();
            clubbola.Posisi();

            Console.WriteLine();
            clubbola = new Pelatih();
            clubbola.Posisi();


            /*IClubBola clubbola; //Abstract Class//
             * clubbola = new Pemain();
             * clubbola.Posisi();
             * Console.WriteLine();
             * clubbola = new Captain();
             * clubbola.Posisi();
             * Console.WriteLine();
             * clubbola = new Pelatih();
             * clubbola.Posisi()*/

            Console.ReadKey();
        }
        public Pemain GetByNama(string nama)
        {
            Pemain obj = _context.Conn
                         .Query <Pemain>("SELECT * FROM pemain WHERE nama = @nama", new { nama = nama })
                         .FirstOrDefault();

            return(obj);
        }
        private Pemain GetPemain()
        {
            var pemain = new Pemain
            {
                nama       = txtNama.Text.Trim(),
                posisi_id  = (int)cmbPosisi.SelectedValue,
                negara     = txtNegara.Text.Trim(),
                keterangan = rtbKeterangan.Text.Trim()
            };

            return(pemain);
        }
示例#4
0
        public int Delete(Pemain obj)
        {
            int result = 0;

            using (IDbContext context = new DbContext())
            {
                _repository = new PemainRepository(context);
                result      = _repository.Delete(obj);
            }

            return(result);
        }
示例#5
0
        public Pemain GetByID(int id)
        {
            Pemain obj = null;

            using (IDbContext context = new DbContext())
            {
                _repository = new PemainRepository(context);
                obj         = _repository.GetByID(id);
            }

            return(obj);
        }
        public void Delete()
        {
            Pemain obj = new Pemain
            {
                id = 3
            };

            var result = _controller.Delete(obj);

            Console.WriteLine(result);

            Assert.IsNotNull(result);
            Assert.IsTrue(result > 0);
        }
        public int Update(Pemain obj)
        {
            var result = 0;

            try
            {
                result = _context.Conn.Update(obj) ? 1 : 0;
            }
            catch
            {
                return(result);
            }

            return(result);
        }
        public int Save(Pemain obj)
        {
            var result = 0;

            try
            {
                result = (int)_context.Conn.Insert(obj);
            }
            catch
            {
                return(result);
            }

            return(result);
        }
        public void Save()
        {
            Pemain obj = new Pemain
            {
                nama      = "Alex Iwobi",
                posisi_id = 6,
                negara    = "Jerman"
            };

            var result = _controller.Save(obj);

            Console.WriteLine(result);

            Assert.IsNotNull(result);
            Assert.IsTrue(result > 0);
        }
        public void Update()
        {
            Pemain obj = new Pemain
            {
                id        = 2,
                nama      = "Henrikh Mkhitaryan",
                posisi_id = 6,
                negara    = "Armenia"
            };

            var result = _controller.Update(obj);

            Console.WriteLine(result);

            Assert.IsNotNull(result);
            Assert.IsTrue(result > 0);
        }
示例#11
0
        private bool NamaIsUnique(string nama, int id = 0)
        {
            Pemain obj = null;

            using (IDbContext context = new DbContext())
            {
                _repository = new PemainRepository(context);
                obj         = _repository.GetByNama(nama);
            }

            if (obj == null || obj.id == id)
            {
                return(true); // unique
            }

            return(false);
        }
示例#12
0
        public int Update(Pemain obj)
        {
            if (!NamaIsUnique(obj.nama, obj.id))
            {
                return(-1);
            }

            int result = 0;

            using (IDbContext context = new DbContext())
            {
                _repository = new PemainRepository(context);
                result      = _repository.Update(obj);
            }

            return(result);
        }
        public Pemain GetByID(int id)
        {
            Pemain obj = _context.Conn.Get <Pemain>(id);

            return(obj);
        }