// // UserDetailsViewModel.swift // Learn Genie // // Created by Suraj Kumar Mandal on 21/09/21. // import Foundation import Alamofire import RealmSwift class UserDetailsViewModel { var delegate : UserDetailsViewProtocol? // func searchStudent(emailId: String) { // let url = "\(ApiUrl.BASE_URL + ApiUrl.API_SEARCH_STUDENT)?email=\(emailId)" // print(url) // let cookieValue = UserDefaultsConstant.getValueFromUserDefults(for: "cookieValue") ?? "" // let headers: HTTPHeaders = [ // "Content-Type": "application/json", // "Accept": "application/json", // "Cookie": "\(Constant.CookieName) = \(cookieValue)" // ] // print(headers) // // AF.request(url, method: .get, encoding: URLEncoding.httpBody, headers: headers).responseJSON { [self] response in // switch response.result { // case .success(let value): // let data = value as! NSDictionary // let id = data.value(forKey: "id") as? Int ?? 0; // if id == 0 { // self.saveStudent() // } else { // delegate?.showAlert(title: "User already exist.", message: "") // } // case .failure(let error): // print(error) // } // } // } // // func saveStudent() { // let topicData = DBManager.sharedInstance.database.objects(TopicModel.self) // if topicData.count != 0 { // let topicId = topicData[0].id // let levelId = topicData[0].levelId // // let url = "\(ApiUrl.BASE_URL + ApiUrl.API_STUDENT)/save.json" // print(url) // let cookieValue = UserDefaultsConstant.getValueFromUserDefults(for: "cookieValue") ?? "" // let headers: HTTPHeaders = [ // "Content-Type": "application/json", // "Accept": "application/json", // "Cookie": "\(Constant.CookieName) = \(cookieValue)" // ] // print(headers) // // let params: Parameters? // params = [ // "name" : , // "mobile" : "mahindrapass123", // "email" : "admin", // "username" : "mahindrapass123", // "password" : "admin", // "gender" : "mahindrapass123", // "dateOfBirth" : "admin", // "state" : "mahindrapass123", // "district" : "mahindrapass123" // ] // print(params!) // // // studentItem.name = binding.etName.text.toString().trim() // studentItem.mobile = binding.etMobNo.text.toString().trim() // studentItem.email = "${studentItem.mobile}@xyz.com" //TODO: Get Email from Google Sign In. // studentItem.username = BasicMethods.getStringBeforeChar(studentItem.email, '@') // studentItem.password = "${studentItem.mobile.substring(6)}${Constant.SEPARATOR}${studentItem.username.substring(0, if(studentItem.username.length > 4) 4 else studentItem.username.length)}" // studentItem.gender = if(mViewModel.gender.get() == null) "Male" else mViewModel.gender.get().toString() // studentItem.dateOfBirth = if(mViewModel.dob.get() == null) "01/01/1970" else mViewModel.dob.get().toString() // studentItem.state = mViewModel.stateItem?.serverId ?: 0 // studentItem.district = mViewModel.districtItem?.serverId ?: 0 // // // // AF.request(url, method: .get, encoding: URLEncoding.httpBody, headers: headers).responseJSON { [self] response in // switch response.result { // case .success(let value): // let data = value as! NSDictionary // let id = data.value(forKey: "id") as? Int ?? 0; // if id == 0 { // self.saveStudent() // } else { // delegate?.showAlert(title: "User already exist.", message: "") // } // case .failure(let error): // print(error) // } // } // } // } } protocol UserDetailsViewProtocol { func stopActivityIndicator() func showToastMessage(message:String) func showAlert(title:String, message:String) }