/// <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()); }
public static MedicalTransaction MapToMedicalTransaction(this MedicalTransactionModel transaction) => new()