50 lines
1.0 KiB
Dart
50 lines
1.0 KiB
Dart
|
|
|
||
|
|
import 'product.dart';
|
||
|
|
|
||
|
|
class Reg {
|
||
|
|
String name = "", address = "", type = "";
|
||
|
|
int numberOfShops = 0;
|
||
|
|
|
||
|
|
final String sellerID;
|
||
|
|
final String buyerID;
|
||
|
|
final List<Product> products;
|
||
|
|
|
||
|
|
Map<String, dynamic> toMap() {
|
||
|
|
var _products = [];
|
||
|
|
products.forEach((p) => _products.add(p.toMap()));
|
||
|
|
return {
|
||
|
|
'products': _products,
|
||
|
|
'seller_id': sellerID,
|
||
|
|
'buyer_id': buyerID,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
Reg(this.sellerID, this.buyerID, this.products);
|
||
|
|
|
||
|
|
void addProduct(Product product) {
|
||
|
|
var _product = _get(product.id);
|
||
|
|
if (_product == null) {
|
||
|
|
_product = product;
|
||
|
|
products.add(product);
|
||
|
|
}
|
||
|
|
_product.dailySale = product.dailySale;
|
||
|
|
_product.storageCapacity = product.storageCapacity;
|
||
|
|
}
|
||
|
|
|
||
|
|
void deleteProduct(Product product) {
|
||
|
|
var _product = _get(product.id);
|
||
|
|
if (_product == null) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
products.remove(_product);
|
||
|
|
}
|
||
|
|
|
||
|
|
Product _get(String id) {
|
||
|
|
try {
|
||
|
|
return products.firstWhere((p) => p.id == id);
|
||
|
|
} catch (e) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|