public async Task <IActionResult> Edit([FromRoute] Guid id, [FromBody] MedicalProtocolRequest request) { try { var medicalProtocol = await medicalProtocolService.EditAsync(id, request); return(Ok(medicalProtocol)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> Create([FromBody] MedicalProtocolRequest request) { try { await medicalProtocolService.CreateAsync(request); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task CreateAsync(MedicalProtocolRequest request) { MedicalProtocol medicalProtocol = new MedicalProtocol((Guid)request.DiseaseId, request.Title, request.Description, request.MaxTemp, request.MinTemp, request.MaxPulse, request.MinPulse, request.MaxBloodPressure, request.MinBloodPressure); var inBase = await applicationContext.MedicalProtocols.FirstOrDefaultAsync(x => x.Title == request.Title); if (inBase != null) { throw new Exception(localizer["MedicalProtocol already exists."]); } await applicationContext.MedicalProtocols.AddAsync(medicalProtocol); await applicationContext.SaveChangesAsync(); }
public async Task <MedicalProtocol> EditAsync(Guid id, MedicalProtocolRequest request) { MedicalProtocol newMedicalProtocol = new MedicalProtocol((Guid)request.DiseaseId, request.Title, request.Description, request.MaxTemp, request.MinTemp, request.MaxPulse, request.MinPulse, request.MaxBloodPressure, request.MinBloodPressure); MedicalProtocol medicalProtocol = await GetAsync(id); if (medicalProtocol == null) { throw new Exception(localizer["MedicalProtocol with this identifier doesn`t exist."]); } medicalProtocol = newMedicalProtocol; medicalProtocol.Id = id; applicationContext.MedicalProtocols.Update(medicalProtocol); await applicationContext.SaveChangesAsync(); return(await GetAsync(medicalProtocol.Id)); }