public async Task <IActionResult> Update([FromRoute] int id, [Required][FromBody] MedicalTransaction medicalTransaction)
        {
            Logger.LogInformation($"Requesting the updating of medical transaction with ID {id} with values {medicalTransaction}...");

            if (medicalTransaction == null)
            {
                ModelState.AddModelError(nameof(medicalTransaction), $"{nameof(medicalTransaction)} is required.");
                return(BadRequest(ModelState));
            }

            if (id != medicalTransaction.Id)
            {
                ModelState.AddModelError(nameof(medicalTransaction.Id), "The id in the transaction body does match the id in the route.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var updatedTransaction = await _medicalTransactionCrudService.UpdateAsync(medicalTransaction, RequestAbortToken)
                                         .ConfigureAwait(false);

                return(Ok(updatedTransaction));
            }
            catch (EntityNotFoundException <IMedicalTransaction> ex)
            {
                return(NotFound(ex.Message));
            }
        }
        public IActionResult PutMedicalTransaction([FromRoute] int id, [FromBody] MedicalTransaction medicalTransaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != medicalTransaction.ID)
            {
                return(BadRequest());
            }

            _medicalService.Update(medicalTransaction);

            try
            {
                _medicalService.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MedicalTransactionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IActionResult PostMedicalTransaction([FromBody] MedicalTransaction medicalTransaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _medicalService.Add(medicalTransaction);
            _medicalService.Save();

            return(CreatedAtAction("GetMedicalTransaction", new { id = medicalTransaction.ID, animalID = medicalTransaction.AnimalID }, medicalTransaction));
        }
        public async Task <IActionResult> AddAsync([FromBody] MedicalTransaction medicalTransaction)
        {
            Logger.LogInformation($"Requesting the creation of medical transaction {medicalTransaction}");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var addedTransaction = await _medicalTransactionCrudService.AddAsync(medicalTransaction, RequestAbortToken)
                                   .ConfigureAwait(false);

            return(CreatedAtAction(nameof(Get), new { id = addedTransaction.Id, animalId = addedTransaction.AnimalId }, addedTransaction));
        }
        public IActionResult PatchMedicalTransaction([FromRoute] int id, [FromBody] MedicalTransaction medicalTransaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != medicalTransaction.ID)
            {
                return(BadRequest());
            }

            MedicalTransaction updatedMedicalTransaction = null;

            try
            {
                updatedMedicalTransaction = _medicalService.Update(medicalTransaction);
                _medicalService.Save();
            }
            catch (EntityNotFoundException <MedicalTransaction> ex)
            {
                return(NotFound(ex.Message));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (updatedMedicalTransaction == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(updatedMedicalTransaction));
        }