Пример #1
0
        public async Task <IActionResult> PutGeoLocations(int id, GeoLocations geoLocations)
        {
            if (id != geoLocations.Id)
            {
                return(BadRequest());
            }

            _context.Entry(geoLocations).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GeoLocationsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <GeoLocations> > PostGeoLocations(GeoLocations geoLocations)
        {
            _context.GeoLocation.Add(geoLocations);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGeoLocations", new { id = geoLocations.Id }, geoLocations));
        }
        public ActionResult CustomerAccounts()
        {
            Employee employee  = (Employee)TempData["employee"];
            var      accounts  = db.CustomerAccountDetails.ToList();
            var      customers = db.Customers.Where(x => x.Zip == employee.Zip).ToList();
            List <CustomerAccountDetails> filteredAccounts = new List <CustomerAccountDetails>();

            foreach (var cust in customers)
            {
                foreach (var acc in accounts)
                {
                    if (acc.CustomerId == cust.ID)
                    {
                        filteredAccounts.Add(acc);
                    }
                }
            }
            GeoLocations Geo = new GeoLocations();
            CustomerAndAccountViewModel view = new CustomerAndAccountViewModel()
            {
                accounts = filteredAccounts, customers = customers, geo = Geo
            };
            EmployeeCustomerAccountsViewModel finalView = new EmployeeCustomerAccountsViewModel()
            {
                CustViewModel = view, emp = employee
            };

            TempData["employee"] = employee;
            return(View(finalView));
        }
        public void SetCoords(Employee emp)
        {
            GeoLocations geo    = new GeoLocations();
            var          coords = geo.GetLatandLong(emp);

            emp.lat = coords["lat"];
            emp.lng = coords["lng"];
            db.SaveChanges();
        }
        public void SetCoords(Customer cust)
        {
            GeoLocations geo    = new GeoLocations();
            var          coords = geo.GetLatandLong(cust);

            cust.lat = coords["lat"];
            cust.lng = coords["lng"];
            db.SaveChanges();
        }
        public void SetCoords(Contractor cont)
        {
            GeoLocations geo    = new GeoLocations();
            var          coords = geo.GetLatandLong(cont);

            cont.lat = coords["lat"];
            cont.lng = coords["lng"];
            db.SaveChanges();
        }
Пример #7
0
        public GeoLocations Check(GeoLocations geoLocate, Coordinates coordinate)
        {
            var maxLat = geoLocate.Coordinates[1].lat;
            var minLat = geoLocate.Coordinates[3].lat;
            var maxLng = geoLocate.Coordinates[1].lng;
            var minLng = geoLocate.Coordinates[3].lng;

            if ((maxLat >= coordinate.lat && coordinate.lat >= minLat) && (maxLng >= coordinate.lng && coordinate.lng >= minLng))
            {
                return(geoLocate);
            }
            return(null);
        }
Пример #8
0
        public List <GeoLocations> Compare(object x, object y)
        {
            List <GeoLocations> NewGeoLocation = new List <GeoLocations> {
            };
            List <Coordinates>  coordinates    = (List <Coordinates>)x;
            List <GeoLocations> geoLocations   = (List <GeoLocations>)y;

            foreach (var coordinate in coordinates)
            {
                GeoLocations value = null;
                for (int i = 0; i < geoLocations.Count(); i++)
                {
                    value = Check(geoLocations[i], coordinate);
                    if (value != null)
                    {
                        break;
                    }
                }
                NewGeoLocation.Add(value);
            }

            return(NewGeoLocation);
        }
Пример #9
0
        public static List <ProviderWrapper> Search(SearchRequest searchRequest)
        {
            List <ProviderResult> providerResults = MemoryStorageCaching.Get <List <ProviderResult> >(CACHE_KEY, SECTION)
                                                    ?? new List <ProviderResult>();

            if (!providerResults.Any())
            {
                using (ApplicationContext context = new ApplicationContext())
                {
                    providerResults = context.ProviderResult.Include(t => t.ContactInformations).Include(t => t.Addresses).Include(t => t.ProvidedServices).ToList();
                    MemoryStorageCaching.Set(CACHE_KEY, providerResults, SECTION, new CacheItemPolicy
                    {
                        AbsoluteExpiration = DateTimeOffset.Now.AddHours(1)
                    });
                }
            }

            List <ProviderResult> filteredList = new List <ProviderResult>();
            LatLong latLong;

            foreach (ProviderResult providerResult in providerResults)
            {
                foreach (string filter in searchRequest.Filters)
                {
                    providerResult.ProvidedServices    = providerResult.ProvidedServices.Distinct(new ServicesEquality()).ToList();
                    providerResult.ContactInformations = providerResult.ContactInformations.Distinct(new ContactEquality()).ToList();

                    if (filter.Any())
                    {
                        if (providerResult.ProvidedServices.Any(t => t.Name.ToLower().Contains(filter.ToLower())))
                        {
                            filteredList.Add(providerResult);
                        }
                    }
                    else
                    {
                        filteredList.Add(providerResult);
                    }
                }
            }

            if (!searchRequest.Query.IsValidLatLong(out latLong))
            {
                if (!string.IsNullOrEmpty(searchRequest.Query))
                {
                    Models.GeoLocation latLongRequest = new GoogleGeoCoder().GetLatLong(searchRequest.Query);
                    latLong = new LatLong
                    {
                        Longitude = latLongRequest.Longitude,
                        Latitude  = latLongRequest.Latitude
                    };
                }
            }

            if (latLong == null)
            {
                throw new Exception("Invalid Query Provided");
            }

            List <ProviderWrapper> providerWrappers = GeoLocations.GetProviderDistances(filteredList, latLong.Latitude, latLong.Longitude, searchRequest.Range);

            return(providerWrappers.Take(searchRequest.Limit).ToList());
        }