UserDetailsViewModel.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // UserDetailsViewModel.swift
  3. // Learn Genie
  4. //
  5. // Created by Suraj Kumar Mandal on 21/09/21.
  6. //
  7. import Foundation
  8. import Alamofire
  9. import RealmSwift
  10. class UserDetailsViewModel {
  11. var delegate : UserDetailsViewProtocol?
  12. // func searchStudent(emailId: String) {
  13. // let url = "\(ApiUrl.BASE_URL + ApiUrl.API_SEARCH_STUDENT)?email=\(emailId)"
  14. // print(url)
  15. // let cookieValue = UserDefaultsConstant.getValueFromUserDefults(for: "cookieValue") ?? ""
  16. // let headers: HTTPHeaders = [
  17. // "Content-Type": "application/json",
  18. // "Accept": "application/json",
  19. // "Cookie": "\(Constant.CookieName) = \(cookieValue)"
  20. // ]
  21. // print(headers)
  22. //
  23. // AF.request(url, method: .get, encoding: URLEncoding.httpBody, headers: headers).responseJSON { [self] response in
  24. // switch response.result {
  25. // case .success(let value):
  26. // let data = value as! NSDictionary
  27. // let id = data.value(forKey: "id") as? Int ?? 0;
  28. // if id == 0 {
  29. // self.saveStudent()
  30. // } else {
  31. // delegate?.showAlert(title: "User already exist.", message: "")
  32. // }
  33. // case .failure(let error):
  34. // print(error)
  35. // }
  36. // }
  37. // }
  38. //
  39. // func saveStudent() {
  40. // let topicData = DBManager.sharedInstance.database.objects(TopicModel.self)
  41. // if topicData.count != 0 {
  42. // let topicId = topicData[0].id
  43. // let levelId = topicData[0].levelId
  44. //
  45. // let url = "\(ApiUrl.BASE_URL + ApiUrl.API_STUDENT)/save.json"
  46. // print(url)
  47. // let cookieValue = UserDefaultsConstant.getValueFromUserDefults(for: "cookieValue") ?? ""
  48. // let headers: HTTPHeaders = [
  49. // "Content-Type": "application/json",
  50. // "Accept": "application/json",
  51. // "Cookie": "\(Constant.CookieName) = \(cookieValue)"
  52. // ]
  53. // print(headers)
  54. //
  55. // let params: Parameters?
  56. // params = [
  57. // "name" : ,
  58. // "mobile" : "mahindrapass123",
  59. // "email" : "admin",
  60. // "username" : "mahindrapass123",
  61. // "password" : "admin",
  62. // "gender" : "mahindrapass123",
  63. // "dateOfBirth" : "admin",
  64. // "state" : "mahindrapass123",
  65. // "district" : "mahindrapass123"
  66. // ]
  67. // print(params!)
  68. //
  69. //
  70. // studentItem.name = binding.etName.text.toString().trim()
  71. // studentItem.mobile = binding.etMobNo.text.toString().trim()
  72. // studentItem.email = "${studentItem.mobile}@xyz.com" //TODO: Get Email from Google Sign In.
  73. // studentItem.username = BasicMethods.getStringBeforeChar(studentItem.email, '@')
  74. // studentItem.password = "${studentItem.mobile.substring(6)}${Constant.SEPARATOR}${studentItem.username.substring(0, if(studentItem.username.length > 4) 4 else studentItem.username.length)}"
  75. // studentItem.gender = if(mViewModel.gender.get() == null) "Male" else mViewModel.gender.get().toString()
  76. // studentItem.dateOfBirth = if(mViewModel.dob.get() == null) "01/01/1970" else mViewModel.dob.get().toString()
  77. // studentItem.state = mViewModel.stateItem?.serverId ?: 0
  78. // studentItem.district = mViewModel.districtItem?.serverId ?: 0
  79. //
  80. //
  81. //
  82. // AF.request(url, method: .get, encoding: URLEncoding.httpBody, headers: headers).responseJSON { [self] response in
  83. // switch response.result {
  84. // case .success(let value):
  85. // let data = value as! NSDictionary
  86. // let id = data.value(forKey: "id") as? Int ?? 0;
  87. // if id == 0 {
  88. // self.saveStudent()
  89. // } else {
  90. // delegate?.showAlert(title: "User already exist.", message: "")
  91. // }
  92. // case .failure(let error):
  93. // print(error)
  94. // }
  95. // }
  96. // }
  97. // }
  98. }
  99. protocol UserDetailsViewProtocol {
  100. func stopActivityIndicator()
  101. func showToastMessage(message:String)
  102. func showAlert(title:String, message:String)
  103. }