/// <summary> /// Update the specified id and handoverDTO. /// </summary> /// <returns>The update.</returns> /// <param name="id">Identifier.</param> /// <param name="handoverDTO">Handover dto.</param> public bool Update(int id, HandoverDTO handoverDTO) { using (var dbContext = new AllocationContext(_dbContextOptions)) { Model.Handover handover = dbContext.Handovers .Include(h => h.HandoverIssues) .SingleOrDefault(h => h.HandoverID == id); if (handover == null) { return(false); } //Update all the attributes Model.Handover newHandover = HandoverDTOToModel(handoverDTO); handover.AdmissionUnit = newHandover.AdmissionUnit; handover.AdmissionDate = newHandover.AdmissionDate; handover.Alerts = newHandover.Alerts; handover.BedNumber = newHandover.BedNumber; handover.NurseName = newHandover.NurseName; handover.HandoverIssues = newHandover.HandoverIssues; handover.Isolation = newHandover.Isolation; handover.PatientName = newHandover.PatientName; handover.PatientId = newHandover.PatientId; handover.PastMedicalHistory = newHandover.PastMedicalHistory; handover.PresentingComplaint = newHandover.PresentingComplaint; handover.SignificantEvents = newHandover.SignificantEvents; handover.StudentName = newHandover.StudentName; handover.SwabSent = newHandover.SwabSent; handover.SwabSentDate = newHandover.SwabSentDate; // Update dbContext.Update(handover); dbContext.SaveChanges(); return(true); } }
/// <summary> /// Handovers the model to dto. /// </summary> /// <returns>The model to dto.</returns> /// <param name="handover">Handover.</param> private HandoverDTO HandoverModelToDTO(Model.Handover handover) { int numberOfIssues = handover.HandoverIssues.Count; HandoverIssueDTO[] handoverIssueDTOs = new HandoverIssueDTO[numberOfIssues]; int i = 0; foreach (HandoverIssue handoverIssue in handover.HandoverIssues) { handoverIssueDTOs[i] = new HandoverIssueDTO( handoverIssue.IssueNumber, handoverIssue.CurrentIssue, handoverIssue.Management, handoverIssue.FollowUp ); i++; } HandoverDTO handoverDTO = new HandoverDTO(handover.BedNumber, handover.AdmissionDate, handover.AdmissionUnit, handover.NurseName, handover.StudentName, handover.PatientId, handover.PatientName, handover.Alerts, handover.PresentingComplaint, handover.PastMedicalHistory, handover.SignificantEvents, handoverIssueDTOs, handover.Isolation, handover.SwabSent, handover.SwabSentDate); return(handoverDTO); }
public IActionResult Create([FromBody] HandoverDTO handover) { if (handover == null) { return(BadRequest(Json(new ErrorResponse("Form Error")))); } int handoverId; handoverId = _handoverProvider.Create(handover); /// 201 for successful create return(CreatedAtAction(handoverId.ToString(), new { id = handoverId })); }
public IActionResult Update(int id, [FromBody] HandoverDTO handover) { if (handover == null) { return(BadRequest(Json(new ErrorResponse("Form Error")))); } bool update_result = _handoverProvider.Update(id, handover); if (update_result == false) { return(NotFound()); } /// 204 for successful update return(NoContent()); }
/// <summary> /// Create the specified handoverDTO. /// </summary> /// <returns>The create.</returns> /// <param name="handoverDTO">Handover dto.</param> public int Create(HandoverDTO handoverDTO) { using (var dbContext = new AllocationContext(_dbContextOptions)) { // Create the handover Model object Model.Handover handover = HandoverDTOToModel(handoverDTO); // Store the object in database dbContext.Handovers.Add(handover); dbContext.SaveChanges(); // EF Core should magically populate this property after the commit return(handover.HandoverID); } }
public IActionResult Get(int id) { try { HandoverDTO handover = _handoverProvider.GetHandover(id); if (handover != null) { return(Json(new HandoverResponse(handover))); } } catch (Exception) { return(NotFound()); } return(NotFound()); }
/// <summary> /// Handovers the DTOT o model. /// </summary> /// <returns>The DTOT o model.</returns> /// <param name="handoverDTO">Handover dto.</param> private Model.Handover HandoverDTOToModel(HandoverDTO handoverDTO) { // retrieve the handover issues DTO from handover form List <HandoverIssue> handoverIssues = new List <HandoverIssue>(); // convert the DTO object into Model object for database storage foreach (HandoverIssueDTO handoverIssueDTO in handoverDTO.HandoverIssues) { HandoverIssue handoverIssue = new HandoverIssue() { IssueNumber = handoverIssueDTO.IssueNumber, CurrentIssue = handoverIssueDTO.CurrentIssue, Management = handoverIssueDTO.Management, FollowUp = handoverIssueDTO.FollowUp }; handoverIssues.Add(handoverIssue); } // Create the handover Model object Model.Handover handover = new Model.Handover() { PatientId = handoverDTO.PatientId, PatientName = handoverDTO.PatientName, Alerts = handoverDTO.Alerts, BedNumber = handoverDTO.BedNumber, AdmissionDate = handoverDTO.AdmissionDate, AdmissionUnit = handoverDTO.AdmissionUnit, NurseName = handoverDTO.NurseName, StudentName = handoverDTO.StudentName, PresentingComplaint = handoverDTO.PresentingComplaint, PastMedicalHistory = handoverDTO.PastMedicalHistory, SignificantEvents = handoverDTO.SignificantEvents, HandoverIssues = handoverIssues, Isolation = handoverDTO.Isolation, SwabSent = handoverDTO.SwabSent, SwabSentDate = handoverDTO.SwabSentDate }; return(handover); }
public HandoverResponse(HandoverDTO handover) : base(ResponseStatus.Success) => Handover = handover;