Exemplo n.º 1
0
        public HttpResponseMessage Insert(PhoneAddRequest model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                ItemResponse <int> response = new ItemResponse <int>();
                response.Item = _phoneService.Insert(model);

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 2
0
        public int Insert(PhoneAddRequest model)
        {
            int id = 0;

            DataProvider.ExecuteNonQuery("dbo.Phone_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@CountryCode", model.CountryCode);
                paramCollection.AddWithValue("@PhoneNumber", model.PhoneNumber);
                paramCollection.AddWithValue("@Extension", model.Extension);
                paramCollection.AddWithValue("@ModifiedBy", model.ModifiedBy);

                SqlParameter idParameter = new SqlParameter("@UserId", System.Data.SqlDbType.Int);
                idParameter.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(idParameter);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                Int32.TryParse(param["@UserId"].Value.ToString(), out id);
            });

            return(id);
        }
Exemplo n.º 3
0
        public void UpdatePhone(PhoneAddRequest model, string userId)
        {
            if (model.Phone != null)
            {
                model.Phone = ParsePhone(model.Phone);
            }

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.AspNetUsers_UpdatePhoneNumber"
               , inputParamMapper: delegate (SqlParameterCollection paramCollection)
               {
                   paramCollection.AddWithValue("@PhoneNumber", model.Phone);
                   paramCollection.AddWithValue("@Id", userId);

               }

               , returnParameters: delegate (SqlParameterCollection param)
               {

               }
               );
        }
Exemplo n.º 4
0
        public int GeneratePhoneVerificationCodeText(PhoneAddRequest model, string userId, string currentPhone)
        {
            Random rnd = new Random();
            int code = rnd.Next(1000, 10000);
            InsertCode(code, userId);

            //string toNumber = "+18186203478"; //delete when ready for production
            //string toNumber = "+19172946087"; //ramona's cell

            string toNumber = "+1" + model.Phone; //uncomment when ready for production

            var twilio = new TwilioRestClient(_AccountSid, _AuthToken);
            string messageBody = "Here is your verification code: " + code;

            var message = twilio.SendMessage(_TwilioNumber, toNumber
                , messageBody);

            string oldPhone = currentPhone;
            int logId = TextMessageLogInsert(userId, oldPhone
                , model.Phone, messageBody);

            return logId;
        }