public async Task <ActionResult> Create([Bind(Include = "trn_code,C_id,time")] buy_items buy_items) { var items = db.items.Where(x => x.C_id == buy_items.C_id).ToArray(); var total_price = db.transactions.Where(x => x.trn_code == buy_items.trn_code).FirstOrDefault(); double sum = (float)total_price.total_price; foreach (var item in items) { sum += item.price; } if (sum >= 500) { sum = sum * (1 - 1.25 * (float)total_price.customer.discount_code) / 100; } if (ModelState.IsValid) { total_price.total_price = (decimal)sum; db.Entry(total_price).State = EntityState.Modified; db.buy_items.Add(buy_items); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.C_id = new SelectList(db.items, "C_id", "C_id", buy_items.C_id); ViewBag.trn_code = new SelectList(db.transactions, "trn_code", "date", buy_items.trn_code); return(View(buy_items)); }
public async Task <ActionResult> DeleteConfirmed(int id) { buy_items buy_items = await db.buy_items.FindAsync(id); db.buy_items.Remove(buy_items); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "trn_code,C_id,time")] buy_items buy_items) { if (ModelState.IsValid) { db.Entry(buy_items).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.C_id = new SelectList(db.items, "C_id", "C_id", buy_items.C_id); ViewBag.trn_code = new SelectList(db.transactions, "trn_code", "date", buy_items.trn_code); return(View(buy_items)); }
// GET: buy_items/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } buy_items buy_items = await db.buy_items.FindAsync(id); if (buy_items == null) { return(HttpNotFound()); } return(View(buy_items)); }
// GET: buy_items/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } buy_items buy_items = await db.buy_items.FindAsync(id); if (buy_items == null) { return(HttpNotFound()); } ViewBag.C_id = new SelectList(db.items, "C_id", "C_id", buy_items.C_id); ViewBag.trn_code = new SelectList(db.transactions, "trn_code", "date", buy_items.trn_code); return(View(buy_items)); }