public async Task <ActionResult <TimeBillViewModel> > Put(int id, [FromBody] TimeBillViewModel model) { var oldBill = await _ctx.TimeBills .Where(b => b.Id == id) .FirstOrDefaultAsync(); if (oldBill == null) { return(BadRequest("Invalid ID")); } _mapper.Map(model, oldBill); var theCase = await _ctx.Cases .Where(c => c.Id == model.CaseId) .FirstOrDefaultAsync(); var theEmployee = await _ctx.Employees .Where(e => e.Id == model.EmployeeId) .FirstOrDefaultAsync(); if (theCase == null || theEmployee == null) { return(BadRequest("Could not find case or employee")); } oldBill.Case = theCase; oldBill.Employee = theEmployee; if (await _ctx.SaveChangesAsync() > 0) { return(Ok(_mapper.Map <TimeBillViewModel>(oldBill))); } return(BadRequest("Failed to save new timebill")); }
public async Task <ActionResult <TimeBillViewModel> > Post([FromBody] TimeBillViewModel model) { var bill = _mapper.Map <TimeBill>(model); var theCase = await _ctx.Cases .Where(c => c.Id == model.CaseId) .FirstOrDefaultAsync(); var theEmployee = await _ctx.Employees .Where(e => e.Id == model.EmployeeId) .FirstOrDefaultAsync(); if (theCase == null || theEmployee == null) { return(BadRequest("Could not find case or employee")); } bill.Case = theCase; bill.Employee = theEmployee; _ctx.Add(bill); if (await _ctx.SaveChangesAsync() > 0) { return(CreatedAtAction("Get", new { id = bill.Id }, _mapper.Map <TimeBillViewModel>(bill))); } return(BadRequest("Failed to save new timebill")); }
public ActionResult TimeBillDetails(DateTime begin, DateTime end) { List <Treatment> treatments = _billingManagementService.GetTreatmentsForTime(begin, end); List <Test> tests = _billingManagementService.GetTestsForTime(begin, end); List <Medication> medications = _billingManagementService.GetMedicationsForTime(begin, end); Dictionary <string, Tuple <double, int, double> > treatmentDict = new Dictionary <string, Tuple <double, int, double> >(); Dictionary <string, Tuple <double, int, double> > testDict = new Dictionary <string, Tuple <double, int, double> >(); Dictionary <string, Tuple <double, int, double> > medicationDict = new Dictionary <string, Tuple <double, int, double> >(); int count = 0; foreach (Treatment treatment in treatments) { if (!String.IsNullOrEmpty(treatment.TreatmentType)) { if (treatmentDict.ContainsKey(treatment.TreatmentType)) { count = treatmentDict[treatment.TreatmentType].Item2 + 1; Tuple <double, int, double> treatmentTuple = new Tuple <double, int, double>(treatment.Rate, count, treatment.Rate * count); treatmentDict[treatment.TreatmentType] = treatmentTuple; } else { Tuple <double, int, double> treatmentTuple = new Tuple <double, int, double>(treatment.Rate, 1, treatment.Rate); treatmentDict.Add(treatment.TreatmentType, treatmentTuple); } } } count = 0; foreach (Test test in tests) { if (!String.IsNullOrEmpty(test.Type)) { if (testDict.ContainsKey(test.Type)) { count = testDict[test.Type].Item2 + 1; Tuple <double, int, double> testTuple = new Tuple <double, int, double>(test.Rate, count, test.Rate * count); testDict[test.Type] = testTuple; } else { Tuple <double, int, double> testTuple = new Tuple <double, int, double>(test.Rate, 1, test.Rate); testDict.Add(test.Type, testTuple); } } } count = 0; foreach (Medication medication in medications) { if (!String.IsNullOrEmpty(medication.Name)) { if (medicationDict.ContainsKey(medication.Name)) { count = medicationDict[medication.Name].Item2 + 1; Tuple <double, int, double> medicationTuple = new Tuple <double, int, double>(medication.Rate, count, medication.Rate * count); medicationDict[medication.Name] = medicationTuple; } else { Tuple <double, int, double> medicationTuple = new Tuple <double, int, double>(medication.Rate, 1, medication.Rate); medicationDict.Add(medication.Name, medicationTuple); } } } // CALCULATE BILL AMOUNT int numVisits = _billingManagementService.GetNumberOfVisitationForTime(begin, end); double Amount = (numVisits * 100) + testDict.Sum(ix => ix.Value.Item3) + treatmentDict.Sum(ix => ix.Value.Item3) + medicationDict.Sum(ix => ix.Value.Item3); TimeBillViewModel timeBillViewModel = new TimeBillViewModel { NumberOfVisitations = numVisits, VisitationCost = 100 * numVisits, TestDict = testDict, TreatmentDict = treatmentDict, MedicationDict = medicationDict, BillAmount = Amount }; return(View(timeBillViewModel)); }