Files
Vocasia-LMS-Mobile-apps--TA…/lib/providers/posting_qna_reply_provider.dart

80 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:initial_folder/services/qna_service.dart';
enum ResultState { uninitilized, loading, failed, success }
class PostingQnaReplyProvider with ChangeNotifier {
ResultState _state = ResultState.uninitilized;
ResultState get state => _state;
//Post Qna Reply
Future<bool> postQnaReply(String textRep, String idQna) async {
try {
_state = ResultState.loading;
notifyListeners();
bool response = await QnaService().postQnaReply(textRep, idQna);
if (response) {
_state = ResultState.success;
notifyListeners();
return true;
} else {
_state = ResultState.failed;
notifyListeners();
return false;
}
} catch (e) {
_state = ResultState.failed;
notifyListeners();
return false;
}
}
//Update QNA Reply
Future<bool> editQnaReply(String textRep, int idRep, String idQna) async {
try {
_state = ResultState.loading;
notifyListeners();
bool response = await QnaService().editQnaReply(idRep, textRep, idQna);
if (response) {
_state = ResultState.success;
notifyListeners();
return true;
} else {
_state = ResultState.failed;
notifyListeners();
return false;
}
} catch (e) {
_state = ResultState.failed;
notifyListeners();
return false;
}
}
// Delete Qna Reply
Future<bool> deleteReplyQna(int idRep) async {
try {
_state = ResultState.loading;
notifyListeners();
bool response = await QnaService().deleteReplyQna(idRep);
if (response) {
_state = ResultState.success;
notifyListeners();
return true;
} else {
_state = ResultState.failed;
notifyListeners();
return false;
}
} catch (e) {
_state = ResultState.failed;
notifyListeners();
return false;
}
}
}