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 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); }