/// <summary> /// Register user /// </summary> /// <param name="subscriberId">User address</param> private void RegisterUser(string subscriberId) { //Log.TraceStart(); try { CoupleChatDM dm = new CoupleChatDM(); //Generate code and send string code = Common.GenerateCode(_codeLength); while (dm.CodeExists(code)) { code = Common.GenerateCode(_codeLength); } //Save in DB var userId = dm.AddUser(subscriberId, code); if (userId > 0) { var message = string.Format(Resources.Info_RegisterSuccess, code.ToUpper()); Sms.Send(subscriberId, message); } else { Log.Error(string.Format(Resources.Error_UserSaveFailed, subscriberId)); } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
private async Task <IdeaMartStatusResponse> RegisterUser(string userAddress, string coupleCode) { Log.TraceStart(); try { //Subscribe User Subscription subscription = new Subscription(); var response = await subscription.Add(_appId, _password, userAddress); if (response != null) { CoupleChatDM dm = new CoupleChatDM(); if (response.statusCode == Consts.SUCCESS)//subscription successful { Caas caas = new Caas(); var chargingResponse = await caas.Charge(_appId, _password, userAddress); if (response.statusCode != Consts.SUCCESS) { Log.Error(string.Format(Resources.Error_ChargeFailed, userAddress)); } //Generate code if (string.IsNullOrEmpty(coupleCode)) { string code = Common.GenerateCode(_codeLength); while (dm.CodeExists(code)) { code = Common.GenerateCode(_codeLength); } //Save in DB var userId = dm.AddUser(userAddress, code); if (userId > 0) { var message = string.Format(Resources.Info_RegisterSuccess, code.ToUpper()); var result = Sms.Send(userAddress, message); } else { Log.Error(string.Format(Resources.Error_UserSaveFailed, userAddress)); } } } else if (response.statusCode == Consts.USER_ALREADY_REGISTERED) { string code = "";// dm.GetUserCode(userAddress); var message = string.Format(Resources.Info_UserAlreadyRegistered, code); var result = Sms.Send(userAddress, message); } else { var message = string.Format(response.statusDetail); var result = Sms.Send(userAddress, message); } } Log.TraceEnd(); return(response); } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }