public void SearchForFiles_WithLocations_AllMatch() { var locationRepository = new LocationRepository(); var locationDto = new CreateLocationDto("test 1", "", testLibrary.LibraryId, -1, -1); var location1Id = locationRepository.CreateLocation(locationDto); var location1 = locationRepository.GetLocation(location1Id); locationDto = new CreateLocationDto("test 2", "", testLibrary.LibraryId, -1, -1); var location2Id = locationRepository.CreateLocation(locationDto); var location2 = locationRepository.GetLocation(location2Id); var fileId = repository.CreateMediaFile(new CreateMediaFileDto("", MediaFileType.VIDEO_TYPE, "")); var file = repository.GetMediaFile(fileId); repository.AddLocationToMediaFile(file, location1).ConfigureAwait(false); repository.AddLocationToMediaFile(file, location2).ConfigureAwait(false); var queries = new List <IMediaFileSearchQueryGenerator>(); queries.Add(new MediaFileWithLocationsGenerator("[\"test 1\", \"test 2\"]")); var actualFiles = repository.SearchForFiles(GetFirstPage(), queries).Result.Results; var expectedFiles = new List <MediaFile> { file }; CollectionAssert.AreEquivalent(expectedFiles, actualFiles); }
public async Task <ActionResult> AddLocation([FromBody] CreateLocationDto location) { if (!await _deviceRepository.ExistByPhoneId(location.DeviceId)) { return(NotFound("Wrong device ID.")); } return(CreatedAtAction(nameof(AddLocation), await _locationService.CreateAsync(location))); }
public long CreateLocation(CreateLocationDto location) { using (var db = DataAccessUtil.CreateSqlConnection()) { db.Open(); var command = GetCreateLocationCommand(db, location, UniqueIdUtil.GenerateUniqueId(), false); command.ExecuteNonQuery(); return(QueryUtil.GetLastInsertedPrimaryKey(db)); } }
private SqliteCommand GetCreateLocationCommand(SqliteConnection db, CreateLocationDto location, string guid, bool ignoreDuplicates) { var ignoreClause = ignoreDuplicates ? "OR IGNORE" : ""; var command = new SqliteCommand($"INSERT {ignoreClause} INTO location(name, description, library_id, deleted, deletion_due_to_cascade, publisher_id, cover_file_id, unique_id) VALUES (@Name, @Description, @LibraryId, false, false, @PublisherId, @CoverId, @UniqueId)", db); command.Parameters.AddWithValue("@Name", location.Name); command.Parameters.AddWithValue("@Description", location.Description); command.Parameters.AddWithValue("@LibraryId", location.LibraryId); command.Parameters.AddWithValue("@PublisherId", QueryUtil.GetNullableIdForStorage(location.PublisherId)); command.Parameters.AddWithValue("@CoverId", QueryUtil.GetNullableIdForStorage(location.CoverFileId)); command.Parameters.AddWithValue("@UniqueId", guid); return(command); }
public async Task <ActionResult <LocationDto> > PostAsync(CreateLocationDto createLocationDto) { // Note: check if the location with same data exists. if (await _locationsRepo.GetByAsync(createLocationDto.StreetName, createLocationDto.Building, createLocationDto.Flat) != null) { return(StatusCode(StatusCodes.Status409Conflict, "Location with the same data already exist.")); } var location = _mapper.Map <Location>(createLocationDto); await _locationsRepo.AddAsync(location); var locationDto = _mapper.Map <LocationDto>(location); return(CreatedAtAction("Get", new { locationId = location.Id }, locationDto)); }
public void TestUpdateLocation_ShouldNotUpdateDifferentLocation() { var locationDto = new CreateLocationDto("Test library", "test desc", testLibrary.LibraryId, -1, -1); var locationToUpdateId = repository.CreateLocation(locationDto); var locationNotUpdatedId = repository.CreateLocation(locationDto); var locationToUpdate = repository.GetLocation(locationToUpdateId); locationToUpdate.Description += "1"; repository.UpdateLocation(locationToUpdate); var locationToNotUpdate = repository.GetLocation(locationNotUpdatedId); Assert.AreNotEqual(locationToUpdate.Description, locationToNotUpdate.Description); }
private long CreateNewLocation(Library library = null, Publisher publisher = null) { long publisherId = -1; if (publisher != null) { publisherId = publisher.PublisherId; } if (library == null) { library = testLibrary; } var locationToCreate = new CreateLocationDto("Test library", "test desc", library.LibraryId, publisherId, -1); return(repository.CreateLocation(locationToCreate)); }
public void TestUpdateLocation() { var locationToCreate = new CreateLocationDto("Test library", "test desc", testLibrary.LibraryId, -1, -1); var locationId = repository.CreateLocation(locationToCreate); var locationRetrieved = repository.GetLocation(locationId); locationRetrieved.Description += "1"; locationRetrieved.Name += "2"; repository.UpdateLocation(locationRetrieved); var updatedLocationRetrieved = repository.GetLocation(locationId); Assert.AreEqual(locationRetrieved.LocationId, updatedLocationRetrieved.LocationId); Assert.AreEqual(locationRetrieved.Name, updatedLocationRetrieved.Name); Assert.AreEqual(locationRetrieved.Description, updatedLocationRetrieved.Description); Assert.AreEqual(locationRetrieved.LibraryId, updatedLocationRetrieved.LibraryId); Assert.AreEqual(locationRetrieved.PublisherId, updatedLocationRetrieved.PublisherId); CollectionAssert.AreEquivalent(new List <Location>() { updatedLocationRetrieved }, repository.GetLocations(GetFirstPage()).Result.Results); }
public Location CreateAndRetrieveLocation(CreateLocationDto dto) { long locationId = CreateLocation(dto); return(new Location(locationId, dto)); }
public long CreateLocation(CreateLocationDto dto) { return(locationRepository.CreateLocation(dto)); }
public IActionResult Post([FromBody] CreateLocationDto model) => _mapper.Map <LocationInsertModel>(model) .Map(_commandRepository.Insert) .Map(x => AllOk(new { id = x })) .Reduce(_ => BadRequest(), error => error is ArgumentNotSet) .Reduce(_ => InternalServerError(), x => _logger.LogError(x.ToString()));