public async Task HandleAsync(ChangeActivityRecordOrder command) { var newActivityRecordOrder = new ActivityRecordOrder(command.NewOrder); await _activityRecordOrderChanger.ChangeOrderAsync(command.Id, newActivityRecordOrder); await _lifeLogContext.SaveChangesAsync(); }
internal TimeActivityRecord(Guid id, Activity activity, Guid dayRecordId, ActivityRecordOrder order, TimeValue value) : base(id, activity, dayRecordId, order) { if (activity.Type != ActivitiesTypes.TimeActivity) { throw new Exception($"Can not create {nameof(TimeActivityRecord)} for activity type other than {ActivitiesTypes.TimeActivity}."); } Value = value; }
internal ActivityRecord(Guid id, Activity activity, Guid dayRecordId, ActivityRecordOrder order) { Id = id; ActivityId = activity.Id; ActivityType = activity.Type; DayRecordId = dayRecordId; Order = order; var nowUtc = DateTime.UtcNow; CreatedAtUtc = nowUtc; UpdatedAtUtc = nowUtc; }
public async Task ChangeOrderAsync(Guid activityRecordId, ActivityRecordOrder newOrder) { var activityRecord = await _activityRecordsRepository.GetByIdAsync(activityRecordId); var oldOrder = activityRecord.Order; // VS bug? if (oldOrder == newOrder) { return; } var allDayRecordActivityRecords = await _activityRecordsRepository.BrowseAsync(new BrowseQuery(activityRecord.DayRecordId)); List <ActivityRecord> activityRecordsToChange = new List <ActivityRecord>(); if (newOrder < oldOrder) { activityRecordsToChange = allDayRecordActivityRecords.Where(dayRecord => dayRecord.Order >= newOrder && dayRecord.Order < oldOrder).ToList(); activityRecordsToChange.ForEach(activityRecord => activityRecord.SetNewOrder(activityRecord.Order.Greater())); } if (newOrder > oldOrder) { var maxOrder = allDayRecordActivityRecords.Max(activityRecord => activityRecord.Order); if (oldOrder == maxOrder) { return; } activityRecordsToChange = allDayRecordActivityRecords.Where(dayRecord => dayRecord.Order > oldOrder && dayRecord.Order <= newOrder).ToList(); activityRecordsToChange.ForEach(activityRecord => activityRecord.SetNewOrder(activityRecord.Order.Smaller())); } activityRecord.SetNewOrder(newOrder); }
internal void SetNewOrder(ActivityRecordOrder newOrder) { Order = newOrder; }
internal OccurrenceActivityRecord(Guid id, Activity activity, Guid dayRecordId, ActivityRecordOrder order) : base(id, activity, dayRecordId, order) { if (activity.Type != ActivitiesTypes.OccurrenceActivity) { throw new Exception($"Can not create {nameof(OccurrenceActivityRecord)} for activity type other than {ActivitiesTypes.OccurrenceActivity}."); } }