public ActionResult generateBill(FormCollection collection)
        {
            var        actions = collection.GetValues("Patient");
            List <int> selectedAppointments = new List <int>();

            foreach (string val in actions)
            {
                if (!(val.Contains("true") || val.Contains("false")))
                {
                    selectedAppointments.Add(Convert.ToInt32(val));
                }
            }
            Billing bill = new Billing();

            bill.comments = "";
            bill.billTime = DateTime.Now;
            dentistContext.billing.Add(bill);
            dentistContext.SaveChanges();

            int billID = dentistContext.billing.OrderByDescending(s => s.billingID).Select(x => x.billingID).FirstOrDefault();

            using (var db = new DentistContext())
            {
                foreach (int i in selectedAppointments)
                {
                    var result = db.Appointments.FirstOrDefault(b => b.appointmentID == i);
                    if (result != null)
                    {
                        result.billingID = billID;
                        db.SaveChanges();
                    }
                }
            }

            List <Invoice> invoice = dentistContext.Database.SqlQuery <Invoice>("Exec Billing @billingID = " + billID).ToList();

            foreach (Invoice inv in invoice)
            {
                List <PatientTreatment> patTreat = dentistContext.patientTreatment.Where(s => s.appointmentID == inv.appointmentID).ToList();

                List <String> treat = new List <String>();

                foreach (PatientTreatment pat in patTreat)
                {
                    treat.Add(dentistContext.treatment.Where(s => s.treatmentID == pat.treatmentID).Select(x => x.name).FirstOrDefault());
                }
                inv.treatments = treat;

                int dentID = dentistContext.Appointments.Where(s => s.appointmentID == inv.appointmentID).Select(x => x.dentistID).FirstOrDefault();
                inv.dentist = dentistContext.Dentists.Where(s => s.dentistID == dentID).Select(s => s.firstName).FirstOrDefault();
            }

            return(View(invoice));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                using (var db = new DentistContext())
                {
                    db.Database.CreateIfNotExists();
                    Patient patient = new Patient()
                    {
                        Name    = "Tomek",
                        Surname = "Walasek",
                        Diagram = new Diagram {
                            PozX = 0, PozY = 1, Color = 1
                        },
                        Visits = new List <Visit>
                        {
                            new Visit {
                                DateOfVisit = DateTime.Now, Description = "asfasf"
                            },
                            new Visit {
                                DateOfVisit = DateTime.Now.AddDays(1), Description = "asdasdas"
                            }
                        },
                        Pictures = new List <Picture>
                        {
                            new Picture {
                                PictureName = "Re3ndgen1.png"
                            },
                            new Picture {
                                PictureName = "Re3ndgen2.jpg"
                            }
                        }
                    };

                    db.Patients.Add(patient);
                    db.SaveChanges();
                }
                Console.WriteLine("Done...");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail... {0}\r\n{1}", ex.Message, ex.InnerException);
            }
            finally
            {
                Console.ReadKey();
            }
        }
        public ActionResult UpdateAppointment(string appID)
        {
            int appointmentID = Convert.ToInt32(appID);

            using (var db = new DentistContext())
            {
                var result = db.Appointments.FirstOrDefault(b => b.appointmentID == appointmentID);
                if (result != null)
                {
                    result.updateType = "2";
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("OpenAppointment", "Appointment"));
        }
 public DentistController()
 {
     dentistContext = new DentistContext();
 }
 public BillingController()
 {
     dentistContext = new DentistContext();
 }
 public AppointmentController()
 {
     dentistContext = new DentistContext();
 }
 public HomeController()
 {
     this.dentistContext = new DentistContext();
 }