public void Edit(jual obj) { var model = GetDataById(obj.id_jual); if (model != null) { model.username = obj.username; model.useradmin = obj.useradmin; model.id_barang = obj.id_barang; model.tgl_beli = obj.tgl_beli; model.qty = obj.qty; try { db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } } else { throw new Exception("Data tidak ditemukan !"); } }
public void AddToCart(jual jual) { //cek apakah cart dengan pengguna dan buku sama sudah ada var result = GetDatabyUser(jual.username, jual.id_barang); var stock = GetBarangById(jual.id_barang); stock.stok -= 1; if (result != null) { //update result.qty += 1; result.tgl_beli = DateTime.Now; } else { //tambah baru db.juals.Add(jual); } try { db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } }
public ActionResult AddToCart(int id) { //cek apakah user sudah login if (Session["username"] == null) { if (User.Identity.IsAuthenticated) { Session["username"] = User.Identity.Name; } else { Response.Redirect("~/Login.aspx"); } } var stock = GetBarangById(id); if (stock.stok == 0) { TempData["Pesan"] = Helpers.Message.GetPesan("Sold Out", "danger", "Item is out of stock"); return(RedirectToAction("Index", "Barang", new { area = "" })); } else { using (JualDAL scService = new JualDAL()) { var newShoppingCart = new jual { username = Session["username"].ToString(), useradmin = "Admin", qty = 1, id_barang = id, tgl_beli = DateTime.Now }; scService.AddToCart(newShoppingCart); } return(RedirectToAction("Index")); } }
public ActionResult Edit(jual jual) { using (JualDAL services = new JualDAL()) { try { services.Edit(jual); TempData["Pesan"] = Helpers.Message.GetPesan("Sukses !", "success", "Data Shopping Category " + jual.Barang.nama_barang + " berhasil diedit"); } catch (Exception ex) { TempData["Pesan"] = Helpers.Message.GetPesan("Error !", "danger", ex.Message); } } if (User.IsInRole("Admin")) { return(RedirectToAction("IndexAdmin")); } return(RedirectToAction("Index")); }