public ActionResult DeleteConfirmed(int id) { tblVoucherDetail tblVoucherDetail = db.tblVoucherDetail.Find(id); db.tblVoucherDetail.Remove(tblVoucherDetail); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Detail_Id,Voucher_Id,Accounts_Id,Dr_Amount,Cr_Amount")] tblVoucherDetail tblVoucherDetail) { if (ModelState.IsValid) { db.Entry(tblVoucherDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Accounts_Id = new SelectList(db.tblAccountsHead, "Accounts_Id", "Accounts_Name", tblVoucherDetail.Accounts_Id); ViewBag.Voucher_Id = new SelectList(db.tblVoucherMaster, "Voucher_Id", "Voucher_No", tblVoucherDetail.Voucher_Id); return(View(tblVoucherDetail)); }
// GET: VoucherDetails/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblVoucherDetail tblVoucherDetail = db.tblVoucherDetail.Find(id); if (tblVoucherDetail == null) { return(HttpNotFound()); } return(View(tblVoucherDetail)); }
// GET: VoucherDetails/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblVoucherDetail tblVoucherDetail = db.tblVoucherDetail.Find(id); if (tblVoucherDetail == null) { return(HttpNotFound()); } ViewBag.Accounts_Id = new SelectList(db.tblAccountsHead, "Accounts_Id", "Accounts_Name", tblVoucherDetail.Accounts_Id); ViewBag.Voucher_Id = new SelectList(db.tblVoucherMaster, "Voucher_Id", "Voucher_No", tblVoucherDetail.Voucher_Id); return(View(tblVoucherDetail)); }
public ActionResult Create([Bind(Include = "Voucher_Id,Voucher_No,Voucher_Date,Supplier_Id")] tblVoucherMaster tblVoucherMaster, string[] DynamicTextBox) { if (ModelState.IsValid) { db.tblVoucherMaster.Add(tblVoucherMaster); //List<tblVoucherDetail> voucherDetailsList = new List<tblVoucherDetail>(); var rowCount = 0; var itemCount = DynamicTextBox.Count(); if (itemCount > 0) { rowCount = itemCount / 3; int j = 0; for (int i = 1; i <= rowCount; i++) { tblVoucherDetail voucherDetails = new tblVoucherDetail(); string account_name = DynamicTextBox[j]; int account_id = db.tblAccountsHead.Where(a => a.Accounts_Name == account_name).Select(a => a.Accounts_Id).FirstOrDefault(); voucherDetails.Accounts_Id = account_id; voucherDetails.Dr_Amount = Convert.ToDouble(DynamicTextBox[j + 1]); voucherDetails.Cr_Amount = Convert.ToDouble(DynamicTextBox[j + 2]); //voucherDetailsList.Add(voucherDetails); db.tblVoucherDetail.Add(voucherDetails); j = j + 3; } } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Supplier_Id = new SelectList(db.tblSupplier, "Supplier_Id", "Supplier_Name", tblVoucherMaster.Supplier_Id); return(View(tblVoucherMaster)); }
public ActionResult Edit([Bind(Include = "Voucher_Id,Voucher_No,Voucher_Date,Supplier_Id")] tblVoucherMaster tblVoucherMaster, string[] DynamicTextBox) { if (ModelState.IsValid) { db.Entry(tblVoucherMaster).State = EntityState.Modified; #region voucher detail table update var rowCount = 0; var itemCount = DynamicTextBox.Count(); if (itemCount > 0) { rowCount = itemCount / 4; int j = 0; List <int> totalItemFromUI = new List <int>(); for (int i = 0; i < itemCount; i = i + 4) { if (DynamicTextBox[i] != "0") { totalItemFromUI.Add(Convert.ToInt16(DynamicTextBox[i])); } } var totalItemInDetailForAVoucherId = db.tblVoucherDetail.Where(a => a.Voucher_Id == tblVoucherMaster.Voucher_Id).Select(a => a.Detail_Id).ToList(); var deletedIDs = totalItemInDetailForAVoucherId.Except(totalItemFromUI); if (deletedIDs != null) { foreach (var item in deletedIDs) { var details = db.tblVoucherDetail.Where(a => a.Detail_Id == item).SingleOrDefault(); db.tblVoucherDetail.Remove(details); } db.SaveChanges(); } for (int i = 1; i <= rowCount; i++) { tblVoucherDetail voucherDetails = new tblVoucherDetail(); int detailID = Convert.ToInt16(DynamicTextBox[j]); string account_name = DynamicTextBox[j + 1]; int account_id = db.tblAccountsHead.Where(a => a.Accounts_Name == account_name).Select(a => a.Accounts_Id).FirstOrDefault(); double dr_amount = Convert.ToDouble(DynamicTextBox[j + 2]); double cr_amount = Convert.ToDouble(DynamicTextBox[j + 3]); if (detailID != 0) { var details = db.tblVoucherDetail.Where(a => a.Detail_Id == detailID).SingleOrDefault(); details.Accounts_Id = account_id; details.Dr_Amount = dr_amount; details.Cr_Amount = cr_amount; } else { voucherDetails.Accounts_Id = account_id; voucherDetails.Dr_Amount = dr_amount; voucherDetails.Cr_Amount = cr_amount; voucherDetails.Voucher_Id = tblVoucherMaster.Voucher_Id; db.tblVoucherDetail.Add(voucherDetails); } j = j + 4; } } #endregion db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Supplier_Id = new SelectList(db.tblSupplier, "Supplier_Id", "Supplier_Name", tblVoucherMaster.Supplier_Id); return(View(tblVoucherMaster)); }