public async Task HandleScheduleUpdatedEvent(ScheduleUpdatedEvent e) { var schedule = await _repository.FindByUUID <Schedule>(e.ScheduleUuid).FirstOrDefaultAsync(); if (schedule == null) { return; } int page = 0, count = 10; do { var followingSchedules = await _repository.Schedules.Where(x => x.ParentId == schedule.Id) .OrderBy(x => x.Id) .Skip(page * count) .Take(count) .ToListAsync(); count = followingSchedules.Count; page++; foreach (var child in followingSchedules) { child.Update(schedule.Title, schedule.Description, schedule.IsPrivate, operatorId: schedule.UserId); } await _repository.UnitOfWork.SaveEntitiesAsync(); } while (count >= 10); }
public async Task HandleScheduleUpdatedEvent(ScheduleUpdatedEvent e) { var schedule = await _repository.FindByUUID <Schedule>(e.ScheduleUuid).FirstOrDefaultAsync(); if (schedule == null) { return; } var model = new FeedUpdateModel { ContentId = schedule.Id.ToString(), FeedTitle = schedule.Title, FeedContent = schedule.Description, FeedType = FeedType.ScheduleNew }; await _feedSvc.UpdateAsync(model); if (schedule.Stage == Stage.Completed) { model.FeedType = FeedType.ScheduleCompleted; await _feedSvc.UpdateAsync(model); } if (_scheduleSvc.ShouldClearCache(schedule.DateAdded) || _scheduleSvc.ShouldClearCache(schedule.DateEnd)) { await _cache.RemoveAsync(CacheKeyStore.HomeFeeds()); } }
public async Task <int> ScheduleDeleteAsync(ISchedule schedule) { // Record in local storage IDomainEvent <ISchedule> eventRaise; if (schedule.ScheduleKey != Guid.Empty) { _dbContext.Entry((Schedule)schedule).State = EntityState.Deleted; eventRaise = new ScheduleUpdatedEvent(schedule); } else { _dbContext.Schedule.Add((Schedule)schedule); eventRaise = new ScheduleCreatedEvent(schedule); } _recordsAffected = await _dbContext.SaveChangesAsync(); schedule.RaiseDomainEvent(eventRaise); return(_recordsAffected); }