workouttest_app/lib/model/exercise_plan.dart
2020-09-16 15:41:39 +02:00

58 lines
1.5 KiB
Dart

import 'package:intl/intl.dart';
class ExercisePlan {
int exercisePlanId;
int customerId;
String name;
String description;
bool private;
DateTime dateAdd;
DateTime dateUpd;
ExercisePlan(String name, int customerId) {
this.customerId = customerId;
this.name = name;
this.dateUpd = DateTime.now();
}
ExercisePlan.fromJson(Map json) {
this.exercisePlanId = json['exercisePlanId'];
this.customerId = json['customerId'];
this.name = json['name'];
this.private = json['private'];
this.description = json['description'];
this.dateAdd = json['dateAdd'] == null ? null : DateTime.parse( json['dateAdd'] );
this.dateUpd = json['dateUpd'] == null ? null : DateTime.parse( json['dateUpd'] );
}
Map<String, dynamic> toJson() {
String formattedDateAdd;
if ( dateAdd != null) {
formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd);
}
String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd);
print("DateAdd $formattedDateAdd");
if ( exercisePlanId == null ) {
return {
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
};
} else {
return {
"exercisePlanId": exercisePlanId,
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
};
}
}
}