public static AnggotaViewModel GetById(int id) { AnggotaViewModel result = new AnggotaViewModel(); using (var db = new PerpusContext()) { result = (from ag in db.Anggota //join pdf in db.Pendaftaran //on ag.KodeAnggota equals pdf.KodeKartu where ag.Id == id select new AnggotaViewModel { Id = ag.Id, KodeAnggota = ag.KodeAnggota, Nama = ag.Nama, Alamat = ag.Alamat, Email = ag.Email, Telepon = ag.Telepon //CreatedBy = ag.CreatedBy, //Created = ag.Created, //ModifiedBy = ag.ModifiedBy, //Modified = ag.Modified }).FirstOrDefault(); } return(result); }
public static List <AnggotaViewModel> GetByPendaftaran(string kodeKartu) { List <AnggotaViewModel> result = new List <AnggotaViewModel>(); using (var db = new PerpusContext()) { result = (from ag in db.Anggota //join pdf in db.Pendaftaran //on ag.KodeAnggota equals pdf.KodeKartu select new AnggotaViewModel { Id = ag.Id, KodeAnggota = ag.KodeAnggota, Nama = ag.Nama, Alamat = ag.Alamat, Email = ag.Email, Telepon = ag.Telepon //CreatedBy = ag.CreatedBy, //Created = ag.Created, //ModifiedBy = ag.ModifiedBy, //Modified = ag.Modified }).ToList(); } return(result); }
public static List <BukuViewModel> GetByPenerbit(string kodePenerbit) { List <BukuViewModel> result = new List <BukuViewModel>(); using (var db = new PerpusContext()) { result = (from bk in db.Buku join pnt in db.Penerbit on bk.KodePenerbit equals pnt.KodePenerbit 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 }).ToList(); } return(result); }
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); }
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); }
public static bool Update(AnggotaViewModel model) { bool result = true; try { using (var db = new PerpusContext()) { if (model.Id == 0) { Anggota anggota = new Anggota { KodeAnggota = model.KodeAnggota, Nama = model.Nama, Alamat = model.Alamat, Email = model.Email, Telepon = model.Telepon //CreatedBy = model.CreatedBy, //Created = model.Created, //ModifiedBy = model.Modified, //Modified = model.Modified }; db.Anggota.Add(anggota); db.SaveChanges(); } else { Anggota anggota = db.Anggota.Where(o => o.Id == model.Id).FirstOrDefault(); if (anggota != null) { anggota.KodeAnggota = model.KodeAnggota; anggota.Nama = model.Nama; anggota.Alamat = model.Alamat; anggota.Email = model.Email; anggota.Telepon = model.Telepon; //anggota.CreatedBy = model.CreatedBy; //anggota.Created = model.Created; //anggota.ModifiedBy = model.ModifiedBy; //anggota.Modified = model.Modified; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public static bool Update(PemasokViewModel model) { bool result = true; try { using (var db = new PerpusContext()) { if (model.Id == 0) { Pemasok pms = new Pemasok(); pms.Id = model.Id; pms.KodePenerbit = model.KodePenerbit; pms.KodePemasok = model.KodePemasok; pms.NamaPemasok = model.NamaPemasok; pms.AlamatPemasok = model.AlamatPemasok; pms.Telepon = model.Telepon; pms.CreatedBy = "Admin"; pms.Created = DateTime.Now; db.Pemasok.Add(pms); db.SaveChanges(); } else { Pemasok pms = db.Pemasok.Where(o => o.Id == model.Id).FirstOrDefault(); if (pms != null) { pms.KodePenerbit = model.KodePenerbit; pms.KodePemasok = model.KodePemasok; pms.NamaPemasok = model.NamaPemasok; pms.AlamatPemasok = model.AlamatPemasok; pms.Telepon = model.Telepon; pms.ModifiedBy = "Admin"; pms.Modified = DateTime.Now; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public static bool Update(PetugasViewModel model) { bool result = true; try { using (var db = new PerpusContext()) { if (model.Id == 0) { Petugas petugas = new Petugas { KodePetugas = model.KodePetugas, Nama = model.Nama //CreatedBy = model.CreatedBy, //Created = model.Created, //ModifiedBy = model.Modified, //Modified = model.Modified }; db.Petugas.Add(petugas); db.SaveChanges(); } else { Petugas petugas = db.Petugas.Where(o => o.Id == model.Id).FirstOrDefault(); if (petugas != null) { petugas.KodePetugas = model.KodePetugas; petugas.Nama = model.Nama; //anggota.CreatedBy = model.CreatedBy; //anggota.Created = model.Created; //anggota.ModifiedBy = model.ModifiedBy; //anggota.Modified = model.Modified; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public static List <PenerbitViewModel> GetAll() { List <PenerbitViewModel> result = new List <PenerbitViewModel>(); using (var db = new PerpusContext()) { result = (from pnb in db.Penerbit select new PenerbitViewModel { Id = pnb.Id, KodePenerbit = pnb.KodePenerbit, NamaPenerbit = pnb.NamaPenerbit, AlamatPenerbit = pnb.AlamatPenerbit, Telepon = pnb.Telepon }).ToList(); } return(result); }
public static PenerbitViewModel GetById(int id) { PenerbitViewModel result = new PenerbitViewModel(); using (var db = new PerpusContext()) { result = (from pnb in db.Penerbit where pnb.Id == id select new PenerbitViewModel { Id = pnb.Id, KodePenerbit = pnb.KodePenerbit, NamaPenerbit = pnb.NamaPenerbit, AlamatPenerbit = pnb.AlamatPenerbit, Telepon = pnb.Telepon }).FirstOrDefault(); } return(result); }
public static List <PemasokViewModel> GetAll() { List <PemasokViewModel> result = new List <PemasokViewModel>(); using (var db = new PerpusContext()) { result = (from pms in db.Pemasok select new PemasokViewModel { Id = pms.Id, KodePenerbit = pms.KodePenerbit, KodePemasok = pms.KodePemasok, NamaPemasok = pms.NamaPemasok, AlamatPemasok = pms.AlamatPemasok, Telepon = pms.Telepon }).ToList(); } return(result); }
public static PemasokViewModel GetById(int id) { PemasokViewModel result = new PemasokViewModel(); using (var db = new PerpusContext()) { result = (from pms in db.Pemasok where pms.Id == id select new PemasokViewModel { Id = pms.Id, KodePenerbit = pms.KodePenerbit, KodePemasok = pms.KodePemasok, NamaPemasok = pms.NamaPemasok, AlamatPemasok = pms.AlamatPemasok, Telepon = pms.Telepon }).FirstOrDefault(); } return(result); }
public static List <PetugasViewModel> GetAll() { List <PetugasViewModel> result = new List <PetugasViewModel>(); using (var db = new PerpusContext()) { result = (from pts in db.Petugas select new PetugasViewModel { Id = pts.Id, KodePetugas = pts.KodePetugas, Nama = pts.Nama //CreatedBy = ag.CreatedBy, //Created = ag.Created, //ModifiedBy = ag.ModifiedBy, //Modified = ag.Modified }).ToList(); } return(result); }
public static PetugasViewModel GetById(int id) { PetugasViewModel result = new PetugasViewModel(); using (var db = new PerpusContext()) { result = (from pts in db.Petugas where pts.Id == id select new PetugasViewModel { Id = pts.Id, KodePetugas = pts.KodePetugas, Nama = pts.Nama //CreatedBy = ag.CreatedBy, //Created = ag.Created, //ModifiedBy = ag.ModifiedBy, //Modified = ag.Modified }).FirstOrDefault(); } return(result); }
public static bool Delete(int id) { bool result = true; try { using (var db = new PerpusContext()) { Penerbit pnb = db.Penerbit.Where(o => o.Id == id).FirstOrDefault(); if (pnb != null) { db.Penerbit.Remove(pnb); db.SaveChanges(); } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }