/// <summary> /// Gets the guide by identifier in asynchronous mode. /// Includes drug instruction and doctor's notes. /// </summary> /// <param name="id">The prescription identifier.</param> /// <returns> /// Drug instruction and doctor's notes. /// </returns> /// <exception cref="ArgumentException"> /// No prescription with such id. /// </exception> public async Task <PrescriptionGuide> GetGuideById(int id) { // Return IQueryable<Prescription> with one entity var prescriptions = await this.unitOfWork.Prescriptions.GetAllAsync(p => p.Id == id && p.IsDeleted == false); if (prescriptions.Count() == 0) { throw new ArgumentException(PRESCRIPTION_IS_NOT_FOUND); } // Return IQueryable<Drug> with one entity var drugs = await this.unitOfWork.Drugs.GetAllAsync(d => d.Id == prescriptions.First().DrugId); // Return IQueryable<PrescriptionGuide> with one entity var guide = prescriptions.Join( drugs, p => p.DrugId, d => d.Id, (p, d) => new PrescriptionGuide { Notes = p.Notes, Instruction = d.Instruction }); PrescriptionGuide result = guide.FirstOrDefault(); return(result); }
public async Task <IActionResult> GetPrescriptionGuideById(int id) { try { PrescriptionGuide result = await this.service.GetGuideById(id); return(this.Ok(result)); } catch (ArgumentException ex) { return(this.NotFound(ex.Message)); } }