public ActionResult Create(int id) { var service = CreateTreatmentNoteService(); var appointment = service.GetAppointmentById(id); var model = new TreatmentNoteCreate { AppointmentId = appointment.AppointmentId, PatientId = appointment.PatientId, StartTime = DateTime.Now }; return(View(model)); }
public ActionResult Create(TreatmentNoteCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateTreatmentNoteService(); if (service.CreateTreatmentNote(model)) { var userId = Guid.Parse(User.Identity.GetUserId()); var aptservice = new AppointmentService(userId); AppointmentDetail appointment = aptservice.GetAppointmentById(model.AppointmentId); TempData["SaveResult"] = "Your note was saved."; return(RedirectToAction("Index", "TreatmentNote", new { id = appointment.PatientId })); } ModelState.AddModelError("", "Note could not be created."); return(View(model)); }
public bool CreateTreatmentNote(TreatmentNoteCreate model) { using (var ctx = new ApplicationDbContext()) { Appointment appointment = GetAppointmentById(model.AppointmentId); //Appointment appointment = ctx.Appointments.Single(e => e.AppointmentId == model.AppointmentId); var entity = new TreatmentNote() { AuthorId = _userId, StartTime = model.StartTime, EndTime = model.EndTime, Content = model.Content, AppointmentId = model.AppointmentId, Created = DateTimeOffset.Now, PatientId = appointment.PatientId }; ctx.TreatmentNotes.Add(entity); return(ctx.SaveChanges() == 1); } }