Ejemplo n.º 1
0
 public ActionResult CreateEdit(BukuViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (BukuDataAccess.Update(model))
             {
                 return(Json(new { success = true, message = "Success" },
                             JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { success = false, message = BukuDataAccess.Message },
                             JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(Json(new { success = false, message = "Please fill required fiels!" },
                         JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 2
0
        public static BukuViewModel GetById(int id)
        {
            BukuViewModel result = new BukuViewModel();

            using (var db = new PerpusContext())
            {
                result = (from bk in db.Buku
                          join pnt in db.Penerbit
                          on bk.KodePenerbit equals pnt.KodePenerbit
                          where bk.Id == id
                          select new BukuViewModel
                {
                    Id = bk.Id,
                    KodeBuku = bk.KodeBuku,
                    Kategori = bk.Kategori,
                    KodePenerbit = bk.KodePenerbit,
                    JudulBuku = bk.JudulBuku,
                    jumlahBuku = bk.jumlahBuku,
                    Pengarang = bk.Pengarang,
                    TahunTerbit = bk.TahunTerbit
                                  //CreatedBy = bk.CreatedBy,
                                  //Created = bk.Created,
                                  //ModifiedBy = bk.ModifiedBy,
                                  //Modified = bk.Modified
                }).FirstOrDefault();
                //result = db.MST_Department.Where(o => o.Id == id).FirstOrDefault();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index()
        {
            BukuViewModel bukuViewModel = new BukuViewModel();

            await Load(bukuViewModel);

            return(View(bukuViewModel));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> InsertData(BukuViewModel bukuViewModel)
        {
            WebService ws = new WebService();

            TempData["message"] = await ws.PostLilu(AppSettings.BaseUrlApi + "/UserManagement/InsertData", JsonSerializer.Serialize(bukuViewModel));

            TempData["message"] = JsonSerializer.Deserialize <string>((string)TempData["message"]);

            return(View("Index", bukuViewModel));
        }
Ejemplo n.º 5
0
        public static bool Update(BukuViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new PerpusContext())
                {
                    if (model.Id == 0)
                    {
                        Buku buku = new Buku();
                        buku.KodeBuku     = model.KodeBuku;
                        buku.Kategori     = model.Kategori;
                        buku.KodePenerbit = model.KodePenerbit;
                        buku.JudulBuku    = model.JudulBuku;
                        buku.jumlahBuku   = model.jumlahBuku;
                        buku.Pengarang    = model.Pengarang;
                        buku.TahunTerbit  = model.TahunTerbit;
                        //buku.CreatedBy = model.CreatedBy;
                        //buku.Created = model.Created;
                        //buku.ModifiedBy = model.ModifiedBy;
                        //buku.Modified = model.Modified;
                        db.Buku.Add(buku);
                        db.SaveChanges();
                    }
                    else
                    {
                        Buku buku = db.Buku.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (buku != null)
                        {
                            buku.KodeBuku     = model.KodeBuku;
                            buku.Kategori     = model.Kategori;
                            buku.KodePenerbit = model.KodePenerbit;
                            buku.JudulBuku    = model.JudulBuku;
                            buku.jumlahBuku   = model.jumlahBuku;
                            buku.Pengarang    = model.Pengarang;
                            buku.TahunTerbit  = model.TahunTerbit;
                            //buku.CreatedBy = model.CreatedBy;
                            //buku.Created = model.Created;
                            //buku.ModifiedBy = model.ModifiedBy;
                            //buku.Modified = model.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> SearchUser(BukuViewModel bukuViewModel)
        {
            UserModel search = new UserModel();

            search.Nama = bukuViewModel.Keyword;

            WebService ws     = new WebService();
            string     result = await ws.PostLilu(AppSettings.BaseUrlApi + "/UserManagement/SearchUser", JsonSerializer.Serialize(search));

            List <UserModel> listUserModel = JsonSerializer.Deserialize <List <UserModel> >(result);

            bukuViewModel.ListUser = listUserModel;
            return(View("Index", bukuViewModel));
        }
Ejemplo n.º 7
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            buku = new Buku();

            buku.UpdateBuku();
            buku.DeleteBuku();


            BukuViewModel bukuViewModel = new BukuViewModel
            {
                AllBuku = buku.ReadAllBuku()
            };

            return(View(bukuViewModel));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> SearchBuku(BukuViewModel bukuViewModel)
        {
            SearchBukuModel search = new SearchBukuModel();

            search.Keyword = bukuViewModel.Keyword;

            WebService ws     = new WebService();
            string     result = await ws.PostLilu(AppSettings.BaseUrlApi + "/Pinjam/SearchBuku", JsonSerializer.Serialize(search));

            List <BukuModel> listBukuModel = JsonSerializer.Deserialize <List <BukuModel> >(result);

            bukuViewModel.ListBuku = listBukuModel;
            await Load(bukuViewModel);

            return(View("Index", bukuViewModel));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> InsertData(BukuViewModel bukuViewModel)
        {
            PinjamModel model = new PinjamModel();

            model.IdBuku         = bukuViewModel.Judul;
            model.IdUser         = bukuViewModel.User;
            model.TanggalPinjam  = bukuViewModel.TglPinjam;
            model.TanggalKembali = bukuViewModel.TglKembali;

            WebService ws = new WebService();

            TempData["message"] = await ws.PostLilu(AppSettings.BaseUrlApi + "/Pinjam/InsertData", JsonSerializer.Serialize(model));

            TempData["message"] = JsonSerializer.Deserialize <string>((string)TempData["message"]);
            await Load(bukuViewModel);

            return(View("Index", bukuViewModel));
        }
Ejemplo n.º 10
0
        private async Task Load(BukuViewModel bukuViewModel)
        {
            bukuViewModel.ListOptionUser.Add(new SelectListItem {
                Text = "Pilih User", Value = "0", Selected = true
            });
            bukuViewModel.ListOptionBuku.Add(new SelectListItem {
                Text = "Pilih Buku", Value = "0", Selected = true
            });

            WebService ws            = new WebService();
            string     resultOptUser = await ws.PostLilu(AppSettings.BaseUrlApi + "/Pinjam/GetOptionUser", "");

            List <CommonOptionModel> userOptionModel = JsonSerializer.Deserialize <List <CommonOptionModel> >(resultOptUser);

            for (int i = 0; i < userOptionModel.Count; i++)
            {
                bukuViewModel.ListOptionUser.Add(new SelectListItem {
                    Text = userOptionModel[i].NamaUser, Value = userOptionModel[i].IdUser
                });
            }

            WebService ws2           = new WebService();
            string     resultOptBuku = await ws2.PostLilu(AppSettings.BaseUrlApi + "/Pinjam/GetOptionBuku", "");

            List <CommonOptionModel> bukuOptionModel = JsonSerializer.Deserialize <List <CommonOptionModel> >(resultOptBuku);

            for (int i = 0; i < bukuOptionModel.Count; i++)
            {
                if (bukuOptionModel[i].Stock.Equals("Tidak Tersedia"))
                {
                    //do nothing
                }
                else
                {
                    bukuViewModel.ListOptionBuku.Add(new SelectListItem {
                        Text = bukuOptionModel[i].JudulBuku, Value = bukuOptionModel[i].IdBuku
                    });
                }
            }
        }
Ejemplo n.º 11
0
 public ActionResult Edit(BukuViewModel model)
 {
     return(CreateEdit(model));
 }