private static void MapSingleEvents(ModelBuilder modelBuilder)
        {
            var entity = modelBuilder.Entity <SingleEvent>();

            entity.HasKey(x => x.Id);
            entity.Property(x => x.Title).IsRequired();
            entity.Property(x => x.Start).IsRequired();
            entity.Property(x => x.Duration).HasConversion(d => d.ToJson(), d => EventDuration.FromJson(d))
            .IsRequired();
            entity.Property(x => x.MailAddresses)
            .HasConversion(ma => ListMapper.ToJson(ma), ma => ListMapper.FromJson(ma));
        }
Esempio n. 2
0
 public override CalendarEvent ToEntity()
 {
     return(new SingleEvent
     {
         Title = Title,
         Description = Description,
         Start = Start,
         Duration = TimeSpan.Parse(Duration) == TimeSpan.Zero
             ? EventDuration.FullDayDuration()
             : EventDuration.TimeSpanDuration(TimeSpan.Parse(Duration)),
         MailAddresses = MailAddresses
     });
 }
 public override CalendarEvent ToEntity()
 {
     return(new EventFromSeries
     {
         Title = Title,
         Description = Description,
         Start = Start,
         Duration = TimeSpan.Parse(Duration) == TimeSpan.Zero
             ? EventDuration.FullDayDuration()
             : EventDuration.TimeSpanDuration(TimeSpan.Parse(Duration)),
         MailAddresses = MailAddresses,
         OldStartDate = OldStartDate
     });
 }
        public override CalendarEvent ToEntity()
        {
            FinishClass finishClass = new NeverFinish();

            // TODO: HIGH : Yes, it's ugly :) I think I would:
            // 1) put it outside of the model - factory perhaps
            // 2) have the factory accept a mapping of enum -> class / use Di container to register mapping using reflection on app start (implementations would have some interface - we search for implementation with name matching enum)
            // 3) write good tests that cover this and implementation that don't match any enum - this way noone would add an implementation without adding an enum / remove implementation and leave enum / change names independently.
            // This looks very ugly and is against SOLID but can't think of anything better, there is way to assign logic to Enum value in Java, but can't think of anything better in C#
            switch (FinishEnum)
            {
            case FinishEnum.AfterDate:
                if (FinishDate != null)
                {
                    finishClass = FinishEnum.GetOccurenceClass(FinishDate.Value);
                }
                break;

            case FinishEnum.AfterOccurs:
                if (OccursAmount != null)
                {
                    finishClass = FinishEnum.GetOccurenceClass(OccursAmount.Value);
                }
                break;

            case FinishEnum.NeverFinish:
                finishClass = FinishEnum.GetOccurenceClass();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new EventSeries
            {
                Title = Title,
                Description = Description,
                Start = Start,
                Duration = TimeSpan.Parse(Duration) == TimeSpan.Zero
                    ? EventDuration.FullDayDuration()
                    : EventDuration.TimeSpanDuration(TimeSpan.Parse(Duration)),
                MailAddresses = MailAddresses,
                RepeatPeriod = RepeatPeriod,
                Finish = finishClass
            });
        }
        private static void MapEventSeries(ModelBuilder modelBuilder)
        {
            var entity = modelBuilder.Entity <EventSeries>();

            entity.HasKey(x => x.Id);
            entity.Property(x => x.Title).IsRequired();
            entity.Property(x => x.Start).IsRequired();
            entity.Property(x => x.Duration).HasConversion(d => d.ToJson(), d => EventDuration.FromJson(d))
            .IsRequired();
            entity.Property(x => x.RepeatPeriod).HasConversion(
                v => v.ToString(),
                v => (RepeatPeriod)Enum.Parse(typeof(RepeatPeriod), v)).IsRequired();
            entity.HasMany(x => x.EditedEvents).WithOne(x => x.EventSeries);
            entity.Property(x => x.Finish).HasConversion(v => v.ToJson(), v => FinishClass.FromJson(v)).IsRequired();
            entity.Property(x => x.MailAddresses)
            .HasConversion(ma => ListMapper.ToJson(ma), ma => ListMapper.FromJson(ma));
            entity.Property(x => x.DeletedOccurrences)
            .HasConversion(deleted => ListMapper.ToJsonDateTime(deleted),
                           deleted => ListMapper.FromJsonDateTime(deleted));
        }