public async Task <ActionResult <Illnesshistory> > PostIllnesshistory(Illnesshistory illnesshistory) { var visit = _visitsRepository.GetByID(illnesshistory.VisitId); if (visit == null) { return(NotFound(NotFoundEmptyJsonResult)); } if (!await _authorizationService.CanUserAccessVisit(visit.ReservationId, this)) { return(Unauthorized(UnauthorizedEmptyJsonResult)); } if ((await _repository.GetByVisitId(visit.ReservationId)).Contains(illnesshistory)) { return(Conflict(ConflictJsonResult("That illness history already exists"))); } illnesshistory.Id = Decimal.Zero; try { _repository.Insert(illnesshistory); _repository.Save(); } catch (DbUpdateException e) { return(StatusCode(500, InternalServerErrorJsonResult(e.Message))); } return(Created("", illnesshistory)); }
public async Task <IActionResult> PutIllnesshistory(decimal illnessHistoryId, Illnesshistory illnesshistory) { if (illnessHistoryId != illnesshistory.Id) { return(BadRequest(BadRequestEmptyJsonResult)); } if (!IllnesshistoryExists(illnesshistory.Id)) { return(NotFound(NotFoundEmptyJsonResult)); } if (!await _authorizationService.CanUserAccessIllnessHistory(illnessHistoryId, this)) { return(Unauthorized(UnauthorizedEmptyJsonResult)); } try { _repository.Update(illnesshistory); _repository.Save(); } catch (DbUpdateConcurrencyException e) { return(StatusCode(500, InternalServerErrorJsonResult(e.Message))); } return(Ok(OkEmptyJsonResult)); }