123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // 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)
- }
|