public ActionResult EditJobCharge(JobCharge jobCharge, int cid) { if (ModelState.IsValid) { try { db.Entry(jobCharge).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); if (jobCharge.Job.Invoices.Any(x => x.detail == "Charge Payment")) { var invoice = db.Invoices.FirstOrDefault(x => x.jobid == jobCharge.jobid && x.detail == "Charge Payment"); invoice.total = db.JobCharges.Where(x => x.jobid == jobCharge.jobid).Sum(x => x.amount); invoice.totalunpaid = db.JobCharges.Where(x => x.jobid == jobCharge.jobid).Sum(x => x.amount) - (invoice.total - invoice.totalunpaid); db.SaveChanges(); } return(RedirectToAction("detail/" + jobCharge.jobid)); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } else { return(View(jobCharge)); } }
void fillSubJobNos() { BindingList <JobCharge> filterList = new BindingList <JobCharge>(JobCharge.GetEntityList()); clbFilter.DataSource = filterList; clbFilter.DisplayMember = "SubJobNo_Desc"; clbFilter.ValueMember = "SubJobNo"; }
void fillJobCharges() { BindingList <JobCharge> filterList = new BindingList <JobCharge>(JobCharge.GetEntityList()); clbFilter.DataSource = filterList; clbFilter.DisplayMember = "Job_Code"; clbFilter.ValueMember = "Job_Code"; }
public ActionResult JobCharge([Bind(Prefix = "Item4")] JobCharge jobCharge, int cid) { if (ModelState.IsValid) { try { if (jobCharge.id == 0) { db.JobCharges.Add(jobCharge); } else { db.Entry(jobCharge).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); if (jobCharge.Job.Invoices.Any(x => x.detail == "Charge Payment")) { var invoice = db.Invoices.FirstOrDefault(x => x.jobid == jobCharge.jobid && x.detail == "Charge Payment"); invoice.total += jobCharge.amount; invoice.totalunpaid += jobCharge.amount; db.SaveChanges(); } return(RedirectToAction("detail/" + jobCharge.jobid)); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } else { return(RedirectToAction("Error500", "Home", new { errormsg = "There is an error processing your input/request!" })); } }