public async Task <IActionResult> PostUserPhoneNumberFriends([FromBody] UserPhoneNumbers numbers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var applicationUser = _context.ApplicationUser
                                  .SingleOrDefault(a => a.Id == numbers.UserId.ToString());

            if (applicationUser == null)
            {
                return(NotFound(numbers.UserId));
            }

            //var registeredUsers = _context.ApplicationUser
            //                              .Where(a => a.PhoneNumber.Equals());
            var registeredUsers = from a in _context.ApplicationUser
                                  where numbers.Numbers.Contains(a.PhoneNumber)
                                  select new UserPhoneResult
            {
                UserId      = Guid.Parse(a.Id),
                PhoneNumber = a.PhoneNumber,
                UserName    = a.UserName
            };
            //List of UserPhoneResult.cs should be the return type
            var data = await registeredUsers.ToListAsync();

            return(Ok(data));
            // TODO move this to a friendrequest controller
            //var friends = await _context.FriendRequests
            //                            .Where(f => f.InitiatorId.Equals(numbers.UserId)
            //                                        || f.TargetId.Equals(numbers.UserId))
            //                            .ToListAsync();
            //return Ok(friends);
        }
Example #2
0
 private void AddUserPhoneNumbersToDisplayList(User user)
 {
     foreach (var number in user.UserContactInformations.FirstOrDefault().UserPhoneNumbers)
     {
         UserPhoneNumbers.Add(number.PhoneNumber);
     }
 }
Example #3
0
        // TODO: make this more efficient
        // .Available status will be overwritten by data read from friendslist
        public async Task AcquireUsersFromPhoneNumbers(UserPhoneNumbers numbers)
        {
            var results = await App.approxiMATEService.PostUserPhoneNumberResultsAsync(numbers);

            var friends = await App.approxiMATEService.GetFriendRequestsAsync(numbers.UserId);

            foreach (var item in results)
            {
                for (int i = 0; i < PhoneContacts.Count; ++i)
                {
                    if (PhoneContacts[i].PhoneNumbers.Contains(item.PhoneNumber))
                    {
                        PhoneContacts[i].ApproxUserId = item.UserId.ToString();
                        PhoneContacts[i].Status       = FriendStatus.Available;
                        if (friends.Any(f => f.InitiatorId.Equals(numbers.UserId) && f.TargetId.Equals(item.UserId)))
                        {
                            PhoneContacts[i].Status = FriendStatus.Initiated;
                            if (friends.Any(f => f.InitiatorId.Equals(item.UserId) && f.TargetId.Equals(numbers.UserId)))
                            {
                                PhoneContacts[i].Status = FriendStatus.Mutual;
                            }
                        }
                        else if (friends.Any(f => f.InitiatorId.Equals(item.UserId) && f.TargetId.Equals(numbers.UserId)))
                        {
                            PhoneContacts[i].Status = FriendStatus.PendingRequest;
                        }
                        if (PhoneContacts[i].ApproxUserId.Equals(App.AppUser.id.ToString()))
                        {
                            PhoneContacts[i].Status = FriendStatus.Blocked;
                        }
                    }
                }
            }
        }
Example #4
0
        public async Task AcquirePhoneContacts(Boolean sort)
        {
            var permission = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Contacts);

            if (permission.Equals(PermissionStatus.Granted))
            {
                PhoneContacts.Clear();
                List <string> contactNumbers = new List <string>();
                var           contacts       = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();

                if (sort)
                {
                    contacts = contacts.OrderBy(c => c.Name).ToList();
                }
                string[] splitParam = new string[] { "stringValue=" };
                foreach (Contact c in contacts)
                {
                    // TODO: look at this logic again
                    // Contact.Number contains string listed below:
                    // <CNPhoneNumber: 0x1c4a33520: stringValue=5127994767, initialCountryCode=(null)>
                    PhoneContact pc = new PhoneContact()
                    {
                        Status       = FriendStatus.NotRegistered,
                        Name         = c.Name,
                        PhoneNumber  = ExtractPhoneNumber(c.Number),
                        PhoneNumbers = new List <String>()
                        {
                            ExtractPhoneNumber(c.Number)
                        }
                    };
                    contactNumbers.Add(pc.PhoneNumber);
                    foreach (string str in c.Numbers)
                    {
                        string multi = ExtractPhoneNumber(str);
                        if (!pc.PhoneNumber.Equals(multi))
                        {
                            contactNumbers.Add(multi);
                            pc.PhoneNumbers.Add(multi);
                        }
                    }
                    PhoneContacts.Add(pc);
                }
                UserPhoneNumbers upn = new UserPhoneNumbers()
                {
                    Numbers = contactNumbers,
                    UserId  = App.AppUser.id
                };
                await AcquireUsersFromPhoneNumbers(upn);
            }
            else
            {
                throw new InvalidOperationException("contacts permission is not granted");
                //await Navigation.PopAsync();
                //await Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await App.Current.MainPage.Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await Navigation.PushAsync(new IssuePage("Please provide permission to access contacts."));
                //await Navigation.PopAsync();
            }
        }
Example #5
0
        private void OnNewPhoneNumberReceived(Dictionary <string, string> phoneNumberAndType)
        {
            var user = _userService.GetAllUsers().FirstOrDefault(x => x.Id == _userId);

            foreach (var keyValuePair in phoneNumberAndType)
            {
                UserPhoneNumbers.Add(keyValuePair.Value);
                user.UserContactInformations.FirstOrDefault().UserPhoneNumbers.Add(new UserPhoneNumber()
                {
                    Active      = true, Description = null,
                    PhoneNumber = keyValuePair.Value, UserContactInformationId = user.UserContactInformations.FirstOrDefault().Id
                });
            }
        }
        public async Task <List <UserPhoneResult> > PostUserPhoneNumberResultsAsync(UserPhoneNumbers numbers)
        {
            var items = new List <UserPhoneResult>();

            if (App.AppUser != null && !App.AppUser.id.Equals(numbers.UserId))
            {
                return(items);
            }
            AddJwtHeader();
            var json     = JsonConvert.SerializeObject(numbers);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PostAsync(Constants.ApproxiMATEwebApiBase + "api/UserPhoneNumbers", content);

            if (response.IsSuccessStatusCode)
            {
                var jsonresult = response.Content.ReadAsStringAsync().Result;
                items = JsonConvert.DeserializeObject <List <UserPhoneResult> >(jsonresult);
            }
            return(items);
        }
        public async Task <IActionResult> AddOtherPhoneNumber(AddPhoneNumberViewModel model)
        {
            // Generate the token and send it
            var user = await GetCurrentUserAsync();

            ApplicationDbContext adc = new ApplicationDbContext();

            //Create new user phone number link
            UserPhoneNumbers upn = new UserPhoneNumbers();

            upn.ApplicationUserId = user.Id;
            upn.PhoneNumberType   = model.NumberType;
            upn.PhoneNumber       = model.PhoneNumber;

            adc.Add(upn);
            adc.SaveChanges();


            return(RedirectToAction(nameof(UpdatePhoneNumber)));
            //return View("UpdatePhoneNumber");
        }