/// <summary> /// <see cref="IDgtAppService"/> /// </summary> /// <returns><see cref="IDgtAppService"/></returns> public DriverDTO AddNewDriver(DriverDTO driverDTO) { if (driverDTO == null) { throw new ArgumentNullException("driverDTO"); } // Check driver identifier is unique var identifierSpec = DriverSpecifications.WithIdentifier(driverDTO.Identifier); var repeatedIdentifierDriver = _driverRepository.AllMatching(identifierSpec); if (repeatedIdentifierDriver != null && repeatedIdentifierDriver.Any()) { throw new InvalidOperationException(String.Format(CommonMessages.exception_ItemAlreadyExistsWithProperty, Names.Driver, Names.Identifier, driverDTO.Identifier)); } // Cast dto to driver and save var driver = MaterializeDriverFromDto(driverDTO); // Set initial points for new drivers driver.SetInitialPoints(); driver.GenerateNewIdentity(); driver.CreatedDate = DateTime.Now; driver.Validate(); _driverRepository.Add(driver); _driverRepository.UnitOfWork.Commit(); return(driver.ProjectedAs <DriverDTO>()); }
/// <summary> /// <see cref="IDgtAppService"/> /// </summary> /// <returns><see cref="IDgtAppService"/></returns> public DriverDTO GetDriverByNifNie(string identifier) { if (String.IsNullOrEmpty(identifier)) { throw new ArgumentNullException("identifier"); } var identifierSpec = DriverSpecifications.WithIdentifier(identifier); var result = _driverRepository.AllMatching(identifierSpec); if (result != null && result.Any()) { return(result.First().ProjectedAs <DriverDTO>()); } else { return(null); } }
/// <summary> /// <see cref="IDgtAppService"/> /// </summary> /// <returns><see cref="IDgtAppService"/></returns> public List <DriverDTO> SearchDrivers(string filter) { if (String.IsNullOrEmpty(filter)) { throw new ArgumentNullException("filter"); } var fulltextSpec = DriverSpecifications.FullText(filter); var result = _driverRepository.AllMatching(fulltextSpec); if (result != null && result.Any()) { return(result.OrderByDescending(i => i.CreatedDate).ProjectedAsCollection <DriverDTO>()); } else { return(null); } }