public ActionResult Xoa_billdetail(int idBilldetail) { billdetail bi = data.billdetails.SingleOrDefault(n => n.id == idBilldetail); if (bi == null) { Response.StatusCode = 404; return(null); } data.billdetails.Remove(bi); data.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult generateb(int cardnumber) { if (Session["cartlist"] == null) { cartlist = new List <CartVM>(); } else { cartlist = (List <CartVM>)Session["cartlist"]; } bill b = new bill(); billdetail bd = new billdetail(); int tamount = 0; int tdiscount = 0; int tnetprice = 0; b.cardnumber = cardnumber; foreach (var cart in cartlist) { tamount = tamount + Convert.ToInt32(cart.price * cart.qty); tdiscount = tdiscount + Convert.ToInt32(cart.discount * cart.qty); b.storeid = Convert.ToInt32(Session["empsessionid"]); b.empid = Convert.ToInt32(Session["employeeid"]); b.dateofbill = DateTime.Now.ToString(); } b.totalamount = tamount; b.billamount = tamount - tdiscount; b.discount = tdiscount; db.bills.Add(b); db.SaveChanges(); bd.billid = b.billid; foreach (var cart in cartlist) { bd.productid = cart.productid; bd.quantity = cart.qty; bd.price = Convert.ToInt32(cart.price); bd.netprice = Convert.ToInt32(cart.netprice); bd.discount = Convert.ToInt32(cart.discount); bd.totalamount = Convert.ToInt32(cart.totalamount); db.billdetails.Add(bd); db.SaveChanges(); } return(View()); }