marco.pms.mobileapp/lib/model/project_model.dart

66 lines
1.9 KiB
Dart

class ProjectModel {
final String id;
final String name;
final String projectAddress;
final String contactPerson;
final DateTime startDate;
final DateTime endDate;
final int teamSize;
final double completedWork;
final double plannedWork;
final String projectStatusId;
final String? tenantId;
ProjectModel({
required this.id,
required this.name,
required this.projectAddress,
required this.contactPerson,
required this.startDate,
required this.endDate,
required this.teamSize,
required this.completedWork,
required this.plannedWork,
required this.projectStatusId,
this.tenantId,
});
// Factory method to create an instance of ProjectModel from a JSON object
factory ProjectModel.fromJson(Map<String, dynamic> json) {
return ProjectModel(
id: json['id'],
name: json['name'],
projectAddress: json['projectAddress'],
contactPerson: json['contactPerson'],
startDate: DateTime.parse(json['startDate']),
endDate: DateTime.parse(json['endDate']),
teamSize: json['teamSize'],
completedWork: json['completedWork'] != null
? (json['completedWork'] as num).toDouble()
: 0.0,
plannedWork: json['plannedWork'] != null
? (json['plannedWork'] as num).toDouble()
: 0.0,
projectStatusId: json['projectStatusId'],
tenantId: json['tenantId'],
);
}
// Method to convert the ProjectModel instance back to a JSON object
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'projectAddress': projectAddress,
'contactPerson': contactPerson,
'startDate': startDate.toIso8601String(),
'endDate': endDate.toIso8601String(),
'teamSize': teamSize,
'completedWork': completedWork,
'plannedWork': plannedWork,
'projectStatusId': projectStatusId,
'tenantId': tenantId,
};
}
}