| | | 1 | | using System.Globalization; |
| | | 2 | | using LifeChart.Domain.Medications; |
| | | 3 | | using Microsoft.EntityFrameworkCore; |
| | | 4 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 5 | | |
| | | 6 | | namespace LifeChart.Infrastructure.Persistence.Configurations; |
| | | 7 | | |
| | | 8 | | public class MedicationConfiguration : IEntityTypeConfiguration<Medication> |
| | | 9 | | { |
| | | 10 | | public void Configure(EntityTypeBuilder<Medication> builder) |
| | | 11 | | { |
| | 0 | 12 | | builder.HasKey(m => m.Id); |
| | | 13 | | |
| | 0 | 14 | | builder.Property(m => m.Name).IsRequired().HasMaxLength(200); |
| | 0 | 15 | | builder.Property(m => m.Dosage).IsRequired().HasMaxLength(100); |
| | | 16 | | |
| | 0 | 17 | | builder.OwnsMany(m => m.IntakeTimes, b => |
| | 0 | 18 | | { |
| | 0 | 19 | | b.WithOwner().HasForeignKey("MedicationId"); |
| | 0 | 20 | | b.Property<int>("Id").ValueGeneratedOnAdd(); |
| | 0 | 21 | | b.HasKey("Id"); |
| | 0 | 22 | | b.Property(i => i.Time) |
| | 0 | 23 | | .HasConversion( |
| | 0 | 24 | | v => v.ToString("HH:mm"), |
| | 0 | 25 | | v => TimeOnly.Parse(v, CultureInfo.CurrentCulture)); |
| | 0 | 26 | | b.Property(i => i.DoseCount); |
| | 0 | 27 | | }); |
| | 0 | 28 | | } |
| | | 29 | | } |