Ejemplo n.º 1
0
        public JsonResult GetClientsWithDistributor(int distributorId)
        {
            var steps = context.ClientSteps3_5.Include(s => s.Distributors).ToList();

            var model = new List <ClientMapJson>();

            foreach (var item in steps)
            {
                if (item.Distributors != null && item.Distributors.Any(d => d.DistributorId == distributorId))
                {
                    var visit = context.Visits.OrderByDescending(v => v.Id).First(v => v.Id == item.VisitId);
                    var data  = context.BusinessDatas.OrderByDescending(v => v.Id).First(d => d.BusinessId == visit.BusinessId);
                    if (string.IsNullOrEmpty(data.Lat) || string.IsNullOrEmpty(data.Lng))
                    {
                        DataController.GetPosition(ref data);
                        context.Entry(data);
                    }
                    if (string.IsNullOrEmpty(data.Lat) || string.IsNullOrEmpty(data.Lng))
                    {
                        continue;
                    }
                    var newItem = new ClientMapJson();
                    newItem.Name = data.RecipientName;
                    newItem.Lat  = data.Lat;
                    newItem.Lng  = data.Lng;
                    newItem.Id   = visit.BusinessId;
                    model.Add(newItem);
                }
            }
            context.SaveChanges();
            return(Json(model));
        }
Ejemplo n.º 2
0
        public JsonResult GetClientsWithProducer(int producerId)
        {
            var steps = context.ClientSteps2.Include(s => s.LaxTypes).Include(s => s.PackedTypes).ToList();

            var model = new List <ClientMapJson>();

            foreach (var item in steps)
            {
                if ((item.LaxTypes != null && item.LaxTypes.Any(t => context.LaxCementTypes.Single(s => s.Id == t.LaxTypeId).ProducerId == producerId)) || (item.PackedTypes != null && item.PackedTypes.Any(t => context.PackedCementTypes.Single(s => s.Id == t.PackedTypeId).ProducerId == producerId)))
                {
                    var visit = context.Visits.OrderByDescending(v => v.Id).First(v => v.Id == item.VisitId);
                    var data  = context.BusinessDatas.OrderByDescending(v => v.Id).First(d => d.BusinessId == visit.BusinessId);
                    if (string.IsNullOrEmpty(data.Lat) || string.IsNullOrEmpty(data.Lng))
                    {
                        DataController.GetPosition(ref data);
                        context.Entry(data);
                    }
                    if (!string.IsNullOrEmpty(data.Lat) && !string.IsNullOrEmpty(data.Lng))
                    {
                        var newItem = new ClientMapJson();
                        newItem.Name = data.RecipientName;
                        newItem.Lat  = data.Lat;
                        newItem.Lng  = data.Lng;
                        newItem.Id   = visit.BusinessId;
                        model.Add(newItem);
                    }
                }
            }
            context.SaveChanges();
            return(Json(model));
        }