Esempio n. 1
0
        public async Task <IHttpActionResult> Charge()
        {
            //URL: http://localhost:2513/api/v1/chat/charge
            IdeaMartStatusResponse statusResponse = new IdeaMartStatusResponse();

            Log.TraceStart();
            try
            {
                ChatAppDM dm       = new ChatAppDM();
                var       userList = dm.GetAllUserAddressList();

                foreach (var userAddress in userList)
                {
                    Caas caas     = new Caas();
                    var  response = await caas.Charge(_appId, _password, userAddress);

                    if (response.statusCode == Consts.SUCCESS)
                    {
                        //var status = dm.ChargeUser(userAddress);
                    }
                    else
                    {
                        Log.Error(string.Format(Resources.Error_ChargeFailed, userAddress));
                    }
                }

                statusResponse.requestId    = "";
                statusResponse.statusCode   = Consts.SUCCESS;
                statusResponse.statusDetail = Consts.SUCCESS;
                statusResponse.timeStamp    = DateTime.UtcNow.ToString();
                statusResponse.version      = "1.0";
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return(BadRequest());
            }
            Log.TraceEnd();

            return(Ok(statusResponse));
        }
Esempio n. 2
0
        //private bool SendSmsToUser(string userAddress, string message)
        //{
        //    bool status = false;

        //    MtSmsReq mtSmsReq = new MtSmsReq();
        //    mtSmsReq.applicationId = _appId;
        //    mtSmsReq.password = _password;
        //    mtSmsReq.destinationAddress = userAddress;
        //    mtSmsReq.message = message;

        //    SmsSender smsSender = new SmsSender(string.Concat(Consts.URL_BASE_ADDRESS, Consts.URL_SMS_SEND));
        //    MtSmsResp mtSmsResp = smsSender.SendSMSReq(mtSmsReq);

        //    if (mtSmsResp.statusCode == "SUCCESS")
        //        status = true;
        //    else
        //        Log.Error(string.Format(Resources.Error_SendSmsFailed, userAddress));

        //    return status;
        //}

        private async Task <IdeaMartStatusResponse> RegisterUser(string userAddress)
        {
            Log.TraceStart();
            try
            {
                //Subscribe User
                Subscription subscription = new Subscription();
                var          response     = await subscription.Add(_appId, _password, userAddress);

                if (response != null)
                {
                    ChatAppDM dm = new ChatAppDM();

                    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
                        string code = Common.GenerateCode(_codeLength);
                        while (dm.CodeExists(code))
                        {
                            code = Common.GenerateCode(_codeLength);
                        }

                        //Save in DB
                        var userId = dm.SubscribeUser(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;
            }
        }