public ActionResult Save(Bill bill) { if (!ModelState.IsValid) { // Ako nije validan, vraćamo korisnika na formu. var viewModel = new BillFormViewModel() { Members = _context.Members.ToList(), Books = _context.Books.ToList() }; return(View("BillForm", viewModel)); } if (bill.ID == 0) { _context.Bills.Add(bill); } else { var billInDb = _context.Bills.Single(c => c.ID == bill.ID); billInDb.MemberID = bill.MemberID; billInDb.BookID = bill.BookID; billInDb.IssuingDate = bill.IssuingDate; billInDb.Total = bill.Total; } _context.SaveChanges(); return(RedirectToAction("Index", "Bills")); }
// GET: BILLs/Edit/5 public ActionResult Edit(decimal id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //Lay ra object thong qua id BILL bILL = db.BILLS.Find(id); if (bILL == null) { return(HttpNotFound()); } //// Cach 1: ////goi ra dropdown list voi gia tri duoc chon biLL.CUSTOMER_ID //ViewBag.CUSTOMER_ID = new SelectList(db.CUSTOMERS, "ID", "NAME", bILL.CUSTOMER_ID); //return View(bILL); // Cach 2: Thong Qua ViewModel var viewModel = new BillFormViewModel { BILL = bILL, CUSTOMERs = db.CUSTOMERS.ToList() }; return(View(viewModel)); }
public ActionResult SaveBill(BillFormViewModel billFormViewModel) { //if (!ModelState.IsValid) //{ // return HttpNotFound(); //} var patient = billFormViewModel.Patient; _context.Patients.Add(patient); _context.SaveChanges(); var patientId = patient.Id; var reports = new List <Report>(); billFormViewModel.Bill.Date = DateTime.Now; billFormViewModel.Bill.DoctorId = billFormViewModel.Report.DoctorId; billFormViewModel.Bill.PatientId = patientId; billFormViewModel.Bill.BillBy = ""; var bill = billFormViewModel.Bill; _context.Bills.Add(bill); _context.SaveChanges(); foreach (var report in billFormViewModel.Reports) { //if (!test.HasValue) //{ // continue; //} var Newreport = new Report { PatientId = patient.Id, Date = billFormViewModel.Report.Date, TestTitleId = report.TestTitleId, Price = report.Price, DateAdded = DateTime.Now, DoctorId = billFormViewModel.Report.DoctorId, ReportBy = "", InvestigatedBy = "", DigitalSignature = billFormViewModel.Report.DigitalSignature, ConsultingPathologistId = _context.Defaultvalues.Single(d => d.Id == 1).Id }; _context.Reports.Add(Newreport); reports.Add(Newreport); _context.SaveChanges(); } foreach (var report in reports) { var billitem = new Billitem { BillId = bill.Id, ReportId = report.Id }; _context.BillItems.Add(billitem); _context.SaveChanges(); } return(RedirectToAction("index", "Report")); }
public ActionResult SubmitBill(BillFormViewModel billViewModel) { if (billViewModel.Id.IsNotNull()) { return(UpdateBill(billViewModel)); } else { return(AddBill(billViewModel)); } }
public ActionResult New() { var books = _context.Books.ToList(); var members = _context.Members.ToList(); var viewModel = new BillFormViewModel { Bill = new Bill(), //Validacija - da bi se ID bio 0, jer je on skriveno (hidden) polje. Books = books, Members = members, }; return(View("BillForm", viewModel)); }
public ActionResult EditBill(int id) { var dbObj = Repository.GetById(id); var billViewModel = new BillFormViewModel { Id = dbObj.Id.ToString(), Description = dbObj.Description, Value = dbObj.Value.ToString() }; return(View("BillForm", billViewModel)); }
public ActionResult SaveNewPatientReport(NewPatientReportViewModel newPatientReportViewModel) { if (!ModelState.IsValid) { var patientReportViewModel = new NewPatientReportViewModel { Patient = newPatientReportViewModel.Patient }; return(View("NewPatientReportForm", patientReportViewModel)); } var patient = newPatientReportViewModel.Patient; _context.Patients.Add(patient); var reports = new List <Report>(); if (newPatientReportViewModel.TestTitleIds[0] == null) { return(HttpNotFound("Form Not Submitted Correctly")); } foreach (var testTitleId in newPatientReportViewModel.TestTitleIds) { if (!testTitleId.HasValue) { continue; } var testTitle = _context.TestTitles.Single(t => t.Id == testTitleId); var Report = new Report { PatientId = patient.Id, TestTitleId = testTitle.Id, Price = testTitle.Price, }; _context.Reports.Add(Report); reports.Add(Report); } var billFormViewModel = new BillFormViewModel { Reports = reports, Patient = patient, Report = newPatientReportViewModel.Report, Bill = new Bill { Discount = 0 }, }; return(View("BillForm", billFormViewModel)); }
private ActionResult AddBill(BillFormViewModel billViewModel) { var billObj = new Models.DataBase.Bills { User_Id = WebHelpers.GetSession().UserId, Description = billViewModel.Description, Value = billViewModel.Value.MoneyToDecimal(), Status = "A" }; Repository.Insert(billObj); return(Redirect("Bills")); }
public ActionResult Edit(int id) { var bill = _context.Bills.SingleOrDefault(c => c.ID == id); if (bill == null) { HttpNotFound(); } var viewModel = new BillFormViewModel { Books = _context.Books.ToList(), Members = _context.Members.ToList(), Bill = bill }; return(View("BillForm", viewModel)); }
[ValidateAntiForgeryToken] // ngan chan gia mao public ActionResult Create(BILL bill) { //Check value of a attribute if (!ModelState.IsValid) { var viewModel = new BillFormViewModel { BILL = bill, CUSTOMERs = db.CUSTOMERS.ToList() }; return(View(viewModel)); } if (bill.ID == 0 | bill.ID == null) { return(View("This bill is not created!")); } else { db.BILLS.Add(bill); } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult BillForm(BillFormViewModel billFormViewModel) { var bill = billFormViewModel; return(View(bill)); }