/// <summary> /// Link user with another user by secret code /// </summary> /// <param name="sourceAddress">User address</param> /// <param name="coupleCode">Secret code of another user to be linked</param> private void LinkUser(string sourceAddress, string coupleCode) { //Log.TraceStart(); try { CoupleChatDM dm = new CoupleChatDM(); //When code is given then user should be linked if (!string.IsNullOrEmpty(coupleCode)) { var coupleUserAddress = dm.GetUserNumberByCode(coupleCode); if (string.IsNullOrEmpty(coupleUserAddress)) { var message = string.Format(Resources.Error_InvalidCode); Sms.Send(sourceAddress, message); } if (coupleUserAddress == sourceAddress) { var message = string.Format(Resources.Error_InvalidCode); Sms.Send(sourceAddress, message); } else if (dm.IsUserLinked(sourceAddress)) { var message = string.Format(Resources.Error_UserAlreadyLinked); Sms.Send(sourceAddress, message); } else if (dm.IsUserLinked(coupleUserAddress)) { var message = string.Format(Resources.Error_CodeAlreadyLinked); Sms.Send(sourceAddress, message); } else { //Save in DB var status = dm.LinkUser(sourceAddress, coupleUserAddress); if (status) { var message = string.Format(Resources.Info_RegisterSuccessCoupleUser); Sms.Send(sourceAddress, message); //Send OK message to first user Sms.Send(coupleUserAddress, message); } else { Log.Error(string.Format(Resources.Error_AddAndLinkUserFailed, sourceAddress)); var message = string.Format(Resources.Error_CannotCoupleUser); Sms.Send(sourceAddress, message); } } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
/// <summary> /// Send sms to user given by a secret code /// </summary> /// <param name="userAddress">Sender's address</param> /// <param name="code">Receiver's secret code</param> /// <param name="receivedMsg">Sms message</param> private void SendSmsByCode(string userAddress, string code, string receivedMsg) { try { CoupleChatDM dm = new CoupleChatDM(); var receiverAddress = dm.GetUserNumberByCode(code); if (!string.IsNullOrEmpty(receiverAddress)) { Sms.Send(receiverAddress, receivedMsg); } else { Sms.Send(userAddress, Resources.Error_InvalidCode); } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }