Merge branch 'pharmacy_mosa_branch' into 'pharmacy'
Pharmacy mosa branch See merge request Cloud_Solution/diplomatic-quarter!176merge-requests/228/merge
commit
7dd72d1324
@ -0,0 +1,32 @@
|
||||
class CountryData {
|
||||
int id;
|
||||
String name;
|
||||
String namen;
|
||||
String twoLetterIsoCode;
|
||||
String threeLetterIsoCode;
|
||||
|
||||
CountryData(
|
||||
{this.id,
|
||||
this.name,
|
||||
this.namen,
|
||||
this.twoLetterIsoCode,
|
||||
this.threeLetterIsoCode});
|
||||
|
||||
CountryData.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
name = json['name'];
|
||||
namen = json['namen'];
|
||||
twoLetterIsoCode = json['two_letter_iso_code'];
|
||||
threeLetterIsoCode = json['three_letter_iso_code'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['name'] = this.name;
|
||||
data['namen'] = this.namen;
|
||||
data['two_letter_iso_code'] = this.twoLetterIsoCode;
|
||||
data['three_letter_iso_code'] = this.threeLetterIsoCode;
|
||||
return data;
|
||||
}
|
||||
}
|
@ -1,24 +1,117 @@
|
||||
|
||||
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
||||
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/Country.dart';
|
||||
import 'package:diplomaticquarterapp/services/pharmacy_services/pharmacyAddress_service.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyAddressesModel.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
||||
import 'package:google_maps_place_picker/google_maps_place_picker.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../base_view_model.dart';
|
||||
|
||||
class PharmacyAddressesViewModel extends BaseViewModel {
|
||||
PharmacyAddressService _pharmacyAddressService = locator<PharmacyAddressService>();
|
||||
List<PharmacyAddressesModel> get address => _pharmacyAddressService.address;
|
||||
PharmacyAddressService _pharmacyAddressService =
|
||||
locator<PharmacyAddressService>();
|
||||
|
||||
List<Addresses> get addresses => _pharmacyAddressService.addresses;
|
||||
|
||||
int get selectedAddressIndex => _pharmacyAddressService.selectedAddressIndex;
|
||||
|
||||
CountryData get country => _pharmacyAddressService.country;
|
||||
|
||||
setSelectedAddressIndex(int index) {
|
||||
_pharmacyAddressService.selectedAddressIndex = index;
|
||||
}
|
||||
|
||||
Future getAddress(address) async {
|
||||
Future getAddressesList() async {
|
||||
setState(ViewState.Busy);
|
||||
await _pharmacyAddressService.getAddress(address);
|
||||
await _pharmacyAddressService.getAddresses();
|
||||
if (_pharmacyAddressService.hasError) {
|
||||
error = _pharmacyAddressService.error;
|
||||
setState(ViewState.Error);
|
||||
} else {
|
||||
print(address.length);
|
||||
setState(ViewState.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Future getCountries(String countryName) async {
|
||||
setState(ViewState.Busy);
|
||||
await _pharmacyAddressService.getCountries(countryName);
|
||||
if (_pharmacyAddressService.hasError) {
|
||||
error = _pharmacyAddressService.error;
|
||||
// setState(ViewState.Error);
|
||||
} else {
|
||||
// setState(ViewState.Idle);
|
||||
}
|
||||
}*/
|
||||
|
||||
Future addEditAddress(PickResult value, Addresses editedAddress) async {
|
||||
setState(ViewState.Busy);
|
||||
|
||||
Addresses sendingAddress;
|
||||
|
||||
if (editedAddress == null) {
|
||||
sendingAddress = Addresses();
|
||||
sendingAddress.id = "0";
|
||||
sendingAddress.firstName = user.firstName;
|
||||
sendingAddress.lastName = user.lastName;
|
||||
sendingAddress.email = user.emailAddress;
|
||||
sendingAddress.company = null;
|
||||
} else {
|
||||
sendingAddress = editedAddress;
|
||||
}
|
||||
value.addressComponents.forEach((element) {
|
||||
if (element.types.contains("country")) {
|
||||
sendingAddress.country = element.longName;
|
||||
}
|
||||
if (element.types.contains("administrative_area_level_1")) {
|
||||
sendingAddress.city = element.longName;
|
||||
}
|
||||
if (element.types.contains("postal_code")) {
|
||||
sendingAddress.zipPostalCode = element.longName;
|
||||
}
|
||||
if (element.types.contains("administrative_area_level_2")) {
|
||||
sendingAddress.province = element.longName;
|
||||
}
|
||||
});
|
||||
sendingAddress.latLong = value.geometry.location.toString();
|
||||
|
||||
await _pharmacyAddressService.getCountries(sendingAddress.country);
|
||||
sendingAddress.countryId = country.id;
|
||||
sendingAddress.stateProvinceId = null;
|
||||
sendingAddress.address1 = value.formattedAddress;
|
||||
sendingAddress.address2 = "";
|
||||
sendingAddress.phoneNumber = user.mobileNumber;
|
||||
sendingAddress.faxNumber = user.faxNumber;
|
||||
sendingAddress.customerAttributes = "";
|
||||
sendingAddress.createdOnUtc = DateTime.now().toString();
|
||||
|
||||
if (editedAddress == null) {
|
||||
await _pharmacyAddressService.addCustomerAddress(sendingAddress);
|
||||
} else {
|
||||
await _pharmacyAddressService.editCustomerAddress(sendingAddress);
|
||||
}
|
||||
|
||||
if (_pharmacyAddressService.hasError) {
|
||||
error = _pharmacyAddressService.error;
|
||||
setState(ViewState.Error);
|
||||
} else {
|
||||
setState(ViewState.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteAddresses(Addresses sendingAddress) async {
|
||||
setState(ViewState.Busy);
|
||||
await _pharmacyAddressService.deleteCustomerAddress(sendingAddress);
|
||||
if (_pharmacyAddressService.hasError) {
|
||||
error = _pharmacyAddressService.error;
|
||||
setState(ViewState.Error);
|
||||
} else {
|
||||
setState(ViewState.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
Future saveSelectedAddressLocally(Addresses selectedAddress) async {
|
||||
await sharedPref.setObject(PHARMACY_SELECTED_ADDRESS, selectedAddress);
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,102 @@
|
||||
import 'package:diplomaticquarterapp/config/config.dart';
|
||||
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/Country.dart';
|
||||
import 'package:diplomaticquarterapp/core/service/base_service.dart';
|
||||
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
|
||||
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
||||
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyAddressesModel.dart';
|
||||
|
||||
class PharmacyAddressService extends BaseService {
|
||||
List<Addresses> addresses = List();
|
||||
CountryData country;
|
||||
int selectedAddressIndex = 0;
|
||||
|
||||
class PharmacyAddressService extends BaseService{
|
||||
Future getAddresses() async {
|
||||
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
|
||||
Map<String, String> queryParams = {'fields': 'addresses'};
|
||||
hasError = false;
|
||||
Addresses selectedAddress;
|
||||
try {
|
||||
await baseAppClient.get("$GET_CUSTOMERS_ADDRESSES$customerId",
|
||||
onSuccess: (dynamic response, int statusCode) async {
|
||||
addresses.clear();
|
||||
var savedAddress =
|
||||
await sharedPref.getObject(PHARMACY_SELECTED_ADDRESS);
|
||||
if (savedAddress != null) {
|
||||
selectedAddress = Addresses.fromJson(savedAddress);
|
||||
}
|
||||
int index = 0;
|
||||
response['customers'][0]['addresses'].forEach((item) {
|
||||
Addresses address = Addresses.fromJson(item);
|
||||
if (selectedAddress != null && selectedAddress.id == item["id"]) {
|
||||
selectedAddressIndex = index;
|
||||
}
|
||||
addresses.add(address);
|
||||
index++;
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
hasError = true;
|
||||
super.error = error;
|
||||
}, queryParams: queryParams);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Future getCountries(String countryName) async {
|
||||
hasError = false;
|
||||
try {
|
||||
await baseAppClient.get("$PHARMACY_GET_COUNTRY",
|
||||
onSuccess: (dynamic response, int statusCode) {
|
||||
// countries.clear();
|
||||
response['countries'].forEach((item) {
|
||||
if (CountryData.fromJson(item).name == countryName ||
|
||||
CountryData.fromJson(item).namen == countryName) {
|
||||
country = CountryData.fromJson(item);
|
||||
}
|
||||
// countries.add(CountryData.fromJson(item));
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
hasError = true;
|
||||
super.error = error;
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
AppSharedPreferences sharedPref = AppSharedPreferences();
|
||||
AppGlobal appGlobal = new AppGlobal();
|
||||
AuthenticatedUser authUser = new AuthenticatedUser();
|
||||
AuthProvider authProvider = new AuthProvider();
|
||||
Future addCustomerAddress(Addresses address) async {
|
||||
makeCustomerAddress(address, ADD_CUSTOMER_ADDRESS);
|
||||
}
|
||||
|
||||
List<PharmacyAddressesModel> get address => address;
|
||||
List<PharmacyAddressesModel> _addressList = List();
|
||||
List<PharmacyAddressesModel> get reviewList => _addressList;
|
||||
String url ="";
|
||||
Future editCustomerAddress(Addresses address) async {
|
||||
makeCustomerAddress(address, EDIT_CUSTOMER_ADDRESS);
|
||||
}
|
||||
|
||||
Future getAddress(address) async {
|
||||
print("step 1");
|
||||
Future deleteCustomerAddress(Addresses address) async {
|
||||
makeCustomerAddress(address, DELETE_CUSTOMER_ADDRESS);
|
||||
}
|
||||
|
||||
Future makeCustomerAddress(Addresses address, String url) async {
|
||||
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
|
||||
hasError = false;
|
||||
url =GET_ADDRESS+"272843?fields=addresses";
|
||||
print(url);
|
||||
await baseAppClient.getPharmacy(url,
|
||||
onSuccess: (dynamic response, int statusCode) {
|
||||
_addressList.clear();
|
||||
response['customers'].forEach((item) {
|
||||
_addressList.add(PharmacyAddressesModel.fromJson(item));
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
hasError = true;
|
||||
super.error = error;
|
||||
});
|
||||
}}
|
||||
super.error = "";
|
||||
|
||||
Map<String, dynamic> customerObject = Map();
|
||||
customerObject["addresses"] = [address];
|
||||
customerObject["id"] = customerId;
|
||||
customerObject["email"] = address.email;
|
||||
customerObject["role_ids"] = [3];
|
||||
Map<String, dynamic> body = Map();
|
||||
body["customer"] = customerObject;
|
||||
|
||||
await baseAppClient.post("$url", onSuccess: (response, statusCode) async {
|
||||
addresses.clear();
|
||||
response['customers'][0]['addresses'].forEach((item) {
|
||||
addresses.add(Addresses.fromJson(item));
|
||||
});
|
||||
}, onFailure: (String error, int statusCode) {
|
||||
hasError = true;
|
||||
super.error = error;
|
||||
}, body: body);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue