예제 #1
0
        public static async Task <bool> CreateContacts(ContactsDataModel contacts)
        {
            try
            {
                ContactsModel contactsModel = new ContactsModel();
                contactsModel.Location = contacts.Location;
                contactsModel.Contacts = contacts.Contacts.ToList <Contact>();

                var json    = JsonConvert.SerializeObject(contactsModel);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpClient client = new HttpClient();
                client.Timeout = TimeSpan.FromMilliseconds(ShortTimeout);
                var uri = new Uri(WebserviceUrls[RegisterEndpoint]);
                client.BaseAddress = uri;

                HttpResponseMessage response = await new HttpClient().PostAsync(uri, content);

                if (GoodResponse(response.StatusCode))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Confirmación", ex.Message, "OK");

                return(false);
            }
        }
예제 #2
0
        public IActionResult Put([FromForm] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // Save Image if exists
            //--------------------------------
            string fileName = SaveImageIfExists(contact);

            // Update contact
            //--------------------------------
            ContactsDataModel _found = _context.Contacts.Find(contact.ContactID);

            _found.FirstName = contact.FirstName;
            _found.LastName  = contact.LastName;
            _found.Email     = contact.Email;
            _found.Phone     = contact.Phone;
            _found.Comments  = contact.Comments;
            _found.Birthday  = contact.Birthday;
            _found.Groups    = contact.Groups;

            if (fileName != "")
            {
                _found.ProfilePicture = FOLDER_NAME + "/" + fileName;
            }
            _context.SaveChanges();
            return(StatusCode(204));
        }
예제 #3
0
        public IActionResult Post([FromForm] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Save Image
            string fileName = SaveImageIfExists(contact);

            string            _newId;
            ContactsDataModel newContact = new ContactsDataModel
            {
                FirstName      = contact.FirstName,
                LastName       = contact.LastName,
                Email          = contact.Email,
                Phone          = contact.Phone,
                Comments       = contact.Comments,
                Birthday       = contact.Birthday,
                Groups         = contact.Groups,
                ProfilePicture = fileName != "" ? FOLDER_NAME + "/" + fileName : null,
            };

            _contactRepository.Add(newContact);
            _contactRepository.SaveChangesAsync();
            _newId = newContact.ContactID;
            return(CreatedAtAction("Get", new { id = _newId }));
        }
예제 #4
0
        public IActionResult Delete(string id)
        {
            ContactsDataModel contact = _context.Contacts.Find(id);

            _context.Contacts.Remove(contact);
            _context.SaveChanges();
            return(StatusCode(204));
        }
        void FilterBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var text = FilterBox.Text;

            ContactsDataModel.FilterUsesContains = true;
            ContactsDataModel.Filter             = text;
            ContactsDataModel.RunFilter();
            ContactsTable.ItemsSource = String.IsNullOrEmpty(text) ? ContactsDataModel.Contacts : ContactsDataModel.FilteredContacts;
        }
 private async void Logout(object sender, RoutedEventArgs e)
 {
     ContactsDataModel.ClearSmartStore();
     if (SDKManager.GlobalClientManager != null)
     {
         await SDKManager.GlobalClientManager.Logout();
     }
     AccountManager.SwitchAccount();
 }
예제 #7
0
 void ContactsDataModel_ContactsSynced(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (_firstSync && ContactsDataModel.Contacts.Count == 0)
     {
         _firstSync = false;
         Task.Delay(1000).ContinueWith(a => ContactsDataModel.SyncDownContacts());
     }
     else
     {
     }
 }
예제 #8
0
 private void Synchronize(object sender, RoutedEventArgs e)
 {
     try
     {
         ContactsDataModel.SyncUpContacts();
     }
     catch (Exception)
     {
         ContactsDataModel.RegisterSoup();
     }
 }
 void ContactsDataModel_ContactsSynced(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (_firstSync && ContactsDataModel.Contacts.Count == 0)
     {
         _firstSync = false;
         ContactsDataModel.SyncDownContacts();
     }
     else
     {
         MessageFlyout.Hide();
     }
 }
 private void Synchronize(object sender, RoutedEventArgs e)
 {
     DisplayProgressFlyout("Synchronizing Data...");
     try
     {
         ContactsDataModel.SyncUpContacts();
     }
     catch (Exception)
     {
         ContactsDataModel.RegisterSoup();
     }
 }
예제 #11
0
        public async Task AddToContacts(string userId, string callerId)
        {
            if (userId == callerId)
            {
                throw new InvalidDataException("Can't add yourself to contacts.");
            }

            try
            {
                await contactsRepository.AddAsync(ContactsDataModel.Create(callerId, userId));

                await unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("Wrong caller id or user id", ex);
            }
        }
 private void ClearSearch(object sender, RoutedEventArgs e)
 {
     ContactsDataModel.Filter = String.Empty;
     ContactsDataModel.RunFilter();
 }
예제 #13
0
        public IActionResult Get(string id)
        {
            ContactsDataModel contact = _context.Contacts.Find(id);

            return(Ok(contact));
        }