Пример #1
0
        public async Task <ActionResult <PhoneDetail> > GetPhoneConversations(string username, string phone)
        {            //Update messages for all user phone numbers
            phone = "+" + phone;
            PhoneDetail newResult = _context.PhoneDetails.Where(a => (a.PhoneNumber == phone)).FirstOrDefault();

            return(newResult);
        }
Пример #2
0
        public async Task <IActionResult> PutPhoneDetail(string id, PhoneDetail phoneDetail)
        {
            if (id != phoneDetail.PhoneSid)
            {
                return(BadRequest());
            }

            _context.Entry(phoneDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhoneDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ActionResult <PhoneDetail> > ChangeForwardingNumber(PhoneDetail phone)
        {
            //Add Forwarding Number
            PhoneDetail newResult = await _context.PhoneDetails.Where(a => (a.PhoneSid == phone.PhoneSid)).FirstAsync();

            newResult.ForwardingNumber = phone.ForwardingNumber;
            _context.PhoneDetails.Update(newResult);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Пример #4
0
        public HttpResponseMessage Get(string id)
        {
            string             singleFilePath = String.Format("{0}/../Data/phones/{1}.json", Helper.AssemblyDirectory, id);
            List <PhoneSimple> simplePhones   = new List <PhoneSimple>();
            PhoneDetail        phoneDetail    = new PhoneDetail();
            //JsonSerializer serailizer = new JsonSerializer();
            string content = File.ReadAllText(singleFilePath);
            HttpResponseMessage response = new HttpResponseMessage();
            JToken token = JToken.Parse(content);

            if (token is JArray)
            {
                simplePhones = token.ToObject <List <PhoneSimple> >();
                response     = Request.CreateResponse <List <PhoneSimple> >(HttpStatusCode.OK, simplePhones);
            }
            else if (token is JObject)
            {
                phoneDetail = token.ToObject <PhoneDetail>();
                response    = Request.CreateResponse <PhoneDetail>(HttpStatusCode.OK, phoneDetail);
            }

            return(response);
            //using (StreamReader json = File.OpenText(singleFilePath))
            //{
            //	using (JsonTextReader reader = new JsonTextReader(json))
            //	{
            //		if (token is JArray)
            //		{
            //			simplePhones = serailizer.Deserialize<List<PhoneSimple>>(reader);
            //		}
            //		else if (token is JObject)
            //		{
            //			phoneDetail = serailizer.Deserialize<PhoneDetail>(reader);
            //		}

            //	}
            //}

            //HttpResponseMessage response;
            //if (simplePhones.Count > 0)
            //	response = Request.CreateResponse<List<PhoneSimple>>(HttpStatusCode.OK, simplePhones);
            //else
            //	response = Request.CreateResponse<PhoneDetail>(HttpStatusCode.OK, phoneDetail);
            //return response;
        }
Пример #5
0
        public static Customer GetContact(ContentResolver resolver, Uri uri)
        {
            var customer = new Customer();

            string[] projection =
            {
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Id,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.DisplayName,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Data,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Data1,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.DisplayNamePrimary,
                ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type
            };

            var cursor = resolver.Query(uri, projection, null, null, null);

            if (cursor.MoveToNext())
            {
                var phoneDetail = new PhoneDetail();

                long id       = cursor.GetLong(0);
                var  lastName = cursor.GetString(1);

                if (!string.IsNullOrEmpty(lastName))
                {
                    customer.LastName  = lastName;
                    customer.FirstName = "FirstName";
                }

                var phoneNumber = cursor.GetString(2);
                if (!string.IsNullOrEmpty(phoneNumber))
                {
                    phoneDetail.Number = phoneNumber;
                }

                phoneDetail.Id         = id.ToString();
                phoneDetail.IsPrimary  = true;
                phoneDetail.NumberType = "Other";

                customer.Phone = phoneDetail;
                return(customer);
            }
            return(null);
        }
Пример #6
0
        public async Task <ActionResult <PhoneDetail> > ReleaseNumber(PhoneDetail phone)
        {
            TwilioClient.Init("28361e6c-85b8-40f5-bde1-bfc8cf68a96c", "PT65bfa7479efd98c38f525e7c352277e70aff63ef22f4e8be", new Dictionary <string, object> {
                ["signalwireSpaceUrl"] = "manish.signalwire.com"
            });
            try
            {
                IncomingPhoneNumberResource.Delete(pathSid: phone.PhoneSid);
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            //Remove from context
            var newResult = await _context.PhoneDetails.Where(a => (a.PhoneSid == phone.PhoneSid)).FirstAsync();

            _context.PhoneDetails.Remove(newResult);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public string InsertPhoneEvent(Wrapper wrapper)
        {
            bool succsess = false;

            if (!_userService.IsRegisteredUserHaveUniqueGuidAndExceedQuota(Guid.Parse(wrapper.userUniqGuid)))
            {
                return(false.ToString());
            }


            String sendtype = wrapper.sendType;

            //Depends on the type(ss) ,we initiate new class and insert it to corresponded field
            switch (sendtype)
            {
            case "PHONEDETAIL":
                //that means,phone for the first time record database.so we need to
                //call _phoneDetailService.Insert methot

                // we are mapping here

                var _phoneDetail = new PhoneDetail();
                _phoneDetail = wrapper.phoneDetail;
                Model.PhoneDetail.PhoneDetail ph = Mapper.Map <PhoneDetail, Model.PhoneDetail.PhoneDetail>(_phoneDetail);
                succsess = _phoneDetailService.Insert(ph);
                break;

            case "CALLDETAIL":
                //that means,phone get a call activity ,so we need to
                //call _callDetailService.Insert methot

                var _phoneuniqeid = wrapper.phoneUniqId;
                //we are finding unique phone record
                var dd = _phoneDetailService.FindByPhoneUniqeId(_phoneuniqeid);

                var ph1 = Mapper.Map <Wcf.Phone.CallDetail,
                                      ByX.Model.CallDetail.CallDetail>(wrapper.callDetail);
                ph1.IDF  = dd.Id;
                succsess = _callDetailService.Insert(ph1);

                break;

            case "MESSAGEDETAIL":
                //that means,phone get a message activity so we need to
                //call _messageDetailService.Insert methot

                var _phoneuniqeid2 = wrapper.phoneUniqId;
                var dd2            = _phoneDetailService.FindByPhoneUniqeId(_phoneuniqeid2);

                var ph2 = new ByX.Model.MessageDetail.MessageDetail();
                ph2 = Mapper.Map <Wcf.Phone.MessageDetail,
                                  Model.MessageDetail.MessageDetail>(wrapper.messageDetail);
                ph2.IDF  = dd2.Id;
                succsess = _messageDetailService.Insert(ph2);

                break;
            }


            return(succsess.ToString());
        }
Пример #8
0
        public async Task <ActionResult <PhoneDetail> > PostPhoneDetailUs(PhoneDetail phoneDetail)
        {
            var client  = new RestClient("https://manish.signalwire.com/api/relay/rest/phone_numbers/search?region=TX");
            var request = new RestRequest(Method.GET);
            var cancellationTokenSource = new System.Threading.CancellationTokenSource();

            request.AddHeader("Authorization", "Basic MjgzNjFlNmMtODViOC00MGY1LWJkZTEtYmZjOGNmNjhhOTZjOlBUNjViZmE3NDc5ZWZkOThjMzhmNTI1ZTdjMzUyMjc3ZTcwYWZmNjNlZjIyZjRlOGJl");
            request.AddHeader("Content-Type", "application/json");
            var response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);

            var jsonObj = JObject.Parse(response.Content.ToString());
            var numList = jsonObj["data"].Last();

            Debug.WriteLine(numList);
            var numberToPurchase = jsonObj["data"].Last()["e164"];

            Debug.WriteLine(numberToPurchase);


            //Purchase #
            client  = new RestClient("https://manish.signalwire.com/api/relay/rest/phone_numbers/");
            request = new RestRequest(Method.POST);
            cancellationTokenSource = new System.Threading.CancellationTokenSource();
            request.AddHeader("Authorization", "Basic MjgzNjFlNmMtODViOC00MGY1LWJkZTEtYmZjOGNmNjhhOTZjOlBUNjViZmE3NDc5ZWZkOThjMzhmNTI1ZTdjMzUyMjc3ZTcwYWZmNjNlZjIyZjRlOGJl");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"number\"\r\n\r\n" + numberToPurchase + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
            response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);

            var purchasedNumberId = (JObject.Parse(response.Content.ToString()))["id"];

            Debug.Write("ID of Phone no");
            Debug.Write(purchasedNumberId);

            //Add to Group Membership
            client  = new RestClient("https://manish.signalwire.com/api/relay/rest/number_groups/4ccced3c-c49b-4cfe-a70b-b647c2e4b549/number_group_memberships");
            request = new RestRequest(Method.POST);
            cancellationTokenSource = new System.Threading.CancellationTokenSource();
            request.AddHeader("Authorization", "Basic MjgzNjFlNmMtODViOC00MGY1LWJkZTEtYmZjOGNmNjhhOTZjOlBUNjViZmE3NDc5ZWZkOThjMzhmNTI1ZTdjMzUyMjc3ZTcwYWZmNjNlZjIyZjRlOGJl");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"phone_number_id\"\r\n\r\n" + purchasedNumberId + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
            response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);

            //Add message context to group
            client  = new RestClient("https://manish.signalwire.com/api/relay/rest/phone_numbers/" + purchasedNumberId);
            request = new RestRequest(Method.PUT);
            cancellationTokenSource = new System.Threading.CancellationTokenSource();
            request.AddHeader("Authorization", "Basic MjgzNjFlNmMtODViOC00MGY1LWJkZTEtYmZjOGNmNjhhOTZjOlBUNjViZmE3NDc5ZWZkOThjMzhmNTI1ZTdjMzUyMjc3ZTcwYWZmNjNlZjIyZjRlOGJl");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nVerifitGroup\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"message_handler\"\r\n\r\nrelay_context\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"message_relay_context\"\r\n\r\nVerifit\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
            response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);

            //Add call context to group
            client  = new RestClient("https://manish.signalwire.com/api/relay/rest/phone_numbers/" + purchasedNumberId);
            request = new RestRequest(Method.PUT);
            cancellationTokenSource = new System.Threading.CancellationTokenSource();
            request.AddHeader("Authorization", "Basic MjgzNjFlNmMtODViOC00MGY1LWJkZTEtYmZjOGNmNjhhOTZjOlBUNjViZmE3NDc5ZWZkOThjMzhmNTI1ZTdjMzUyMjc3ZTcwYWZmNjNlZjIyZjRlOGJl");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
            request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nVerifitGroup\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"call_handler\"\r\n\r\nrelay_context\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"call_relay_context\"\r\n\r\nVerifit\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
            response = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);


            //Save it to model
            Console.WriteLine(phoneDetail.UserName);
            phoneDetail.UserName    = (phoneDetail.UserName).ToLower();
            phoneDetail.PhoneNumber = numberToPurchase.ToString();
            phoneDetail.PhoneSid    = purchasedNumberId.ToString();
            DateTime createDate = DateTime.Now;
            DateTime expireDate = createDate.AddDays(30);

            phoneDetail.TimeCreated = (createDate.ToString("s"));
            phoneDetail.TimeExpired = (expireDate.ToString("s"));


            _context.PhoneDetails.Add(phoneDetail);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPhoneDetail", new { id = phoneDetail.PhoneSid }, phoneDetail));
        }