144 lines
3.0 KiB
Dart
144 lines
3.0 KiB
Dart
import 'package:aitrainer_app/model/customer.dart';
|
|
import 'package:aitrainer_app/service/customer_service.dart';
|
|
|
|
class GenderItem {
|
|
GenderItem(this.dbValue,this.name);
|
|
final String dbValue;
|
|
String name;
|
|
}
|
|
|
|
class CustomerRepository {
|
|
Customer customer;
|
|
//List<CustomerRepository> customerList = List<CustomerRepository>();
|
|
bool visibleDetails = false;
|
|
List<GenderItem> genders;
|
|
|
|
CustomerRepository({this.customer}) {
|
|
customer = Customer();
|
|
genders = [
|
|
GenderItem("m", "Man"),
|
|
GenderItem("w", "Woman"),
|
|
];
|
|
}
|
|
|
|
String getGenderByName(String name) {
|
|
String dbValue;
|
|
genders.forEach((element) {
|
|
if (element.name == name) {
|
|
dbValue = element.dbValue;
|
|
}
|
|
});
|
|
return dbValue;
|
|
}
|
|
|
|
String getGenderByDBValue(String dbValue) {
|
|
String name;
|
|
genders.forEach((element) {
|
|
if (element.dbValue == dbValue) {
|
|
name = element.name;
|
|
}
|
|
});
|
|
return name;
|
|
}
|
|
|
|
String get name {
|
|
return this.customer.name != null ? this.customer.name : "";
|
|
}
|
|
|
|
String get firstName {
|
|
return this.customer.firstname != null ? this.customer.firstname : "";
|
|
}
|
|
|
|
String get sex {
|
|
return this.customer.sex == "m" ? "Man" : "Woman";
|
|
}
|
|
|
|
int get birthYear {
|
|
return this.customer.birthYear;
|
|
}
|
|
|
|
String get goal {
|
|
return this.customer.goal;
|
|
}
|
|
|
|
String get fitnessLevel {
|
|
return this.customer.fitnessLevel;
|
|
}
|
|
|
|
String get bodyType {
|
|
return this.customer.bodyType;
|
|
}
|
|
|
|
setName(String name) {
|
|
this.customer.name = name;
|
|
}
|
|
setFirstName(String firstName) {
|
|
this.customer.firstname = firstName;
|
|
}
|
|
|
|
setPassword( String password ) {
|
|
this.customer.password = password;
|
|
}
|
|
|
|
setEmail(String email) {
|
|
this.customer.email = email;
|
|
}
|
|
|
|
|
|
setSex(String sex) {
|
|
this.customer.sex = sex;
|
|
}
|
|
|
|
setWeight( int weight) {
|
|
this.customer.weight = weight;
|
|
}
|
|
|
|
setBirthYear( int birthYear ) {
|
|
this.customer.birthYear = birthYear;
|
|
}
|
|
|
|
setFitnessLevel( String level ) {
|
|
this.customer.fitnessLevel = level;
|
|
}
|
|
|
|
setGoal( String goal ) {
|
|
this.customer.goal = goal;
|
|
}
|
|
|
|
setBodyType(String bodyType) {
|
|
this.customer.bodyType = bodyType;
|
|
}
|
|
|
|
createNew() {
|
|
this.customer = Customer();
|
|
}
|
|
|
|
Customer getCustomer() {
|
|
return this.customer;
|
|
}
|
|
|
|
void setCustomer ( Customer customer ) {
|
|
this.customer = customer;
|
|
}
|
|
|
|
Future<void> addCustomer() async {
|
|
final Customer modelCustomer = customer;
|
|
await CustomerApi().addCustomer(modelCustomer);
|
|
}
|
|
|
|
Future<void> saveCustomer() async {
|
|
final Customer modelCustomer = customer;
|
|
await CustomerApi().saveCustomer(modelCustomer);
|
|
}
|
|
|
|
/* Future<List<CustomerRepository>> getCustomers() async {
|
|
final results = await CustomerApi().getRealCustomers("");
|
|
this.customerList = results.map((item) => CustomerRepository(customer: item)).toList();
|
|
return this.customerList;
|
|
}
|
|
|
|
addNewCustomerToList(CustomerRepository customerViewModel) {
|
|
customerList.add(customerViewModel);
|
|
}*/
|
|
}
|