/// <summary> /// Removes a penalty sets on a croissant. /// </summary> /// <param name="date">Date to remove the penalty from.</param> public void RemovePenalty(DateTime date) { // Remove the penalties for this date var croissantsToUpdate = (from Croissant c in Croissants where c.Date.HasValue && c.Date.Value == date select c).ToList(); foreach (var croissant in croissantsToUpdate) { croissant.Date = null; } // Sort the list of croissant to put the gaps to the right of the collection Croissants.BubbleSort(SortDirection.Ascending); // Update the list of penalties for this instance: simply remove the penalties at this date var penaltiesToRemove = (from p in PenaltiesAdded where p == date select p).ToList(); foreach (var penalty in penaltiesToRemove) { PenaltiesAdded.Remove(penalty); } // TODO: Eventually, improve the removal of a penalty. // Right now, it is very simple: delete all penalties at this date. But it can have // consequences, especially it we remove a penalty on friday: 2 croissants are removed, // or 3 if the person didn't submit their CRA the whole week. // Plus, if we remove a penalty in the week and the person already has a penalty on friday // and didn't submit their CRA the rest of the week, the added "foutage de gueule" croissant // needs to be remove. }
/// <summary> /// Adds a penalty to the line for the given date. /// </summary> /// <param name="date">Date to set the penalty on.</param> public void AddPenalty(DateTime date) { // Check that there is no existing penalty for the given date. // If that's the case, a penalty is added. Otherwise, the PenaltyAlreadyExistsAtThisDate event is raised. if (!Croissants.Any(c => c.Date.HasValue && c.Date.Value == date)) { // Reordering the list of penalties in an ObservableCollection means new instanciation => add the new date at the correct index instead. int penaltiesToAdd = PenaltiesToAdd(date); for (int i = 0; i < penaltiesToAdd; i++) { ProcessPenaltyAdding(date); } // A penalty was added for this instance // -> very simple processing... PenaltiesAdded.Add(date); } else { if (PenaltyAlreadyExistsAtThisDate != null) { PenaltyAlreadyExistsAtThisDate(this, EventArgs.Empty); } } }