You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

841 lines
29 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // RecipientViewModel.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/27/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class RecipientViewModel: ModelExtension {
  10. let userId = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
  11. private var cddTransferReasonList: [String] = [String] ()
  12. private var cddTransferReasonValueList: [String] = [String] ()
  13. private var cddStateList: [String] = [String]()
  14. private var cddStateValueList: [String] = [String]()
  15. private var cddDistrictList: [String] = [String]()
  16. private var cddDistrictValueList: [String] = [String]()
  17. private var cddRelationList: [String] = [String] ()
  18. private var cddRelationValueList: [String] = [String] ()
  19. private var countryList: [AgentCountryList] = [AgentCountryList] ()
  20. private var cddCountryList: [String] = [String]()
  21. private var cddCountryFlag: [String] = [String] ()
  22. private var cddCountryIdList: [String] = [String] ()
  23. var recipientModel = AgentCountryList()
  24. var recipientCreatedUpdated: Box<Bool?> = Box(nil)
  25. var recipientListObtained: Box<Bool?> = Box(nil)
  26. var recipientDeleted: Box<Bool?> = Box(nil)
  27. var cddCountryListAvailable: Box<Bool?> = Box(nil)
  28. var cddListAvailable: Box<Int?> = Box(nil)
  29. var recipientArray = [Recipient]()
  30. private var recipient: Recipient!
  31. private var newRecipient: Recipient!
  32. /**
  33. */
  34. var recipientConnectionTimeOut: Box<Bool?> = Box(nil)
  35. var recipientDeletedTimeOut: Box<Bool?> = Box(nil)
  36. override init() {
  37. var reciepient = Recipient()
  38. reciepient.firstName = ""
  39. reciepient.lastName = ""
  40. reciepient.country = ""
  41. reciepient.state = ""
  42. reciepient.state = ""
  43. reciepient.stateId = ""
  44. reciepient.city = ""
  45. reciepient.address = ""
  46. reciepient.district = ""
  47. reciepient.districtId = ""
  48. reciepient.relation = ""
  49. reciepient.relationId = ""
  50. reciepient.mobileNumber = ""
  51. reciepient.email = ""
  52. reciepient.recipientId = ""
  53. reciepient.reason = ""
  54. reciepient.reasonId = ""
  55. reciepient.reason = ""
  56. reciepient.reasonId = ""
  57. reciepient.countryId = ""
  58. self.recipient = reciepient
  59. }
  60. init(recipient: Recipient) {
  61. self.recipient = recipient
  62. }
  63. /**
  64. To update first name
  65. - parameter firstName: first name
  66. */
  67. func updateFirstName(firstName: String) {
  68. recipient.firstName = firstName
  69. }
  70. /**
  71. To update middle name
  72. - parameter middleName: middle name
  73. */
  74. func updateMiddleName(middleName: String) {
  75. recipient.middleName = middleName
  76. }
  77. /**
  78. To update lasr name
  79. - parameter lastName: last name
  80. */
  81. func updateLastName(lastName: String) {
  82. recipient.lastName = lastName
  83. }
  84. /**
  85. To update country
  86. - parameter country: country
  87. */
  88. func updateCountry(country: String) {
  89. recipient.country = country
  90. }
  91. /**
  92. To update state
  93. - parameter state: state
  94. */
  95. func updateState(state: String) {
  96. recipient.state = state
  97. }
  98. /**
  99. To update district
  100. - parameter district: district
  101. */
  102. func updateDistrict(district: String) {
  103. recipient.district = district
  104. }
  105. /**
  106. To update city
  107. - parameter city: city
  108. */
  109. func updateCity(city: String) {
  110. recipient.city = city
  111. }
  112. /**
  113. To update address
  114. - parameter address: address
  115. */
  116. func updateAddress(address: String) {
  117. recipient.address = address
  118. }
  119. /**
  120. To update address
  121. - parameter address: address
  122. */
  123. func updateRelation(relation: String) {
  124. recipient.relation = relation
  125. }
  126. /**
  127. To update mobile
  128. - parameter mobile: mobile
  129. */
  130. func updateMobile(mobile: String) {
  131. recipient.mobileNumber = mobile
  132. }
  133. /**
  134. To update email
  135. - parameter email: email
  136. */
  137. func updateEmail(email: String) {
  138. recipient.email = email
  139. }
  140. /**
  141. To update transferReason
  142. - parameter reason: transferReason
  143. */
  144. func updateTransferReason(reason: String){
  145. recipient.reason = reason
  146. }
  147. /**
  148. To get recipient details
  149. - returns: recipient detail info
  150. */
  151. func getRecipientDetails() -> [String: String] {
  152. if recipient.email == nil {
  153. if recipient.middleName == nil {
  154. return ["firstName": recipient?.firstName ?? "",
  155. "lastName": recipient?.lastName ?? "",
  156. "city": recipient?.city ?? "",
  157. "state": recipient?.state ?? "",
  158. "address": recipient?.address ?? "",
  159. "country": recipient?.country ?? "",
  160. "district": recipient?.district ?? "",
  161. "relation": recipient?.relation ?? "",
  162. "mobileNumber": recipient?.mobileNumber ?? "",
  163. "userId": getUserId(),
  164. "reason": recipient?.reason ?? ""]
  165. } else {
  166. return ["firstName": recipient?.firstName ?? "",
  167. "middleName": recipient?.middleName ?? "",
  168. "lastName": recipient?.lastName ?? "",
  169. "city": recipient?.city ?? "",
  170. "state": recipient?.state ?? "",
  171. "address": recipient?.address ?? "",
  172. "country": recipient?.country ?? "",
  173. "district": recipient?.district ?? "",
  174. "relation": recipient?.relation ?? "",
  175. "mobileNumber": recipient?.mobileNumber ?? "",
  176. "userId": getUserId(),
  177. "reason": recipient?.reason ?? ""]
  178. }
  179. } else {
  180. if recipient.middleName == nil {
  181. return ["firstName": recipient?.firstName ?? "",
  182. "lastName": recipient?.lastName ?? "",
  183. "city": recipient?.city ?? "",
  184. "state": recipient?.state ?? "",
  185. "address": recipient?.address ?? "",
  186. "country": recipient?.country ?? "",
  187. "district": recipient?.district ?? "",
  188. "relation": recipient?.relation ?? "",
  189. "mobileNumber": recipient?.mobileNumber ?? "",
  190. "email": recipient?.email ?? "",
  191. "userId": getUserId(),
  192. "reason": recipient?.reason ?? ""]
  193. } else {
  194. return ["firstName": recipient?.firstName ?? "",
  195. "middleName": recipient?.middleName ?? "",
  196. "lastName": recipient?.lastName ?? "",
  197. "city": recipient?.city ?? "",
  198. "state": recipient?.state ?? "",
  199. "address": recipient?.address ?? "",
  200. "country": recipient?.country ?? "",
  201. "district": recipient?.district ?? "",
  202. "relation": recipient?.relation ?? "",
  203. "mobileNumber": recipient?.mobileNumber ?? "",
  204. "email": recipient?.email ?? "",
  205. "userId": getUserId(),
  206. "reason": recipient?.reason ?? ""]
  207. }
  208. }
  209. }
  210. /**
  211. To remove Recipient
  212. - parameter recipientId: id
  213. */
  214. func removeRecipient(recipientId: String) {
  215. let id = recipientId
  216. if !Reachability.isConnectedToNetwork() {
  217. self.internetConnection.value = false
  218. } else {
  219. RestApiMananger.sharedInstance.deleteRecipient(recipientId: recipientId) { result in
  220. switch result {
  221. case .success(_):
  222. self.recipientDeleted.value = true
  223. case let .failure(errorJSON):
  224. self.setErrorMessage(message: errorJSON["message"].stringValue)
  225. self.recipientDeleted.value = false
  226. case .updateAccessCode:
  227. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  228. result in
  229. if result != "Error"{
  230. let uuid = RestApiMananger.sharedInstance.getUUID()
  231. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  232. self.removeRecipient(recipientId: id)
  233. }
  234. }
  235. case .logOutUser():
  236. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  237. self.anotherLogin.value = true
  238. case .timeOut:
  239. self.recipientDeletedTimeOut.value = false
  240. }
  241. }
  242. }
  243. }
  244. /**
  245. To update recipient details
  246. -parameter recipientId: id
  247. - parameter updateParams: recipient updated detail info
  248. */
  249. func updateRecipient(recipientId: String, updateParams: [String: String]) {
  250. let id = recipientId
  251. let upd_params = updateParams
  252. if !Reachability.isConnectedToNetwork() {
  253. self.internetConnection.value = false
  254. } else {
  255. RestApiMananger.sharedInstance.updateRecipient(recipientId: recipientId, recipientDetails: updateParams) { result in
  256. switch result {
  257. case .success(_):
  258. self.recipientCreatedUpdated.value = true
  259. case let .failure(errorJSON):
  260. self.setErrorMessage(message: errorJSON["message"].stringValue)
  261. self.recipientCreatedUpdated.value = false
  262. case .updateAccessCode:
  263. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  264. result in
  265. if result != "Error"{
  266. let uuid = RestApiMananger.sharedInstance.getUUID()
  267. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  268. self.updateRecipient(recipientId: id, updateParams: upd_params)
  269. }
  270. }
  271. case .logOutUser():
  272. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  273. self.anotherLogin.value = true
  274. case .timeOut:
  275. self.recipientConnectionTimeOut.value = false
  276. }
  277. }
  278. }
  279. }
  280. /// To create recipient
  281. func createRecipient(){
  282. if !Reachability.isConnectedToNetwork() {
  283. self.internetConnection.value = false
  284. } else {
  285. RestApiMananger.sharedInstance.createNewRecipient(recipientDetails: self.getRecipientDetails()) { result in
  286. switch result {
  287. case let .success(createdJSON):
  288. do {
  289. self.newRecipient = try JSONDecoder().decode(Recipient.self, from: createdJSON.rawData())
  290. self.recipientCreatedUpdated.value = true
  291. } catch {
  292. self.recipientCreatedUpdated.value = false
  293. }
  294. case let .failure(errorJSON):
  295. self.setErrorMessage(message: errorJSON["message"].stringValue)
  296. self.recipientCreatedUpdated.value = false
  297. case .updateAccessCode:
  298. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  299. result in
  300. if result != "Error"{
  301. let uuid = RestApiMananger.sharedInstance.getUUID()
  302. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  303. self.createRecipient()
  304. }
  305. }
  306. case .logOutUser():
  307. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  308. self.anotherLogin.value = true
  309. case .timeOut:
  310. self.recipientConnectionTimeOut.value = false
  311. }
  312. }
  313. }
  314. }
  315. /**
  316. To get recipients list with pagination
  317. - parameter size: list size
  318. - parameter page: page no
  319. */
  320. func getAllRecipientsThroughPagination(size: Int , page: Int) {
  321. if !Reachability.isConnectedToNetwork() {
  322. self.internetConnection.value = false
  323. } else {
  324. RestApiMananger.sharedInstance.fetchRecipientListThroughPagination(userId: userId!, page: page, size: size) { result in
  325. switch result {
  326. case let .success(fetchedJSON):
  327. self.recipientArray.removeAll()
  328. guard fetchedJSON.count > 0 else {
  329. self.recipientListObtained.value = true
  330. return
  331. }
  332. for i in 0 ... (fetchedJSON.count-1) {
  333. do {
  334. let recipient = try JSONDecoder().decode(Recipient.self, from: fetchedJSON[i].rawData())
  335. self.recipientArray.append(recipient)
  336. } catch {
  337. }
  338. }
  339. self.recipientListObtained.value = true
  340. case let .failure(errorJSON):
  341. self.setErrorMessage(message: errorJSON["message"].stringValue)
  342. self.recipientListObtained.value = false
  343. case .updateAccessCode():
  344. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  345. result in
  346. if result != "Error"{
  347. let uuid = RestApiMananger.sharedInstance.getUUID()
  348. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  349. self.getAllRecipientsThroughPagination(size: size , page: page)
  350. }
  351. }
  352. case .logOutUser():
  353. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  354. self.anotherLogin.value = true
  355. case .timeOut:
  356. self.recipientConnectionTimeOut.value = false
  357. }
  358. }
  359. }
  360. }
  361. /// - returns: recipient
  362. func getCreatedRecipient() -> Recipient {
  363. return newRecipient
  364. }
  365. /// - returns: recipient list
  366. func getRecipientArray() -> [Recipient] {
  367. return recipientArray
  368. }
  369. /// - returns: state list
  370. func getStateList() -> [String] {
  371. return cddStateList
  372. }
  373. /// - returns: list of state id
  374. func getStateValueList() -> [String] {
  375. return cddStateValueList
  376. }
  377. /**
  378. To get a state
  379. - parameter index: position of state in an array
  380. - returns: state
  381. */
  382. func getState(index: Int) -> String {
  383. return cddStateList[index]
  384. }
  385. /**
  386. To get a state id
  387. - parameter index: position of state id in an array
  388. - returns: state id
  389. */
  390. func getStateValue(index: Int) -> String {
  391. let isIndexValid = cddStateValueList.indices.contains(index)
  392. if isIndexValid == true {
  393. return cddStateValueList[index]
  394. }
  395. return ""
  396. }
  397. /// - returns: list of district
  398. func getDistrictList() -> [String] {
  399. return cddDistrictList
  400. }
  401. /// - returns: list of district id
  402. func getDistrictValueList() -> [String] {
  403. return cddDistrictValueList
  404. }
  405. /**
  406. To get a district
  407. - parameter index: position of district in an array
  408. - returns: district
  409. */
  410. func getDistrict(index: Int) -> String {
  411. return cddDistrictList[index]
  412. }
  413. /**
  414. To get a district id
  415. - parameter index: position of district in an array
  416. - returns: district id
  417. */
  418. func getDistrictValue(index: Int) -> String {
  419. let isIndexValid = cddDistrictValueList.indices.contains(index)
  420. if isIndexValid == true {
  421. return cddDistrictValueList[index]
  422. }
  423. return ""
  424. }
  425. /// - returns: list of transfer reason
  426. func getTransferReason() -> [String] {
  427. return cddTransferReasonList
  428. }
  429. /// - returns: list of transfer reason id
  430. func getTransferReasonValueList() -> [String] {
  431. return cddTransferReasonValueList
  432. }
  433. /**
  434. To get a transferReason id
  435. - parameter index: position of transferReason id in an array
  436. - returns: transferReason id
  437. */
  438. func getTransferReasonValue(index:Int) -> String {
  439. let isIndexValid = cddTransferReasonValueList.indices.contains(index)
  440. if isIndexValid == true {
  441. return cddTransferReasonValueList[index]
  442. }
  443. return ""
  444. }
  445. /**
  446. To get a transferReason
  447. - parameter index: position of transferReason in an array
  448. - returns: transferReason
  449. */
  450. func getTransferReasonName(index: Int) -> String {
  451. return cddTransferReasonList[index]
  452. }
  453. /// - returns: list of relation
  454. func getRelationList() -> [String] {
  455. return cddRelationList
  456. }
  457. /// - returns: list of relation id
  458. func getRelationValueList() -> [String] {
  459. return cddRelationValueList
  460. }
  461. /**
  462. To get a relation id
  463. - parameter index: position of relation id in an array
  464. - returns: relation id
  465. */
  466. func getRelationValue(index: Int) -> String{
  467. let isIndexValid = cddRelationValueList.indices.contains(index)
  468. if isIndexValid == true {
  469. return cddRelationValueList[index]
  470. }
  471. return ""
  472. }
  473. /**
  474. To get a relation
  475. - parameter index: position of relation in an array
  476. - returns: relation
  477. */
  478. func getRelationName(index: Int) -> String {
  479. return cddRelationList[index]
  480. }
  481. /// - returns: list of country detail
  482. func getCountryList() -> [AgentCountryList] {
  483. return countryList
  484. }
  485. /**
  486. To get a Country Flag Url
  487. - parameter index: position of Country Flag Url in an array
  488. - returns: Country Flag Url
  489. */
  490. func getCountryFlagUrl(index: Int) -> String {
  491. if let countryFlag = countryList[index].flagUrl {
  492. return countryFlag
  493. }
  494. return ""
  495. }
  496. /**
  497. To get a Country id
  498. - parameter index: position of Country id in an array
  499. - returns: Country id
  500. */
  501. func getCountryId(index: Int) -> String {
  502. let isIndexValid = countryList.indices.contains(index)
  503. if isIndexValid == true{
  504. if let countryId = countryList[index].countryId{
  505. return countryId
  506. }
  507. }
  508. return ""
  509. }
  510. /**
  511. To get a Country name
  512. - parameter index: position of Country name in an array
  513. - returns: Country name
  514. */
  515. func getCountryName(index: Int) -> String {
  516. return countryList[index].country!
  517. }
  518. /// - returns: list of Country name
  519. func getCountryNameList() -> [String]{
  520. return countryList.map{$0.country!}
  521. }
  522. /// - returns: list of country id
  523. func getCountryIdList() -> [String]{
  524. return countryList.map{$0.countryId!}
  525. }
  526. /// - returns: list of country flag url
  527. func getCountryFlagUrlList() -> [String]{
  528. return countryList.map{$0.flagUrl ?? ""}
  529. }
  530. /**
  531. To set a Country id
  532. - parameter referenceIndex: position of Country id in an array
  533. */
  534. func setCountryId(referenceIndex: Int) {
  535. recipient.country = cddCountryIdList[referenceIndex]
  536. }
  537. /**
  538. To set a transfer reason
  539. - parameter referenceIndex: position of transfer reason in an array
  540. */
  541. func setTransferReason(referenceIndex: Int) {
  542. recipient.reason = cddTransferReasonValueList[referenceIndex]
  543. }
  544. /**
  545. To set a Relation
  546. - parameter referenceIndex: position of Relation in an array
  547. */
  548. func setRelation(referenceIndex: Int) {
  549. recipient.relation = cddRelationValueList[referenceIndex]
  550. }
  551. /**
  552. To set a state
  553. - parameter referenceIndex: position of state in an array
  554. */
  555. func setState(referenceIndex: Int) {
  556. let isIndexValid = cddStateValueList.indices.contains(referenceIndex)
  557. if isIndexValid == true{
  558. recipient.state = cddStateValueList[referenceIndex]
  559. }
  560. }
  561. /**
  562. To set a District
  563. - parameter referenceIndex: position of District in an array
  564. */
  565. func setDistrict(referenceIndex: Int) {
  566. recipient.district = cddDistrictValueList[referenceIndex]
  567. }
  568. /**
  569. To get cdd list such as occupation , relation, state ect
  570. - parameter cddName: cddcode
  571. - parameter param: cdd info
  572. */
  573. func fetchCDDListFor(cddName: String, param: [String: String]) {
  574. if !Reachability.isConnectedToNetwork() {
  575. self.internetConnection.value = false
  576. } else {
  577. RestApiMananger.sharedInstance.getCDDListFor(cddCode: cddName, param: param) { result in
  578. switch result {
  579. case let .success(cddJSON):
  580. switch cddName {
  581. case cddCode.TransferReason.rawValue:
  582. self.cddTransferReasonList.removeAll()
  583. self.cddTransferReasonValueList.removeAll()
  584. case cddCode.Province.rawValue:
  585. self.cddStateValueList.removeAll()
  586. self.cddStateList.removeAll()
  587. case cddCode.District.rawValue:
  588. self.cddDistrictList.removeAll()
  589. self.cddDistrictValueList.removeAll()
  590. case cddCode.Relation.rawValue:
  591. self.cddRelationList.removeAll()
  592. self.cddRelationValueList.removeAll()
  593. default:
  594. return
  595. }
  596. if cddJSON.count > 0 {
  597. for i in 0 ... (cddJSON.count-1) {
  598. do {
  599. let cddNameValuePair = try JSONDecoder().decode(Cdd.self, from: cddJSON[i].rawData())
  600. switch cddName {
  601. /// used for transfer reason
  602. case cddCode.TransferReason.rawValue:
  603. self.cddTransferReasonList.append(cddNameValuePair.name)
  604. self.cddTransferReasonValueList.append(cddNameValuePair.value)
  605. case cddCode.Province.rawValue:
  606. self.cddStateList.append(cddNameValuePair.name)
  607. self.cddStateValueList.append(cddNameValuePair.value)
  608. case cddCode.District.rawValue:
  609. self.cddDistrictList.append(cddNameValuePair.name)
  610. self.cddDistrictValueList.append(cddNameValuePair.value)
  611. case cddCode.Relation.rawValue:
  612. self.cddRelationList.append(cddNameValuePair.name)
  613. self.cddRelationValueList.append(cddNameValuePair.value)
  614. default:
  615. return
  616. }
  617. } catch {
  618. break
  619. }
  620. }
  621. }
  622. switch cddName {
  623. case cddCode.TransferReason.rawValue:
  624. self.cddListAvailable.value = 1
  625. case cddCode.Province.rawValue:
  626. self.cddListAvailable.value = 2
  627. case cddCode.District.rawValue:
  628. self.cddListAvailable.value = 3
  629. case cddCode.Relation.rawValue:
  630. self.cddListAvailable.value = 4
  631. default:
  632. return
  633. }
  634. case let .failure(errorJSON):
  635. self.setErrorMessage(message: errorJSON["message"].stringValue)
  636. self.cddListAvailable.value = 0
  637. case .updateAccessCode:
  638. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  639. result in
  640. if result != "Error"{
  641. let uuid = RestApiMananger.sharedInstance.getUUID()
  642. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  643. self.fetchCDDListFor(cddName: cddName, param: param)
  644. }
  645. }
  646. case .logOutUser():
  647. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  648. self.anotherLogin.value = true
  649. case .timeOut:
  650. self.recipientConnectionTimeOut.value = false
  651. }
  652. }
  653. }
  654. }
  655. /// To get list of country
  656. func fetchListOfCountry(){
  657. if !Reachability.isConnectedToNetwork() {
  658. self.internetConnection.value = false
  659. } else {
  660. RestApiMananger.sharedInstance.fetchCountryList() { result in
  661. switch result {
  662. case let .success(countryListJSON):
  663. self.countryList.removeAll()
  664. guard countryListJSON.count > 0 else {
  665. self.cddCountryListAvailable.value = true
  666. return
  667. }
  668. for i in 0 ... (countryListJSON.count-1) {
  669. do {
  670. let cddCountry = try JSONDecoder().decode(AgentCountryList.self, from: countryListJSON[i].rawData())
  671. if cddCountry.countryId != "118" {
  672. self.countryList.append(cddCountry)
  673. self.cddCountryList.append(cddCountry.country!)
  674. if let flagUrl = cddCountry.flagUrl {
  675. self.cddCountryFlag.append(flagUrl)
  676. } else {
  677. self.cddCountryFlag.append("")
  678. }
  679. self.cddCountryIdList.append(cddCountry.countryId!)
  680. }
  681. } catch {
  682. self.cddCountryListAvailable.value = false
  683. }
  684. }
  685. self.cddCountryListAvailable.value = true
  686. case let .failure(errorJSON):
  687. self.setErrorMessage(message: errorJSON["message"].stringValue)
  688. case .updateAccessCode:
  689. RestApiMananger.sharedInstance.updateAccessCode(userId: self.userId!, password: self.getLoginPassword()) {
  690. result in
  691. if result != "Error"{
  692. let uuid = RestApiMananger.sharedInstance.getUUID()
  693. UserDefaults.standard.set((result + ":" + uuid).toBase64(), forKey: "com.gmeremit.accessCode")
  694. self.fetchListOfCountry()
  695. }
  696. }
  697. case .logOutUser():
  698. RestApiMananger.sharedInstance.cancelExistingNetworkCalls()
  699. self.anotherLogin.value = true
  700. case .timeOut:
  701. self.recipientConnectionTimeOut.value = false
  702. }
  703. }
  704. }
  705. }
  706. /**
  707. To get inex of a country id
  708. - parameter id: position of country id in an array
  709. - returns: index
  710. */
  711. func getIndex(id: String) -> Int {
  712. return getCountryIdList().index(of: id)!
  713. }
  714. /**
  715. check empty textfield in array
  716. - parameter arrayofInfo: list of textfield
  717. - returns: Bool
  718. */
  719. func allFieldsFilled(arrayofInfo: [String]) -> Bool {
  720. for info in arrayofInfo {
  721. if info.isBlank {
  722. return false
  723. }
  724. }
  725. return true
  726. }
  727. }