public void UpdateTransaction(MedicalTransaction transaction)
 {
     MedicineId      = transaction.MedicineId;
     Dose            = transaction.Dose;
     TransactionDate = transaction.TransactionDate;
     UnitId          = transaction.UnitId;
 }
        /// <summary>
        /// Updates a medical transaction with the given values.
        /// </summary>
        /// <param name="item">The property values with which to update the medical transaction.</param>
        /// <param name="cancellationToken">A token that can be used to signal operation cancellation.</param>
        /// <returns>The updated medical transaction.</returns>
        public virtual async Task <MedicalTransaction> UpdateAsync(MedicalTransaction item, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Updating medical transaction with ID {item.Id}...");
            var medicalTransaction = await LivestockContext.MedicalTransactions
                                     .FindAsync(new object[] { item.Id }, cancellationToken)
                                     .ConfigureAwait(false);

            if (medicalTransaction == null)
            {
                throw new EntityNotFoundException <IMedicalTransaction>(item.Id);
            }

            medicalTransaction.UpdateTransaction(item);

            var changes = LivestockContext.Update(medicalTransaction);
            await LivestockContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(changes.Entity.MapToMedicalTransaction());
        }
        /// <summary>
        /// Attempts to add a medical transaction to the database context.
        /// </summary>
        /// <param name="item">The object that contains the information for the new medical transaction.</param>
        /// <param name="cancellationToken">A token that can be used to signal operation cancellation.</param>
        /// <returns>The added medical transaction.</returns>
        public virtual async Task <MedicalTransaction> AddAsync(MedicalTransaction item, CancellationToken cancellationToken)
        {
            Logger.LogInformation("Adding a medical transaction...");

            var entity = new MedicalTransactionModel
            {
                AnimalId        = item.AnimalId,
                Dose            = item.Dose,
                MedicineId      = item.MedicineId,
                TransactionDate = item.TransactionDate,
                UnitId          = item.UnitId
            };

            var changes = await LivestockContext.MedicalTransactions.AddAsync(entity, cancellationToken)
                          .ConfigureAwait(false);

            await LivestockContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(changes.Entity.MapToMedicalTransaction());
        }