public void Handle(AppointmentScheduled @event) { if (@event.From != null && @event.To != null) { TimeSlot = new TimeSlot(@event.From.Value, @event.To.Value); } Id = @event.AppointmentId; JobId = @event.JobId; StaffMemberId = @event.StaffMemberId; Status = Status.Initiated; }
public void Execute(AppointmentScheduled @event) { Printer.Print("Updating JobView in effect of AppointmentScheduled event", ConsoleColor.Magenta); var staffRepository = new MyRepository <StaffMember>(); var staff = @event.StaffMemberId.HasValue ? staffRepository.Fetch(@event.StaffMemberId.Value) : null; var jobViewRepository = new MyRepository <JobView>(); var jobView = jobViewRepository.Fetch(@event.JobId); jobView.Appointments.Add(new AppointmentView { Id = @event.AppointmentId, AssignedTo = staff == null ? null : staff.Name, From = @event.From, To = @event.To }); jobViewRepository.Update(jobView); Publish(jobView); }