workouttest_app/lib/repository/exercise_repository.dart
2020-08-17 12:38:47 +02:00

88 lines
2.0 KiB
Dart

import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:aitrainer_app/service/exercise_service.dart';
class ExerciseRepository {
Exercise exercise;
Customer customer;
ExerciseType exerciseType;
double rmWendler = 0;
double rmMcglothlin = 0;
double rmLombardi = 0;
double rmMayhew = 0;
double rmOconner = 0;
double rmWathen = 0;
createNew() {
this.exercise = Exercise();
exercise.dateAdd = DateTime.now();
}
setQuantity(double quantity) {
if ( this.exercise == null ) {
this.createNew();
}
this.exercise.quantity = quantity;
}
setUnitQuantity(double unitQuantity) {
if ( this.exercise == null ) {
this.createNew();
}
this.exercise.unitQuantity = unitQuantity;
}
setUnit( String unit) {
if ( this.exercise == null ) {
this.createNew();
}
this.exercise.unit = unit;
}
setDatetimeExercise(DateTime datetimeExercise) {
if ( this.exercise == null ) {
this.createNew();
}
this.exercise.dateAdd = datetimeExercise;
}
double get unitQuantity {
return this.exercise.unitQuantity;
}
double get quantity {
return this.exercise.quantity;
}
Exercise getExercise() {
return this.exercise;
}
Future<void> addExercise() async {
final Exercise modelExercise = this.exercise;
modelExercise.customerId = this.customer.customerId;
modelExercise.exerciseTypeId = this.exerciseType.exerciseTypeId;
await ExerciseApi().addExercise(modelExercise);
}
setCustomer(Customer customer) {
this.customer = customer;
}
setExerciseType( ExerciseType exerciseType) {
this.exerciseType = exerciseType;
}
/*
Future<List<ExerciseRepository>> getExercisesByCustomer( int customerId ) async {
final results = await ExerciseApi().getExercisesByCustomer(customerId);
this.exerciseList = results.map((item) => ExerciseRepository(exercise: item)).toList();
return this.exerciseList;
} */
}