public ActionResult Edit(DBukuModel model, HttpPostedFileBase file) { string imageUrl = ""; if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/images/" + ImageName); file.SaveAs(physicalPath); imageUrl = ImageName; } try { DBuku buku = context.DBukus.Where(some => some.Id == model.Id).Single <DBuku>(); buku.Judul = model.Judul; buku.Penerbit = model.Penerbit; buku.LTerbit = model.LTerbit; buku.Pengarang = model.Pengarang; buku.Jumlah = model.Jumlah; buku.IdBuku = (int)model.IdBuku; buku.Images = imageUrl; buku.Id = model.Id; context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create() { List <AutenModel> aut = new List <AutenModel>(); var secret = from sec in context.Autens select new AutenModel { Username = sec.Username, AutSes = sec.AutSes }; aut = secret.ToList(); int k = aut.Count(); string a = ""; string b = ""; foreach (var open in aut) { a = open.Username; b = open.AutSes; } if (Session[a] == null) { return(RedirectToAction("SignIn")); } DBukuModel model = new DBukuModel(); PreparePublisher(model); return(View(model)); }
public ActionResult Pinjam(int id) { //int j = int.Parse(Session["User"].ToString()); DBukuModel mode = context.DBukus.Where(model => model.Id == id).Select(model => new DBukuModel() { Judul = model.Judul, Penerbit = model.Penerbit, LTerbit = model.LTerbit, Pengarang = model.Pengarang, Jumlah = model.Jumlah, IdBuku = (int)model.IdBuku, Images = model.Images, Id = model.Id, }).SingleOrDefault(); int ka = (int)Session["KTP"]; DateTime now = DateTime.Now; Pinjam p = new Pinjam() { WPinjam = DateTime.Today, IdUser = (int)Session["KTP"], PBuku = mode.Judul, IdBuku = mode.Id }; context.Pinjams.InsertOnSubmit(p); context.SubmitChanges(); return(RedirectToAction("DaftarBuku")); }
private void PreparePublisher(DBukuModel model) { model.Kelompoks = context.Kelompoks.AsQueryable <Kelompok>().Select(x => new SelectListItem() { Text = x.GBuku, Value = x.Id.ToString(), }); }
public ActionResult Delete(DBukuModel model) { try { DBuku buku = context.DBukus.Where(some => some.Id == model.Id).Single <DBuku>(); buku.Id = model.Id; context.DBukus.DeleteOnSubmit(buku); context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int?id) { List <AutenModel> aut = new List <AutenModel>(); var secret = from sec in context.Autens select new AutenModel { Username = sec.Username, AutSes = sec.AutSes }; aut = secret.ToList(); int k = aut.Count(); string a = ""; string b = ""; foreach (var open in aut) { a = open.Username; b = open.AutSes; } if (Session[a] == null) { return(RedirectToAction("SignIn")); } if (id == null) { return(HttpNotFound()); } DBukuModel mode = context.DBukus.Where(model => model.Id == id).Select(model => new DBukuModel() { Judul = model.Judul, Penerbit = model.Penerbit, LTerbit = model.LTerbit, Pengarang = model.Pengarang, Jumlah = model.Jumlah, IdBuku = (int)model.IdBuku, Images = model.Images, Id = model.Id }).SingleOrDefault(); PreparePublisher(mode); return(View(mode)); }
public ActionResult Create(DBukuModel model, HttpPostedFileBase file) { if (ModelState.IsValid) { return(RedirectToAction("Index")); } string imageUrl = ""; if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/images/" + ImageName); file.SaveAs(physicalPath); imageUrl = ImageName; } try { DBuku buku = new DBuku() { Judul = model.Judul, Penerbit = model.Penerbit, LTerbit = model.LTerbit, Pengarang = model.Pengarang, Jumlah = model.Jumlah, IdBuku = model.IdBuku, Images = imageUrl, Id = model.Id }; context.DBukus.InsertOnSubmit(buku); context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }