/
Extrap
/
Network_technologies_Project
Обзор
Документация
Войти
/
Extrap
/
Network_technologies_Project
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Project/Services/WorkoutValidationService.cs
63 строки
2 KB
Extrap
Решил трабл с отправкой тренировки
20 дек 2025, 18:48
20 дек 2025, 18:48
77f5498
Код
Авторство
О чём код?
using Project.Models; using Project.Models.DTOs; namespace Project.Services { public static class WorkoutValidationService { public static bool ValidateWorkout(WorkoutCreateDTO dto, out string errorMessage) { errorMessage = string.Empty; if (dto.StartTime > DateTime.UtcNow) { errorMessage = "Start time cannot be in the future"; return false; } if (dto.DurationSeconds <= 0) { errorMessage = "Duration must be greater than zero"; return false; } if (dto.Type == Workout.ActivityType.Running || dto.Type == Workout.ActivityType.Walking || dto.Type == Workout.ActivityType.Cycling || dto.Type == Workout.ActivityType.Swimming || dto.Type == Workout.ActivityType.Rowing || dto.Type == Workout.ActivityType.Skiing || dto.Type == Workout.ActivityType.Hiking || dto.Type == Workout.ActivityType.Climbing || dto.Type == Workout.ActivityType.Surfing || dto.Type == Workout.ActivityType.Snowboarding) { if (!dto.DistanceKm.HasValue || dto.DistanceKm <= 0) { errorMessage = "Distance must be provided and greater than zero for this activity type"; return false; } } if (dto.AvgHeartRate.HasValue && (dto.AvgHeartRate < 30 || dto.AvgHeartRate > 220)) { errorMessage = "Average heart rate must be between 30 and 220 bpm"; return false; } if (dto.MaxHeartRate.HasValue && (dto.MaxHeartRate < 30 || dto.MaxHeartRate > 250)) { errorMessage = "Maximum heart rate must be between 30 and 250 bpm"; return false; } if (dto.Calories.HasValue && dto.Calories < 0) { errorMessage = "Calories burned cannot be negative"; return false; } return true; } } }