コード例 #1
0
        /*
         * 1. Function update merupakan entity framework yang berfungsi untuk melakukan update data tanpa melakukan proses query
         * 2. int input merupakan parameter yang digunakan untuk merubah data sesuai dengan nilai yang dimiliki oleh parameter.
         * 3. karena non void, maka parameter inpu akan di return nilainya.
         */
        public int update(int input)
        {
            Program panggilvoid = new Program();

            Console.Write("Inputkan Username      : "******"Inputkan Password      : "******"Inputkan First Name    : "); string first_name = Console.ReadLine();
            Console.Write("Inputkan Last Name     : "); string last_name  = Console.ReadLine();
            Console.Write("Inputkan Email         : "); string email      = Console.ReadLine();
            Console.Write("Inputkan Address       : "); string address    = Console.ReadLine();
            Console.Write("Inputkan Phone         : "); string phone      = Console.ReadLine();
            Console.Write("Inputkan Status        : "); string status     = Console.ReadLine();
            Console.Write("Inputkan Pocket        : "); int    pocket     = Convert.ToInt32(Console.ReadLine());
            Console.Write("Inputkan Role          : "); string role       = Console.ReadLine();

            news_user call = GetById(input);

            call.username   = username;
            call.password   = password;
            call.first_name = first_name;
            call.last_name  = last_name;
            call.email      = email;
            call.address    = address;
            call.phone      = phone;
            call.status     = status;
            call.pocket     = pocket;
            call.role       = role;

            _context.Entry(call).State = System.Data.Entity.EntityState.Modified;
            _context.SaveChanges();
            return(input);
        }
コード例 #2
0
        /*
         * 1. Function GetById digunakan untuk cek id table yang diinputkan. apabila id sesuai dengan databse makan akan di simpan
         * kedalam objek call.
         * 2. nilai parameter input yang telak dimasukkan kedalam objek call akan dikembalikan nilainya (return value)
         */
        public news_user GetById(int input)
        {
            news_user call = _context.news_user.Find(input);

            if (call == null)
            {
                Console.Write("Id " + input + " Tidak Ada");
                Console.Read();
            }
            return(call);
        }
コード例 #3
0
        /*
         * 1. Function Insert digunakan untuk menambahkan data category.
         * 2. try dan catch digunakan untuk mengatasi error runtime yang bukan karena kesalahan penulisan code.
         * 3. function void, sehingga tidak return value.
         */
        public void insert()
        {
            Console.Write("Inputkan ID            : "); int    id         = Convert.ToInt32(Console.ReadLine());
            Console.Write("Inputkan Username      : "******"Inputkan Password      : "******"Inputkan First Name    : "); string first_name = Console.ReadLine();
            Console.Write("Inputkan Last Name     : "); string last_name  = Console.ReadLine();
            Console.Write("Inputkan Email         : "); string email      = Console.ReadLine();
            Console.Write("Inputkan Address       : "); string address    = Console.ReadLine();
            Console.Write("Inputkan Phone         : "); string phone      = Console.ReadLine();
            Console.Write("Inputkan Status        : "); string status     = Console.ReadLine();
            Console.Write("Inputkan Pocket        : "); int    pocket     = Convert.ToInt32(Console.ReadLine());
            Console.Write("Inputkan Role          : "); string role       = Console.ReadLine();

            news_user call = new news_user()
            {
                id         = id,
                username   = username,
                password   = password,
                first_name = first_name,
                last_name  = last_name,
                email      = email,
                address    = address,
                phone      = phone,
                status     = status,
                pocket     = pocket,
                role       = role
            };

            try
            {
                _context.news_user.Add(call);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.Write(ex.InnerException);
                Console.Write(ex.Message);
                Console.Write(ex.StackTrace);
            }
        }