Esempio n. 1
0
 private void InsertRecords()
 {
     var operations = new List <Operation>
     {
         new Operation {
             OperationName = "Appendectomy",
             Doctor        = "Max Schmidt",
             Date          = DateTime.Now.AddDays(10),
             HospitalWard  = new HospitalWard
             {
                 Country = "Poland",
                 Region  = "Pomeranian Voivodeship",
             },
             MedicalProcedures = new List <MedicalProcedure>
             {
                 new MedicalProcedure {
                     MedicalProcedureName = "Treatment",
                     Price       = 40,
                     Description = "Simple medical procedure"
                 }
             }
         },
         new Operation {
             OperationName = "Lung surgery",
             Doctor        = "Johny",
             Date          = DateTime.Now.AddDays(10),
             HospitalWard  = new HospitalWard
             {
                 Country = "Poland",
                 Region  = "Masovian district",
             },
             MedicalProcedures = new List <MedicalProcedure>
             {
                 new MedicalProcedure {
                     MedicalProcedureName = "Operation",
                     Price       = 80,
                     Description = "Simple lungs operaion"
                 }
             }
         },
     }; hospitalContext.AddRange(operations); hospitalContext.SaveChanges();
 }
 public IActionResult Create(List <PatientServices> patientServices)
 {
     ViewBag.patient = new SelectList((from p in _db.Patients.ToList() select new {
         Id = p.Id,
         Name = p.Id + "-" + p.Title + " " + p.FirstName + " " + p.LastName
     }), "Id", "Name");
     ViewBag.Doctor = new SelectList((from emp in _db.Employee.Where(em => em.DesignationId == 1).ToList()
                                      select new
     {
         Id = emp.Id,
         Name = emp.Id + "-" + emp.Name
     }), "Id", "Name");
     ViewBag.service = new SelectList((from s in _db.Services.ToList()
                                       select new
     {
         Id = s.Id,
         Name = s.Id + "-" + s.Name
     }), "Id", "Name");
     if (!ModelState.IsValid)
     {
         ModelState.AddModelError("", "Invalid Model");
         var message = string.Join(" | ", ModelState.Values
                                   .SelectMany(v => v.Errors)
                                   .Select(e => e.ErrorMessage));
         return(View("Index", message));
     }
     if (patientServices.Count > 0)
     {
         _db.AddRange(patientServices);
         if (_db.SaveChanges() > 0)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View());
 }