Esempio n. 1
0
        public async Task DeleteAsync(ActivityRecord activityRecord)
        {
            var allActivityRecordsInDayRecord = await _activityRecordsRepository.BrowseAsync(new BrowseQuery(activityRecord.DayRecordId));

            var allActivityRecordsWithGreaterOrder = allActivityRecordsInDayRecord.Where(activityRecordFromDayRecord => activityRecordFromDayRecord.Order > activityRecord.Order).ToList();

            allActivityRecordsWithGreaterOrder.ForEach(activityRecordWithGreaterOrder => activityRecordWithGreaterOrder.SetNewOrder(activityRecordWithGreaterOrder.Order.Smaller()));

            _activityRecordsRepository.Remove(activityRecord);
        }
        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);
        }