public async Task <ActionResult <Medicinehistory> > PostMedicinehistory(Medicinehistory medicinehistory)
        {
            if (MedicinehistoryExists(medicinehistory))
            {
                return(Conflict(ConflictJsonResult("Identical medicine history already exists")));
            }

            if (!await _authorizationService.CanUserAccessIllnessHistory(medicinehistory.IllnesshistoryId, this))
            {
                return(Unauthorized(UnauthorizedEmptyJsonResult));
            }

            try
            {
                _repository.Insert(medicinehistory);
                _repository.Save();
            }
            catch (DbUpdateException e)
            {
                return(StatusCode(500, InternalServerErrorJsonResult(e.Message)));
            }

            return(Created("", medicinehistory));
        }
 private bool MedicinehistoryExists(Medicinehistory medHist)
 {
     return(_repository.Exists(medHist.IllnesshistoryId, medHist.MedicineId, medHist.Startdate));
 }
        public async Task <IActionResult> PutMedicinehistory(decimal IllnessHistoryId, decimal MedicineId, DateTime startDate, Medicinehistory medicinehistory)
        {
            if (MedicineId != medicinehistory.MedicineId || IllnessHistoryId != medicinehistory.IllnesshistoryId || medicinehistory.Startdate != startDate)
            {
                return(BadRequest(BadRequestEmptyJsonResult));
            }

            if (!MedicinehistoryExists(medicinehistory))
            {
                return(NotFound(NotFoundEmptyJsonResult));
            }

            if (!await _authorizationService.CanUserAccessIllnessHistory(IllnessHistoryId, this))
            {
                return(Unauthorized(UnauthorizedEmptyJsonResult));
            }

            try
            {
                _repository.Update(medicinehistory);
                _repository.Save();
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(StatusCode(500, InternalServerErrorJsonResult(e.Message)));
            }

            return(Ok(OkEmptyJsonResult));
        }