public void doStuff() { DataClasses1DataContext db = new DataClasses1DataContext(); //Bill_Item item = db.Bill_Items.Single(p => p.Title == "123") ?? null; //item.Description = "This was changed! Yay"; //item._Title = "No work"; db.SubmitChanges(); List<Bill_Item> billList = getAllBills(); }
public bool deleteBill(int billId , DataClasses1DataContext db) { //DataClasses1DataContext db = new DataClasses1DataContext(); var deleteB = getBillById(billId); db.Bill_Items.DeleteOnSubmit(deleteB); try { db.SubmitChanges(); }catch (Exception e) { Console.Write(e); return false; } return true; }
// // GET: /Bill/Delete/5 public ActionResult Delete(int id) { try { DataClasses1DataContext db = new DataClasses1DataContext(); Bill_Item bill = db.Bill_Items.Single(p => p.Id == id); db.Bill_Items.DeleteOnSubmit(bill); db.SubmitChanges(); return RedirectToAction("Index"); } catch (Exception e) { Console.Write(e.StackTrace); return View("Index"); //TODO: Return Error view } }
public bool addNewBill() { DataClasses1DataContext db = new DataClasses1DataContext(); db.Bill_Items.InsertOnSubmit(this); try { db.SubmitChanges(); } catch (Exception ex) { Console.Write(ex); } //BillModel //Bill_Item item = new Bill_Item(); return false; }
public ActionResult Edit(BillModel model) { try { DataClasses1DataContext db = new DataClasses1DataContext(); BudgetGuru.DataLayer.Bill_Item bill = new Bill_Item(); Bill_Item item = db.Bill_Items.Single(p => p.Id == model.billId); //Load by primary key. Ideal way to update using Linq-SQL //bill.Id = model.billId; item.Title = model.billTitle ?? string.Empty; item.Description = model.billDescription ?? string.Empty; item.DueDate = Convert.ToDateTime(model.datepicker); item.Amout = Convert.ToDecimal(model.billAmt); db.SubmitChanges(); //bill.updateBill(model.billId); return RedirectToAction("Index"); } catch (Exception e) { return View(); } }