Ejemplo n.º 1
0
        public void FindMultiplePetsInRadiusFromLocation()
        {
            const double SearchRadiusInKm = 2.91;

            this.PopulateDatabase();

            var testLocation = new LocationDTO
            {
                Latitude  = 42.683074,
                Longitude = 23.293244
            };

            string searcherId = "searcherId";

            // Act
            var petCollection = this.petService.FindPetsInRadius(searcherId, testLocation, SearchRadiusInKm);

            // Assert
            petCollection
            .Should()
            .HaveCount(2);

            var firstPet = petCollection.FirstOrDefault();

            firstPet.Id.Should().Be(FirstPetId);
            firstPet.Owner.Id.Should().Be(FirstPetOwnerId);

            var secondPet = petCollection.ElementAt(1);

            secondPet.Id.Should().Be(SecondPetId);
            secondPet.Owner.Id.Should().Be(SecondPetOwnerId);
        }
        /// <summary>
        /// Creates a location record within the dimension table
        /// </summary>
        /// <param name="location"></param>
        public bool CreateLocationDimension(LocationDTO location)
        {
            bool Success = false;

            SQLAzure.DbConnection dbConn = new SQLAzure.DbConnection(_connectionString);

            try
            {
                string query = @"IF NOT EXISTS (SELECT LocationID from DimLocation WHERE LocationID = @LocationID)
                                    INSERT INTO DimLocation (LocationID, LocationNumber) VALUES (@LocationID, @LocationNumber)";

                dbConn.Open();

                SQLAzure.RetryLogic.DbCommand dbComm = new SQLAzure.RetryLogic.DbCommand(dbConn);
                dbComm.CommandText = query;

                dbComm.Parameters.Add(new SqlParameter("LocationID", location.LocationID));
                dbComm.Parameters.Add(new SqlParameter("LocationNumber", location.LocationNumber));

                dbComm.ExecuteNonQuery(System.Data.CommandType.Text);

                Success = true;
            }
            catch (SqlException)
            {
                throw;
            }
            finally
            {
                dbConn.Close();
            }

            return(Success);
        }
Ejemplo n.º 3
0
        public void SearchersPetsDoNotShowUpInSearch()
        {
            // Arrange
            const double SearchRadiusInKm = 3;

            this.PopulateDatabase();

            var testLocation = new LocationDTO
            {
                Latitude  = 42.683074,
                Longitude = 23.293244
            };

            string searcherId = FirstPetOwnerId;

            // Act
            var petCollection = this.petService.FindPetsInRadius(searcherId, testLocation, SearchRadiusInKm);

            // Assert
            petCollection
            .Should()
            .HaveCount(1);

            var pet = petCollection.FirstOrDefault();

            pet.Id.Should().Be(SecondPetId);
            pet.Owner.Id.Should().Be(SecondPetOwnerId);
        }
Ejemplo n.º 4
0
        public void FindOnePetInRadiusFromLocation()
        {
            // Arrange
            const double SearchRadiusInKm  = 1;
            const double DistanceToPetInKm = 0.8;

            this.PopulateDatabase();

            var testLocation = new LocationDTO
            {
                Latitude  = 42.683074,
                Longitude = 23.293244
            };

            this.locationServiceMock.Setup(locationService => locationService.Distance(testLocation, It.IsAny <LocationDTO>(), It.IsAny <DistanceUnit>())).Returns(DistanceToPetInKm);

            string searcherId = SecondPetOwnerId;

            // Act
            var petCollection = this.petService.FindPetsInRadius(searcherId, testLocation, SearchRadiusInKm);

            // Assert
            petCollection
            .Should()
            .HaveCount(1);

            var pet = petCollection.FirstOrDefault();

            pet.Id.Should().Be(FirstPetId);
            pet.Distance.Should().Be(DistanceToPetInKm);
            pet.Owner.Id.Should().Be(FirstPetOwnerId);
        }
Ejemplo n.º 5
0
        public async void RemoveWithObjectAsync_GivenDatabaseError_ReturnsERROR_DELETING()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            locationRepositoryMock.Setup(c => c.DeleteAsync(locationToDelete.Id)).ReturnsAsync(false);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { });
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.ERROR_DELETING, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(locationToDelete.Id));
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Ejemplo n.º 6
0
        public async void CreateAsync_GivenLocationyExists_ReturnsSUCCESS()
        {
            var locationToCreate = new LocationCreateDTO
            {
                City    = "Sydney",
                Country = "Australia"
            };

            var existingLocation = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToCreate.City, locationToCreate.Country)).ReturnsAsync(existingLocation);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.CreateAsync(locationToCreate);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToCreate.City, locationToCreate.Country));
                locationRepositoryMock.Verify(c => c.CreateAsync(It.IsAny <LocationCreateDTO>()), Times.Never());
            }
        }
Ejemplo n.º 7
0
        public async void RemoveWithObjectAsync_GivenLocationExistsAndInNoProjectsOrUsers_ReturnsSuccess()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            locationRepositoryMock.Setup(c => c.DeleteAsync(locationToDelete.Id)).ReturnsAsync(true);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { });
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(locationToDelete.Id));
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Ejemplo n.º 8
0
        public async void RemoveWithObjectAsync_GivenLocationExistsInMoreThanOneProjectAndUser_ReturnsSuccess()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            var projectsArray = new ProjectSummaryDTO[]
            {
                new ProjectSummaryDTO {
                    Title = "Project1", LocationId = locationToDelete.Id
                },
                new ProjectSummaryDTO {
                    Title = "Project2", LocationId = locationToDelete.Id
                }
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(projectsArray);
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(It.IsAny <int>()), Times.Never());
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Ejemplo n.º 9
0
        public async void UpdateAsync_GivenLocationExists_ReturnsSuccess()
        {
            var locationToUpdate = new LocationDTO
            {
                Id      = 1,
                City    = "Sydne",
                Country = "Australia"
            };

            var locationToUpdateWithChanges = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToUpdateWithChanges.Id)).ReturnsAsync(locationToUpdate);
            locationRepositoryMock.Setup(c => c.UpdateAsync(locationToUpdateWithChanges)).ReturnsAsync(true);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.UpdateAsync(locationToUpdateWithChanges);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToUpdateWithChanges.Id));
                locationRepositoryMock.Verify(c => c.UpdateAsync(locationToUpdateWithChanges));
            }
        }
Ejemplo n.º 10
0
        public async void UpdateAsync_GivenErrorUpdating_ReturnsERROR_UPDATING()
        {
            var locationToUpdate = new LocationDTO
            {
                Id      = 1,
                City    = "Sydne",
                Country = "Australia"
            };

            var locationToUpdateWithChanges = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToUpdateWithChanges.Id)).ReturnsAsync(locationToUpdate);
            locationRepositoryMock.Setup(c => c.UpdateAsync(locationToUpdateWithChanges)).ReturnsAsync(false);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.UpdateAsync(locationToUpdateWithChanges);

                Assert.Equal(ResponseLogic.ERROR_UPDATING, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToUpdateWithChanges.Id));
                locationRepositoryMock.Verify(c => c.UpdateAsync(locationToUpdateWithChanges));
            }
        }
Ejemplo n.º 11
0
        public async void FindAsyncWithCity_GivenLocationsExist_ReturnsEnumerableLocations()
        {
            var locationsToReturn = new LocationDTO[]
            {
                new LocationDTO {
                    Id = 1, City = "Sydney", Country = "Australia"
                },
                new LocationDTO {
                    Id = 2, City = "Melbourne", Country = "Australia"
                },
                new LocationDTO {
                    Id = 3, City = "Brisbane", Country = "Australia"
                }
            };

            locationRepositoryMock.Setup(c => c.FindWildcardAsync("e")).ReturnsAsync(locationsToReturn);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var results = await logic.FindAsync("e");

                Assert.Equal(locationsToReturn, results);
                locationRepositoryMock.Verify(c => c.FindWildcardAsync("e"));
            }
        }
Ejemplo n.º 12
0
        partial void Merge(PolygonLocation entity, LocationDTO dto, object state)
        {
            var zrange = dto.ZRange;

            if (zrange != null && zrange.Length == 2)
            {
                entity.ZRange = this.vector2DConverter.Convert(zrange, dto);
            }

            var points = dto.Points;

            if (points != null)
            {
                entity.Points = new List <Vector2D>(points.Length);
                foreach (var point in points)
                {
                    if (point == null || point.Length != 2)
                    {
                        continue;
                    }

                    entity.Points.Add(this.vector2DConverter.Convert(point, dto));
                }
            }
        }
Ejemplo n.º 13
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();

            try
            {
                LocationDTO obj = new LocationDTO();
                obj.ID         = -1;
                obj.City       = txtCity.Text;
                obj.District   = txtDistrict.Text;
                obj.Region     = txtRegion.Text;
                obj.StreetName = txtStreetName.Text;

                ds = LocationDAO.Location_Search(obj);
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgvLocation.DataSource = ds.Tables[0].Copy();
                }
                else
                {
                    clsMessages.ShowWarning("Không tìm thấy");
                }
            }
            catch (Exception ex)
            {
                clsMessages.ShowErrorException(ex);
            }
            finally
            {
                ds.Dispose();
            }
        }
        /// <summary>
        /// Updates a location record within the dimension table
        /// </summary>
        /// <param name="location"></param>
        public bool UpdateLocationDimension(LocationDTO location)
        {
            bool Success = false;

            SQLAzure.DbConnection dbConn = new SQLAzure.DbConnection(_connectionString);

            try
            {
                string query = @"UPDATE DimLocation SET LocationID = @LocationID, LocationNumber = @LocationNumber WHERE ID = @ID";
                dbConn.Open();

                SQLAzure.RetryLogic.DbCommand dbComm = new SQLAzure.RetryLogic.DbCommand(dbConn);
                dbComm.CommandText = query;

                dbComm.Parameters.Add(new SqlParameter("ID", location.ID));
                dbComm.Parameters.Add(new SqlParameter("LocationID", location.LocationID));
                dbComm.Parameters.Add(new SqlParameter("LocationNumber", location.LocationNumber));

                dbComm.ExecuteNonQuery(System.Data.CommandType.Text);

                Success = true;
            }
            catch (SqlException)
            {
                throw;
            }
            finally
            {
                dbConn.Close();
            }

            return(Success);
        }
        /// <summary>
        /// Returns a single location dimension
        /// </summary>
        /// <returns></returns>
        public LocationDTO GetLocationDimension(int ID)
        {
            SQLAzure.DbConnection dbConn   = new SQLAzure.DbConnection(_connectionString);
            LocationDTO           location = new LocationDTO();

            try
            {
                dbConn.Open();

                SQLAzure.RetryLogic.DbCommand dbComm = new SQLAzure.RetryLogic.DbCommand(dbConn);
                dbComm.CommandText = "SELECT ID, AccountID, AccountName FROM DimAccount WHERE ID = @ID";

                dbComm.Parameters.Add(new SqlParameter("ID", ID));

                System.Data.IDataReader rdr = dbComm.ExecuteReader(System.Data.CommandType.Text);

                while (rdr.Read())
                {
                    location.ID             = Convert.ToInt32(rdr["ID"]);
                    location.LocationID     = Guid.Parse(rdr["LocationID"].ToString());
                    location.LocationNumber = Convert.ToInt32(rdr["LocationNumber"].ToString());
                }
            }
            catch (SqlException)
            {
                throw;
            }
            finally
            {
                dbConn.Close();
            }

            return(location);
        }
Ejemplo n.º 16
0
        public bool TestAddStaffToLocation()
        {
            using (var scope = services.CreateScope())
            {
                var locationService = scope.ServiceProvider.GetService <ILocationService>();
                var locationRepo    = scope.ServiceProvider.GetService <IRepository <Location> >();

                LocationDTO locationDTO = new LocationDTO()
                {
                    Name = "Test location", Address = "E la tara", Capacity = 2, RentFee = 2200
                };
                int      locationId = locationService.CreateLocation(locationDTO);
                StaffDTO staffDTO   = new StaffDTO()
                {
                    Id = 1059, FirstName = "Cosmin1", LastName = "Popescu", Email = "*****@*****.**", Phone = "0745600566", Fee = 1500, StaffRoleId = 2
                };
                StaffDTO staffDTO1 = new StaffDTO()
                {
                    Id = 0, FirstName = "Becks", LastName = "LA1L", Email = "*****@*****.**", Phone = "0789898989", Fee = 8, StaffRoleId = 3
                };
                List <StaffDTO> staffDTOs = new List <StaffDTO>()
                {
                    staffDTO, staffDTO1
                };

                locationService.AddStaffLocation(staffDTOs, locationId);

                int numberOfTotalStaffOfNewLocation = locationRepo.Query().Include(l => l.Staffs).Where(l => l.Id == locationId).FirstOrDefault().Staffs.Count;
                return(numberOfTotalStaffOfNewLocation == 2);
            }
        }
        public HttpResponseMessage GetLocationByGuidAndId(Guid guid, int id)
        {
            var result       = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account");
            var clientEntity = _lookupService.GetClientByGuid(guid);

            if (clientEntity == null)
            {
                _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid));
            }
            else
            {
                var locationEntity = _lookupService.GetLocationByIdAndClientId(new List <string> {
                    clientEntity.Id.ToString()
                }, id);
                var location = new LocationDTO();
                if (locationEntity != null)
                {
                    location       = LocationMapper.ToDataTransferObject(locationEntity);
                    location.Areas = _lookupService.GetAreasByLocationId(location.Id).Select(x => AreaMapper.ToDataTransferObject(x)).ToList();
                }
                result = Request.CreateResponse(HttpStatusCode.OK, location);
            }
            result.Headers.Add("Access-Control-Allow-Origin", "*");
            return(result);
        }
Ejemplo n.º 18
0
        public async Task <List <LocationDTO> > Buscar(LocationDTO location)
        {
            try
            {
                if (location.ImageId == 0 || location.ImageId == null)
                {
                    return(null);
                }
                location.IsSearch = true;
                await AddLocation(location);

                Image image = await imageRepo.GetById((int)location.ImageId);

                List <Image> images = await BuscarParecidos(image);

                List <LocationDTO> result = new List <LocationDTO>();
                foreach (Image i in images)
                {
                    if (i.Id != location.ImageId)
                    {
                        var loc = locationRepo.FindBy(x => x.ImageId == i.Id).Result.FirstOrDefault();
                        if (loc != null && !loc.IsSearch && loc.UserId != location.UserId && getDistance(loc.toDto(), location) < 3000)
                        {
                            result.Add(loc.toDto());
                        }
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 19
0
        public double getDistance(LocationDTO loc1, LocationDTO loc2)
        {
            var coor1 = getPoints(loc1.Coordinates).First();
            var coor2 = getPoints(loc2.Coordinates).First();

            return(coor1.GetDistanceTo(coor2));
        }
Ejemplo n.º 20
0
        private void initDummyProjects()
        {
            Content = null;
            Content = new ObservableCollection <ProjectViewModel>();

            var _location = new LocationDTO {
                Id = 1, City = "Copenhagen", Country = "Denmark"
            };

            var _dummyProjects = new List <ProjectDTO>();

            for (int i = 0; i < 20; i++)
            {
                _dummyProjects.Add(new ProjectDTO {
                    Title = "Project " + i, Location = _location, Description = "Description " + i, Category = new CategoryDTO {
                        Name = "Programming"
                    }
                });
            }

            foreach (var p in _dummyProjects)
            {
                Content.Add(new ProjectViewModel(p));
            }
        }
        public async Task <bool> ChangeLocationAsync(Worker worker, LocationDTO newLocation)
        {
            if (worker.StatusId == (int)WorkerStatus.Offline)
            {
                return(false);
            }

            var locationHistory = Mapper.Map <LocationDTO, WorkerLocationHistory>(newLocation);

            locationHistory.TimeStamp = DateTime.Now;
            locationHistory.WorkerId  = worker.Id;

            await db.WorkersLocationHistory.CreateAsync(locationHistory);

            var lastLocation = await db.WorkersLastLocation.FindByIdAsync(worker.Id);

            if (lastLocation == null)
            {
                await db.WorkersLastLocation.CreateAsync(new WorkerLastLocation()
                {
                    Latitude  = newLocation.Latitude,
                    Longitude = newLocation.Longitude,
                    Worker    = worker
                });
            }
            else
            {
                lastLocation.Latitude  = newLocation.Latitude;
                lastLocation.Longitude = newLocation.Longitude;
                await db.WorkersLastLocation.UpdateAsync(lastLocation);
            }

            return(true);
        }
        private void GroupBoxToLocation()
        {
            LocationDTO location = GetCurrentItem();

            location.Name    = textBoxLocationsName.Text;
            location.Scenery = textBoxLocationsScenery.Text;
            location.ZipCode = textBoxLocationsZipcode.Text;

            if (!string.IsNullOrWhiteSpace(textBoxLocationsLongitude.Text))
            {
                location.Longitude = Convert.ToDecimal(textBoxLocationsLongitude.Text);
            }
            else
            {
                location.Longitude = null;
            }

            if (!string.IsNullOrWhiteSpace(textBoxLocationsLatitude.Text))
            {
                location.Latitude = Convert.ToDecimal(textBoxLocationsLatitude.Text);
            }
            else
            {
                location.Latitude = null;
            }
        }
Ejemplo n.º 23
0
        //Delete location by id
        public static bool Delete(int Id)
        {
            GlobalSettings.LoggedInClientId = LocationService.GetById(Id).ClientId;
            int PartnerId = ClientService.GetById(Convert.ToInt32(GlobalSettings.LoggedInClientId)).PartnerId;

            GlobalSettings.LoggedInPartnerId = PartnerId;

            bool IsExists = IsChildEntityExist(Id);

            try
            {
                if (IsExists != true)
                {
                    LocationDTO LocationDTO = new LocationDTO();
                    LocationDTO = GetById(Id);
                    UnitOfWork uow = new UnitOfWork();
                    uow.LocationRepo.Delete(Id);
                    uow.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
        public static async Task <List <List <double> > > GenerateBuffer(int range, LocationDTO locationDTO)
        {
            Feature feat = new Feature()
            {
                Geometry = new Geometry()
                {
                    Coordinates = new List <double>()
                    {
                        locationDTO.Longitude, locationDTO.Latitude
                    }
                }
            };

            RootObject root = new RootObject()
            {
                Geometries = new Geometries
                {
                    Feature = new List <Feature>()
                    {
                        feat
                    }
                },
                Distances = new List <int>()
                {
                    range
                }
            };


            List <List <double> > coords = await BufferService.GetBuffer(JsonConvert.SerializeObject(root));

            return(coords);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Put(int id, LocationDTO location)
        {
            if (id != location.Id)
            {
                return(BadRequest());
            }

            var _location = await _context.Locations
                            .Include(p => p.Campaign)
                            .Include(p => p.Faction)
                            .FirstOrDefaultAsync(p => p.Id == id);

            _location.Name     = location.Name;
            _location.Campaign = await _context.Campaigns.FirstOrDefaultAsync(p => p.Id == location.CampaignId);

            _location.Faction = await _context.Factions.FirstOrDefaultAsync(p => p.Id == location.FactionId);

            _location.Description = location.Description;
            _location.Longitude   = location.Longitude;
            _location.Latitude    = location.Latitude;
            _location.Status      = location.Status;

            _context.Locations.Update(_location);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 26
0
        public bool TestChangeLocationOfEvent()
        {
            using (var scope = services.CreateScope())
            {
                var eventService = scope.ServiceProvider.GetService <IEventService>();
                var eventRepo    = scope.ServiceProvider.GetService <IRepository <Event> >();

                EventDTO eventDTO = new EventDTO()
                {
                    Description = "Sample description", StartTime = DateTime.Now, EndTime = DateTime.Now.AddDays(2), EstimatedBudget = 300, Name = "Super name", EventTypeId = 2, LocationId = 2
                };
                int newEventId = eventService.CreateEvent(eventDTO);

                int oldLocationId = eventRepo.Query().Include(e => e.Location).Where(e => e.Id == newEventId).FirstOrDefault().LocationId;

                LocationDTO locationDTO = new LocationDTO()
                {
                    Address = "Addresa mea", Capacity = 10, Name = "O noua locatie", RentFee = 1
                };
                eventService.ChangeEventLocation(locationDTO, newEventId);

                int newLocationId = eventRepo.Query().Include(e => e.Location).Where(e => e.Id == newEventId).FirstOrDefault().LocationId;

                return(newLocationId > oldLocationId);
            }
        }
Ejemplo n.º 27
0
        static async Task Main()
        {
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
            locationProvider           = new LocationTracker();
            var min = new LocationDTO {
                Longitude = -10, Latitude = -10
            };
            var max = new LocationDTO {
                Longitude = 10, Latitude = 10
            };

            locationReporter = new LocationReporter(Mapper.Map(min), Mapper.Map(max));

            locationReporter.Subscribe(locationProvider,
                                       Console.WriteLine,
                                       (x) => Console.WriteLine(x.Message),
                                       (x) => { },
                                       TurnOffAll,
                                       TurnOnAll
                                       );
            deviceProvider = new DeviceTracker();
            deviceReporter = new DeviceReporter();
            deviceReporter.Subscribe(deviceProvider,
                                     Console.WriteLine,
                                     (x) => Console.WriteLine(x.Message),
                                     (x) => { _ = CurrentConnection.SendAsync(MessageParser.CreateMessage("OnNext", x, x.GetType().Name)); }
                                     );
            await CreateServer();
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> CreateLocation(LocationDTO locationDTO)
        {
            var location = _mapper.Map <LocationDTO, Location>(locationDTO);
            await _locationRepository.Add(location);

            return(CreatedAtAction(nameof(GetLocation), new { id = location.LocationId }, location));
        }
        public async Task <Object> GetResponseFromService(LocationDTO model)
        {
            string timeFormatForUrl = DateTime.Now.ToString("yyyyMMdd");

            LocationEntity location = new LocationEntity();

            location.latitude  = model.latitude;
            location.longitude = model.longitude;

            var loc = new LocationDTO();

            loc.latitude  = model.latitude;
            loc.longitude = model.longitude;

            await _context.Locations.AddAsync(location);

            await _context.SaveChangesAsync();

            await _hubContext.Clients.All.SendAsync("OnLocation", loc);

            HttpClient httpClient    = new HttpClient();
            string     rawStringJSON = await httpClient.GetStringAsync($"{_myConfig.foursquare}{ model.latitude.Value.ToString(CultureInfo.InvariantCulture)},{ model.longitude.Value.ToString(CultureInfo.InvariantCulture)}&v={ timeFormatForUrl}&limit=10");

            Object deserializedJSON = JsonConvert.DeserializeObject(rawStringJSON);

            return(deserializedJSON);
        }
Ejemplo n.º 30
0
        public void LocationsRepositoryTest()
        {
            //Container initialization
            string connectionString = "";

            var container = new WindsorContainer();

            container.Register(
                Component.For <ILocationsRepository>()
                .ImplementedBy <PostgresqLocationsRepository>()
                .DependsOn(Dependency.OnValue("connectionString", connectionString))
                .Named("pgrslocrepo"));

            //Test
            ILocationsRepository locationRepository = container.Resolve <ILocationsRepository>();

            //Category Test
            string newCategory = "aggghtldon";

            Assert.IsFalse(locationRepository.DeleteCategory(newCategory));
            Assert.IsTrue(locationRepository.InsertCategory(newCategory, null) != -1);
            Assert.IsTrue(locationRepository.DeleteCategory(newCategory));

            //Location Test
            var enumerator = locationRepository.GetCategories().GetEnumerator();

            enumerator.MoveNext(); int pCatId = locationRepository.GetCategoryByName(enumerator.Current.Key).Id;
            var userId = "-a1";

            var loc = new Location
            {
                UserId = userId,
                PCatId = pCatId,
                Name   = "TestLocation",
                Lat    = "11",
                Lng    = "12",
                Desc   = "A description",
                Type   = "POI"
            };
            int id = locationRepository.Insert(loc);

            Assert.AreEqual(locationRepository.GetOwnerId(id), userId);
            LocationDTO locdto1 = locationRepository.GetById(id);

            loc.Desc = "New description";
            Assert.IsTrue(locationRepository.Update(id, loc));
            Assert.IsFalse(locationRepository.Update(-1, loc));
            LocationDTO locdto2 = locationRepository.GetById(id);

            Assert.AreNotEqual(locdto1, locdto2);
            var locs = new List <LocationDTO>(locationRepository.GetByUserId(userId));

            Assert.IsTrue(locs.Count == 1);
            Assert.AreEqual(locs[0], locdto2);
            Assert.IsTrue(locationRepository.DeleteById(id));
            var newLocs = new List <LocationDTO>(locationRepository.GetByUserId(userId));

            Assert.IsTrue(newLocs.Count == 0);
            Assert.IsNull(locationRepository.GetById(id));
        }
 private static bool AssertLocationsAreSame(LocationDTO newLoc, long locId, LocationDTO locRet)
 {
     return (newLoc.Identifier == locRet.Identifier) &&
       (newLoc.Latitude == locRet.Latitude) &&
       (newLoc.Longitude == locRet.Longitude) &&
     (newLoc.LocationTypeName.ToUpper() == locRet.LocationTypeName.ToUpper()) &&
      (locId == locRet.LocationId) &&
     (newLoc.LocationName == locRet.LocationName) &&
     (newLoc.LocationPath == locRet.LocationPath) &&
     (newLoc.UtcOffset == locRet.UtcOffset) &&
     (newLoc.ExtendedAttributes != null && locRet.ExtendedAttributes != null ?
        newLoc.ExtendedAttributes.Count == locRet.ExtendedAttributes.Count : true);
 }
        public LocationDTO CreateLocationDTO(string identifier, string locName)
        {
            //Create a new location instance:

            string locTypeName = "Hydrology Station";

            //Uncomment the following for MWS
            //string locTypeName = "Telemetered Hydrology Station";
            //Uncomment the following for USGS
            //string locTypeName = "Land (LA)";

            //ToDo: we can add attributes if the custom tables are implemented:
            Dictionary<string, object> attrDic = null;
            //E.g.:
            //Dictionary<string, object> attrDic = new Dictionary<string, object>();
            //attrDic["LoggerType"] = "Sonic";
            //attrDic["Number2_1Single"] = 2.3;
            //Location_Extension table:
            //attrDic["Contact"] = "Bill Chen";
            //attrDic["LoggerNumber"] = 21;
            //attrDic["INTNOTNULL"] = 1;

            float lat = -19.67F;
            float lon = 55.07F;
            float utcOffset = locUTCOff_hrs;

            string locPath = textboxRootLocationFolder.Text; //Default: "All Locations"

            LocationDTO newLoc = new LocationDTO()
            {
                Identifier = identifier,
                LocationName = locName,
                LocationTypeName = locTypeName,
                ExtendedAttributes = attrDic,
                Latitude = lat,
                Longitude = lon,
                UtcOffset = utcOffset,
                LocationPath = locPath
            };
            return newLoc;
        }
Ejemplo n.º 33
0
 public CarrierMovementDTO(LocationDTO departureLocation, LocationDTO arrivalLocation)
 {
     this.departureLocation = departureLocation;
     this.arrivalLocation = arrivalLocation;
 }