Пример #1
0
        public ActionResult Client(int id)
        {
            List <SPinjamModel> SP = new List <SPinjamModel>();
            var mode = from SPinjam in context.SPinjams
                       where SPinjam.Id == id
                       select new SPinjamModel()
            {
                IdUser   = SPinjam.IdUser,
                Id       = SPinjam.Id,
                PBuku    = SPinjam.PBuku,
                WKembali = DateTime.Now,
                IdBuku   = (int)SPinjam.IdBuku,
                Status   = SPinjam.Status
            };

            SP = mode.ToList();

            int    Id = 0, IdUser = 0, IdBuku = 0;
            string PBuku = "", Stat = "";

            foreach (var s in SP)
            {
                Id     = s.Id;
                IdUser = s.IdUser;
                PBuku  = s.PBuku;
                IdBuku = s.IdBuku;
                Stat   = s.Status;
            }

            if (Stat == "Dibalikan")
            {
                return(RedirectToAction("Confirm"));
            }

            TBaca baca = new TBaca()
            {
                Buku    = PBuku,
                ReWaktu = DateTime.Now,
                IdUser  = IdUser
            };

            context.TBacas.InsertOnSubmit(baca);

            SPinjam buku = context.SPinjams.Where(some => some.Id == Id).Single <SPinjam>();

            buku.Status = "Dibalikan";

            /*int tmbh = 0;
             * var Add = from tambah in context.DBukus where tambah.Id == Id select tambah;
             * foreach (var tmb in Add)
             *  tmbh = tmb.Jumlah;*/

            DBuku book = context.DBukus.Where(some => some.Id == IdBuku).Single <DBuku>();

            book.Jumlah = book.Jumlah + 1;
            context.SubmitChanges();

            return(RedirectToAction("Confirm"));
        }
Пример #2
0
        public ActionResult Acc(int id)
        {
            List <PinjamModel> SP = new List <PinjamModel>();
            var mode = from Pinjam in context.Pinjams
                       join Biodata in context.Biodatas
                       on Pinjam.Id equals id
                       select new PinjamModel()
            {
                IdUser  = Pinjam.IdUser,
                Id      = Pinjam.Id,
                User    = Biodata.Username,
                PBuku   = Pinjam.PBuku,
                WPinjam = DateTime.Now,
                IdBuku  = (int)Pinjam.IdBuku
            };

            SP = mode.Distinct().ToList();

            int    Id = 0, IdUser = 0, IdBuku = 0;
            string PBuku = "";

            foreach (var s in SP)
            {
                Id     = s.Id;
                IdUser = s.IdUser;
                PBuku  = s.PBuku;
                IdBuku = s.IdBuku;
            }


            SPinjam spinjam = new SPinjam()
            {
                IdUser   = IdUser,
                PBuku    = PBuku,
                IdBuku   = IdBuku,
                Status   = "Dipinjam",
                WKembali = DateTime.Now.AddDays(7)
            };

            DBuku book = context.DBukus.Where(some => some.Id == IdBuku).Single <DBuku>();

            book.Jumlah = book.Jumlah - 1;

            context.SPinjams.InsertOnSubmit(spinjam);
            context.SubmitChanges();


            Pinjam buku = context.Pinjams.Where(some => some.Id == id).Single <Pinjam>();

            context.Pinjams.DeleteOnSubmit(buku);
            context.SubmitChanges();

            return(RedirectToAction("Confirm"));
        }
Пример #3
0
        public ActionResult Remove(int Id)
        {
            var    saring = from SPinjam in context.SPinjams where SPinjam.Id == Id select new { SPinjam.Status };
            string hasil  = "";

            foreach (var sa in saring)
            {
                hasil = sa.Status;
            }

            if (hasil == "Dipinjam")
            {
                return(RedirectToAction("Confirm"));
            }

            SPinjam Del = context.SPinjams.Where(some => some.Id == Id).Single <SPinjam>();

            context.SPinjams.DeleteOnSubmit(Del);
            context.SubmitChanges();
            return(RedirectToAction("Confirm"));
        }