public Workout(string name, string shortName, WorkoutCategory category, Step[] steps) { Name = name; ShortName = string.IsNullOrEmpty(shortName) ? null : shortName; // empty shortName -> null CategoryName = category == null ? null : category.Name; Steps = steps; }
private void SaveWorkoutCategory() { var category = new WorkoutCategory(_view.CategoryName, _view.CategoryColor); _data.AddOrUpdateWorkoutCategory(category); _view.Close(); }
public EditWorkoutCategoryForm(WorkoutCategory category) : this() { // disabling the name field to avoid renaming of existing workouts txtName.Enabled = false; // assign control values according to the category to be edited txtName.Text = category.Name; comColorNames.Text = category.CategoryColor.ToKnownColor().ToString(); }
/// <summary> /// Removes a workout category from the data model. /// </summary> /// <param name="category">Category to remove.</param> public void RemoveWorkoutCategory(WorkoutCategory category) { if (!_categories.Contains(category)) { return; } _categories.Remove(category); // (no need to sort) Logger.Debug("Triggering CategoryChanged event"); CategoryChanged(this, new WorkoutCategoryChangedEventArgs(category, false)); }
/// <summary> /// Adds a new workout category to the data model. /// </summary> /// <param name="category">New workout category to add.</param> private void AddWorkoutCategory(WorkoutCategory category) { var index = _categories.FindIndex(c => string.Compare(c.Name, category.Name, StringComparison.InvariantCulture) > 0); _categories.Insert(index == -1 ? _categories.Count : index, category); Logger.Debug("Triggering CategoryChanged event"); CategoryChanged(this, new WorkoutCategoryChangedEventArgs(category, true)); }
/// <summary> /// Adds a new workout category if no category exists with the provided category's name or /// replaces the existing category with the same name. /// </summary> /// <param name="category">The new workout category to add or update.</param> public void AddOrUpdateWorkoutCategory(WorkoutCategory category) { // TODO: (add/edit/update) add proper updating of workout category var existing = _categories.FirstOrDefault(c => c.Name == category.Name); if (existing != null) { // NOTE: Removing category "under the hood" which means that the // WorkoutCategoryChanged-event is not triggered (which will be triggered afterwards) _categories.Remove(existing); } AddWorkoutCategory(category); }
public WorkoutCategoryChangedEventArgs(WorkoutCategory category, bool categoryAdded) { WorkoutCategory = category; CategoryAdded = categoryAdded; }