Beispiel #1
0
        private async void RemoveItem(int?ItemID)
        {
            Item item     = Itens.Find(it => it.ItemID == ItemID);
            var  resposta = await UserDialogs.Instance.ConfirmAsync("Remove List Item?", item.Description, "Yes", "No");

            if (resposta)
            {
                bool useWCF = Preferences.Get("UseWCF", false);
                if (!useWCF)
                {
                    List <Assignment> ListAssignments = await App.SQLiteDb.GetAssignmentsByItemAsync(item.ItemID);

                    foreach (Assignment assi in ListAssignments)
                    {
                        await App.SQLiteDb.DeleteAssignmentAsync(assi);
                    }
                    ListObject obj = AssignmentsAgrupados.Where(assi => assi.ItemID == item.ItemID).FirstOrDefault();
                    AssignmentsAgrupados.Remove(obj);
                    Itens.Remove(item);
                    await App.SQLiteDb.DeleteItemAsync(item);
                }
                else
                {
                    var client = new HttpClient
                    {
                        Timeout     = TimeSpan.FromMilliseconds(15000),
                        BaseAddress = new Uri(GetUrlBase())
                    };

                    using (var response = await client.GetAsync("RemoveItem/" + ItemID))
                    {
                        if (response != null)
                        {
                            if (response.IsSuccessStatusCode)
                            {
                                var respStr = await response.Content.ReadAsStringAsync();

                                ListObject obj = AssignmentsAgrupados.Where(assi => assi.ItemID == item.ItemID).FirstOrDefault();
                                AssignmentsAgrupados.Remove(obj);
                                Itens.Remove(item);
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private async void RemoveAssignment(Assignment assignment)
        {
            var resposta = await UserDialogs.Instance.ConfirmAsync("Remove Assignment?", assignment.Title, "Yes", "No");

            if (resposta)
            {
                bool useWCF = Preferences.Get("UseWCF", false);
                if (!useWCF)
                {
                    ListObject listaObj = AssignmentsAgrupados.Where(obj => obj.ItemID == assignment.ItemID).FirstOrDefault();
                    listaObj.Remove(assignment);
                    // AssignmentsAgrupados.Where(assi => assi.Assignments.Remove(assignment));

                    await App.SQLiteDb.DeleteAssignmentAsync(assignment);
                }
                else
                {
                    var client = new HttpClient
                    {
                        Timeout     = TimeSpan.FromMilliseconds(15000),
                        BaseAddress = new Uri(GetUrlBase())
                    };

                    using (var response = await client.GetAsync("RemoveAssignment/" + assignment.AssignmentID))
                    {
                        if (response != null)
                        {
                            if (response.IsSuccessStatusCode)
                            {
                                var respStr = await response.Content.ReadAsStringAsync();

                                ListObject listaObj = AssignmentsAgrupados.Where(obj => obj.ItemID == assignment.ItemID).FirstOrDefault();
                                listaObj.Remove(assignment);
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public override void OnNavigatedTo(INavigationParameters parameters)
        {
            MessagingCenter.Unsubscribe <CreateItemViewModel, Item>(this, "ItemCreated");
            MessagingCenter.Subscribe <CreateItemViewModel, Item>(this, "ItemCreated", (sender, args) =>
            {
                ListObject objeto = new ListObject()
                {
                    ItemID = args.ItemID, ItemDescription = args.Description
                };
                AssignmentsAgrupados.Add(objeto);
                if (Itens == null)
                {
                    Itens = new List <Item>();
                }
                Itens.Add(args);
            });

            MessagingCenter.Unsubscribe <CreateAssignmentViewModel, Assignment>(this, "AssignmentCreated");
            MessagingCenter.Subscribe <CreateAssignmentViewModel, Assignment>(this, "AssignmentCreated", (sender, args) =>
            {
                ListObject objectList = AssignmentsAgrupados.Where(obj => obj.ItemID == args.ItemID).FirstOrDefault();
                objectList.Add(args);
            });
        }