Esempio n. 1
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);
            });
        }
Esempio n. 2
0
        private async void PeriodChanged()
        {
            AssignmentsAgrupados.Clear();
            ListObject listaObj;


            if (Itens != null)
            {
                bool useWCF = Preferences.Get("UseWCF", false);
                if (!useWCF)
                {
                    foreach (Item element in Itens)
                    {
                        listaObj = new ListObject()
                        {
                            ItemDescription = element.Description, ItemID = element.ItemID
                        };

                        List <Assignment> ListAssignments = null;

                        ListAssignments = await App.SQLiteDb.GetAssignmentsByItemAsync(element.ItemID);

                        foreach (Assignment assi in ListAssignments)
                        {
                            assi.AssignmentDate = Convert.ToDateTime(assi.DateString);
                            if (SelectedPeriod.Value == 2 && DatesAreInTheSameWeek(assi.AssignmentDate, DateTime.Now))
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 1 && DatesAreInTheSameDay(assi.AssignmentDate, DateTime.Now))
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 3 && assi.AssignmentDate.Month == DateTime.Now.Month && assi.AssignmentDate.Year == DateTime.Now.Year)
                            {
                                listaObj.Add(assi);
                            }
                            else if (SelectedPeriod.Value == 4 && assi.AssignmentDate.CompareTo(DateTime.Today) >= 0)
                            {
                                listaObj.Add(assi);
                            }
                        }
                        listaObj.ItemID          = element.ItemID;
                        listaObj.ItemDescription = element.Description;
                        AssignmentsAgrupados.Add(listaObj);
                    }
                }
                else
                {
                    if (Itens != null && Itens.Count > 0)
                    {
                        var client = new HttpClient
                        {
                            Timeout     = TimeSpan.FromMilliseconds(15000),
                            BaseAddress = new Uri(GetUrlBase())
                        };

                        var json    = JsonConvert.SerializeObject(Itens);
                        var content = new StringContent(json, Encoding.UTF8, "application/json");
                        using (var response2 = await client.PostAsync("GetAssignmentsByItem", content))
                        {
                            if (response2 != null)
                            {
                                if (response2.IsSuccessStatusCode)
                                {
                                    var respStr2 = await response2.Content.ReadAsStringAsync();

                                    if (!String.IsNullOrEmpty(respStr2))
                                    {
                                        List <Assignment> ListAssignments = JsonConvert.DeserializeObject <List <Assignment> >(respStr2);
                                        foreach (Item element in Itens)
                                        {
                                            listaObj = new ListObject()
                                            {
                                                ItemDescription = element.Description, ItemID = element.ItemID
                                            };
                                            foreach (Assignment assi in ListAssignments)
                                            {
                                                if (assi.ItemID == element.ItemID)
                                                {
                                                    assi.AssignmentDate = Convert.ToDateTime(assi.DateString);
                                                    if (SelectedPeriod.Value == 2 && DatesAreInTheSameWeek(assi.AssignmentDate, DateTime.Now))
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 1 && DatesAreInTheSameDay(assi.AssignmentDate, DateTime.Now))
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 3 && assi.AssignmentDate.Month == DateTime.Now.Month && assi.AssignmentDate.Year == DateTime.Now.Year)
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                    else if (SelectedPeriod.Value == 4 && assi.AssignmentDate.CompareTo(DateTime.Today) >= 0)
                                                    {
                                                        listaObj.Add(assi);
                                                    }
                                                }
                                            }
                                            listaObj.ItemID          = element.ItemID;
                                            listaObj.ItemDescription = element.Description;
                                            AssignmentsAgrupados.Add(listaObj);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Warning", "Connection Failed", "OK");
                            }
                        }
                    }
                }
            }
        }