Beispiel #1
0
        public async Task <ObservableCollection <FoodLineCom> > GetFoodLine(double la, double lo, double distancia, string idUsuario, string categoria)
        {
            try
            {
                ObservableCollection <FoodLine> xx;
                if (la == 0)
                {
                    xx = await Task.Factory.FromAsync <ObservableCollection <FoodLine> >(proxy.BeginGetFoodLine(0, 0, 0, idUsuario, categoria, null, null), proxy.EndGetFoodLine);
                }
                else
                {
                    xx = await Task.Factory.FromAsync <ObservableCollection <FoodLine> >(proxy.BeginGetFoodLine(la, lo, distancia, idUsuario, categoria, null, null), proxy.EndGetFoodLine);
                }

                //Los platos por proveedor
                var gr = xx.Where(p => p.CProveedor != null &&
                                  p.CPlato.Categoria != "Oferta" &&
                                  p.CPlato.Categoria != "Evento").GroupBy(p => p.Usuario);
                ObservableCollection <FoodLineCom> comp = new ObservableCollection <FoodLineCom>();
                foreach (var i in gr)
                {
                    comp.Add(new FoodLineCom {
                        CProveedor = i.First().CProveedor, Lines = i.ToList()
                    });
                }
                /////////////////////////

                ///////Ofertas y eventos
                var ofertas = xx.Where(p => p.CPlato.Categoria == "Oferta");
                foreach (var i in ofertas)
                {
                    comp.Add(new FoodLineCom {
                        CPlato = i.CPlato, CProveedor = i.CProveedor, Lines = new List <FoodLine>()
                        {
                            i
                        }
                    });
                }
                var eventos = xx.Where(p => p.CPlato.Categoria == "Evento");
                foreach (var i in eventos)
                {
                    comp.Add(new FoodLineCom {
                        CPlato = i.CPlato, CProveedor = i.CProveedor, Lines = new List <FoodLine>()
                        {
                            i
                        }
                    });
                }

                /////////////////////////


                //Solicitudes
                var g2r = xx.Where(p => p.CProveedor == null);
                foreach (var i in g2r)
                {
                    comp.Add(new FoodLineCom {
                        CPlato = i.CPlato, Lines = new List <FoodLine>()
                        {
                            i
                        }
                    });
                }
                //////////////
                return(new ObservableCollection <FoodLineCom>(comp.OrderBy(p => p.Usuario)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }