You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.7 KiB
109 lines
3.7 KiB
import 'TesoBusinessDetail.dart';
|
|
import 'Product.dart';
|
|
|
|
class CouponDetails {
|
|
String couponId;
|
|
String businessId;
|
|
Product targetProduct;
|
|
String type;
|
|
int quantity;
|
|
DateTime expiration;
|
|
double worth;
|
|
String state;
|
|
TesoBusinessDetail issuer;
|
|
double productCost;
|
|
double lowerLimit;
|
|
double upperLimit;
|
|
String countID;
|
|
String condition;
|
|
|
|
CouponDetails(
|
|
{this.businessId,
|
|
this.couponId,
|
|
this.expiration,
|
|
this.issuer,
|
|
this.productCost,
|
|
this.quantity,
|
|
this.state,
|
|
this.targetProduct,
|
|
this.type,
|
|
this.worth,
|
|
this.lowerLimit,
|
|
this.upperLimit,
|
|
this.countID,
|
|
this.condition});
|
|
|
|
factory CouponDetails.fromJSON(Map<String, dynamic> json) {
|
|
try {
|
|
return CouponDetails(
|
|
businessId: json['businessId'],
|
|
couponId: json['couponId'],
|
|
targetProduct: Product.fromJson(json['target']),
|
|
expiration: DateTime.parse((json['expiration'].toString())),
|
|
issuer: TesoBusinessDetail.fromJSON(json['issuer']),
|
|
productCost: double.tryParse((json['productCost']).toString()),
|
|
lowerLimit: double.parse((json['lowerLimit']).toString()),
|
|
upperLimit: double.parse((json['upperLimit']).toString()),
|
|
quantity: json['quantity'],
|
|
state: json['state'],
|
|
type: json['type'],
|
|
worth: double.parse((json['worth']).toString()) == 0.0
|
|
? double.parse((json['lowerLimit']).toString())
|
|
: double.parse((json['worth']).toString()),
|
|
countID: json['countID'].toString(),
|
|
condition: json['condition'].toString());
|
|
} catch (e) {
|
|
print(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
factory CouponDetails.fromJSON2(Map<String, dynamic> json) {
|
|
return CouponDetails(
|
|
businessId: json['businessId'],
|
|
couponId: json['couponId'],
|
|
expiration: DateTime.parse((json['expiration'].toString())),
|
|
issuer: TesoBusinessDetail.fromJSON(json['issuer']),
|
|
productCost: double.tryParse((json['productCost']).toString()),
|
|
lowerLimit: double.parse((json['lowerLimit']).toString()),
|
|
upperLimit: double.parse((json['upperLimit']).toString()),
|
|
quantity: json['quantity'],
|
|
state: json['state'],
|
|
type: json['type'],
|
|
worth: double.parse((json['worth']).toString()) == 0.0
|
|
? double.parse((json['lowerLimit']).toString())
|
|
: double.parse((json['worth']).toString()),
|
|
countID: json['countID'].toString(),
|
|
condition: json['condition'].toString());
|
|
}
|
|
|
|
Map<dynamic, dynamic> toJson() {
|
|
final Map<dynamic, dynamic> data = Map<dynamic, dynamic>();
|
|
try {
|
|
data['businessId'] = this.businessId;
|
|
data['couponId'] = this.couponId;
|
|
data['target'] = this.targetProduct;
|
|
data['expiration'] = this.expiration.toIso8601String();
|
|
data['issuer'] = this.issuer;
|
|
data['productCost'] = this.productCost.toString();
|
|
data['quantity'] = this.quantity;
|
|
data['state'] = this.state;
|
|
data['type'] = this.type;
|
|
data['worth'] = this.worth;
|
|
data['lowerLimit'] = this.lowerLimit;
|
|
data['upperLimit'] = this.upperLimit;
|
|
data['countID'] = this.countID;
|
|
data['condition'] = this.condition;
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
return data;
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return '{"businessId": "$businessId", "couponId": "$couponId", "target": "$targetProduct", "couponId": "$couponId", "expiration": "$expiration"' +
|
|
'"issuer": "$issuer", "productCost": "$productCost", "quantity": "$quantity", "state": "$state", "type": "$type", "worth": "$worth",' +
|
|
'"lowerLimit": "$lowerLimit", "upperLimit": "$upperLimit","countID":"$countID","condition":"$condition"}';
|
|
}
|
|
}
|
|
|