コード例 #1
0
        /// <summary>
        /// Search Contact by 'First Name'
        /// </summary>
        /// <param name="obj"></param>
        private async void SearchContact()
        {
            try
            {
                using (var client = ServerInstance.GetServerInstance())
                {
                    if (client == null)
                    {
                        return;
                    }

                    HttpResponseMessage httpRequestMessage = await client.GetAsync("api/Contact/firstName/" + SearchText + "");

                    if (!httpRequestMessage.IsSuccessStatusCode)
                    {
                        Contacts.Clear();
                        StatusMessage = string.Format("No Contact Found.");
                        return;
                    }

                    var result = await httpRequestMessage.Content.ReadAsAsync <List <ContactModel> >();

                    if (result != null)
                    {
                        Contacts = new ObservableCollection <ContactModel>(result);
                    }

                    StatusMessage = string.Format("Find Command, {0} result found.", Contacts.Count());
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogLevel.Exception, nameof(SearchContact), ex.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Delete selcted contacts
        /// </summary>
        private async void Delete()
        {
            try
            {
                using (var client = ServerInstance.GetServerInstance())
                {
                    if (client == null)
                    {
                        return;
                    }

                    var contactsToBeRemoved = Contacts.Where(x => x.IsChecked).ToList();

                    if (!contactsToBeRemoved.Any())
                    {
                        return;
                    }

                    for (int index = 0; index < contactsToBeRemoved.Count();)
                    {
                        if (contactsToBeRemoved.Count <= index)
                        {
                            continue;
                        }

                        var item = contactsToBeRemoved[index];

                        if (item == null)
                        {
                            continue;
                        }

                        HttpResponseMessage httpRequestMessage = await client.DeleteAsync("api/Contact/" + item.Contact_Id);

                        if (!httpRequestMessage.IsSuccessStatusCode)
                        {
                            StatusMessage = string.Format("Delete command Failed.");
                            return;
                        }

                        var result = await httpRequestMessage.Content.ReadAsAsync <bool>();

                        if (!result)
                        {
                            continue;
                        }

                        Contacts.Remove(item);
                        StatusMessage = string.Format("Delete Command, {0} deleted.", item.Contact_Id);
                        index++;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogLevel.Exception, nameof(Delete), ex.ToString());
            }
        }
コード例 #3
0
        /// <summary>
        /// Add Contact(s)
        /// </summary>
        private async void Add()
        {
            try
            {
                using (var client = ServerInstance.GetServerInstance())
                {
                    if (client == null)
                    {
                        return;
                    }

                    foreach (var contactTobeAdd in Contacts.Where(x => x.IsChecked).ToList())
                    {
                        if (client == null)
                        {
                            return;
                        }

                        HttpResponseMessage httpRequestMessage = await client.PutAsJsonAsync("api/Contact/add", contactTobeAdd);

                        if (!httpRequestMessage.IsSuccessStatusCode)
                        {
                            StatusMessage = string.Format("Add command Failed.");
                            return;
                        }

                        var result = await httpRequestMessage.Content.ReadAsAsync <Guid>();

                        if (result == null || result == Guid.Empty)
                        {
                            return;
                        }

                        contactTobeAdd.Contact_Id = result;
                        StatusMessage             = string.Format("Add Command, {0} added.", contactTobeAdd.Contact_Id);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogLevel.Exception, nameof(Add), ex.ToString());
            }
        }
コード例 #4
0
        /// <summary>
        /// Get all contacts
        /// </summary>
        /// <param name="obj"></param>
        private async void GetAllContacts()
        {
            try
            {
                using (var client = ServerInstance.GetServerInstance())
                {
                    if (client == null)
                    {
                        return;
                    }

                    HttpResponseMessage httpRequestMessage = await client.GetAsync("api/Contact/all");

                    if (!httpRequestMessage.IsSuccessStatusCode)
                    {
                        Contacts.Clear();
                        StatusMessage = string.Format("GET command, Failed or No Contacts Found .");
                        return;
                    }

                    var result = await httpRequestMessage.Content.ReadAsAsync <List <ContactModel> >();

                    if (result == null || !result.Any())
                    {
                        return;
                    }

                    Contacts = new ObservableCollection <ContactModel>(result);

                    StatusMessage = string.Format("GET command, {0} result found.", Contacts.Count());
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogLevel.Exception, nameof(GetAllContacts), ex.ToString());
            }
        }