Map() публичный Метод

public Map ( object source, Type, sourceType, Type, destinationType ) : object
source object
sourceType Type,
destinationType Type,
Результат object
 public async Task <IActionResult> GetMessagesByCustomer(Guid customerId)
 {
     try
     {
         var result = _mappingService.Map <DutyMessage, DutyMessageDto>(await _repository.GetByCustomerId(customerId));
         return(Ok(result));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Пример #2
0
        public void WhenMappingLevelAggregation()
        {
            MappingService mappingService    = new MappingService(null);
            var            searchResultItem1 = new ApprenticeshipSearchResultsItem
            {
                StandardId = "101",
                Title      = "Standard 1"
            };

            var resultList = new List <ApprenticeshipSearchResultsItem> {
                searchResultItem1
            };
            var levels = new Dictionary <int, long?> {
                { 2, 3L }, { 3, 38L }, { 4, 380L }
            };
            var model = new ApprenticeshipSearchResponse {
                TotalResults = 1234L, SearchTerm = "apprenticeship", Results = resultList, AggregationLevel = levels, SelectedLevels = new List <int> {
                    2
                }
            };

            var mappedResult = mappingService.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(model);

            mappedResult.AggregationLevel.Count().Should().Be(3);
            mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "2")?.Checked.Should().BeTrue();
            mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "3")?.Checked.Should().BeFalse();

            mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "4")?.Count.Should().Be(380);
        }
Пример #3
0
        public UserDto GetUser(Guid userKey, string userProfileOriginator)
        {
            UserDto userDto = null;

            Execute(uow =>
            {
                var cacheKey = CacheKeyHelper.GetCacheKey <UserDto>(userKey);
                userDto      = uow.Cache.GetCachedItem <UserDto>(cacheKey);
                if (userDto != null)
                {
                    userDto.UserProfile = GetUserProfile(uow, userDto.Key, userProfileOriginator);
                    return;
                }

                var user = uow.Store.FirstOrDefault <User>(x => x.Key == userKey);
                if (user == null)
                {
                    return;
                }
                userDto             = MappingService.Map <UserDto>(user);
                userDto.UserProfile = GetUserProfile(uow, userDto.Key, userProfileOriginator);
                CacheUserDto(uow, userDto);
            });

            return(userDto);
        }
 public void ServiceLoadsFromFile()
 {
     var loader = new Mock<ILoader>();
     var subject = new MappingService(loader.Object, "tracks");
     var result = subject.Map(new Mapping());
     loader.Verify( l => l.Load(It.IsAny<string>()));
 }
Пример #5
0
        private Response MapUsing(MappingService mappingService)
        {
            var result = mappingService.Map(Mapping.From(this.Bind<SerializableMapping>()));

            var viewmodel = new SerializableMapping();
            return Response.AsJson(result.To(viewmodel));
        }
Пример #6
0
        CreateUser(UserUpdateDto userUpdateDto, ICollection <UserProfileDto> userProfiles)
        {
            var     updateResultType = UserUpdateResultType.Unknown;
            UserDto userDto          = null;
            var     result           = ExecuteWithProcessResult(uow =>
            {
                userDto = GetUser(uow, null, userUpdateDto.Email.Address);
                if (userDto != null)
                {
                    updateResultType = UserUpdateResultType.EmailExists;
                    return;
                }

                var user = uow.Store.Add(MappingService.Map <User>(userUpdateDto));
                if (user == null)
                {
                    updateResultType = UserUpdateResultType.GeneralFailure;
                    throw new Exception("Failed to create User.");
                }

                userDto = MappingService.Map <UserDto>(user);
                CacheUserDto(uow, userDto);
                foreach (var userProfileDto in userProfiles)
                {
                    userProfileDto.UserKey = user.Key;
                    var userProfile        = MappingService.Map <UserProfile>(userProfileDto);
                    uow.Store.Add(userProfile);
                    var cacheKey = GetUserProfileCacheKey(userProfileDto.UserKey, userProfileDto.UserProfileOriginator);
                    uow.Cache.SetCachedItemAsync(cacheKey, userProfileDto).Wait();
                }
            });

            return(result, userDto, updateResultType);
        }
Пример #7
0
        public void TestMapper_Enumerable_Found()
        {
            var services = new ServiceCollection();

            services.AddScoped <IMapper <SourceModel, DestinationModel>, TestMapper>();
            var serviceProvider = services.BuildServiceProvider();

            var mappingService = new MappingService(serviceProvider);

            var sources = new List <SourceModel>
            {
                new SourceModel
                {
                    Value = "value",
                },
                new SourceModel
                {
                    Value = "other",
                },
            };
            var destinations = mappingService.Map <SourceModel, DestinationModel>(sources)
                               .ToList();

            Assert.NotNull(destinations);
            Assert.Equal(2, destinations.Count);
            Assert.IsType <DestinationModel>(destinations[0]);
            Assert.IsType <DestinationModel>(destinations[1]);
            Assert.Equal("value", destinations[0].Value);
            Assert.Equal("other", destinations[1].Value);
        }
Пример #8
0
        protected UserDto UpdateUser(IdentityUow uow, Guid userKey, Action <User> updateAction)
        {
            var user    = uow.Store.UpdatePropertiesOnly(x => x.Key == userKey, updateAction);
            var userDto = MappingService.Map <UserDto>(user);

            CacheUserDto(uow, userDto);
            return(userDto);
        }
Пример #9
0
        public void ThrowArgumentNullException_WhenObjectFromIsNull()
        {
            // Arrange
            var postService = new MappingService();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => postService.Map <Type>(null));
        }
Пример #10
0
 private void CollectScopeAssociatedInfo(IdentityUow uow, ScopeDto scopeDto)
 {
     scopeDto.ScopeClaims = uow.Store.List <ScopeClaim>(set => set.Where(x => x.ScopeKey == scopeDto.Key))
                            .Select(x => MappingService.Map <ScopeClaimDto>(x))
                            .ToList();
     scopeDto.ScopeSecrets = uow.Store.List <ScopeSecret>(set => set.Where(x => x.ScopeKey == scopeDto.Key))
                             .Select(x => MappingService.Map <ScopeSecretDto>(x))
                             .ToList();
 }
Пример #11
0
        public async Task <Seller> CreateSeller(Seller seller)
        {
            return(await Task.Run(() =>
            {
                var temp = MappingService.Map <Domain.Seller>(seller);
                var result = MappingService.Map <Seller>(SellerService.Create(temp));

                return result;
            }));
        }
Пример #12
0
        public async Task <Customer> CreateCustomer([FromBody] Customer customer)
        {
            return(await Task.Run(() =>
            {
                var temp = MappingService.Map <Domain.Customer>(customer);
                var result = MappingService.Map <Customer>(CustomerService.Create(temp));

                return result;
            }));
        }
Пример #13
0
        public async Task <Order> CreateCustomer([FromBody] Order order,
                                                 [FromBody] int customerId, [FromBody] int sellerId)
        {
            return(await Task.Run(() =>
            {
                var temp = MappingService.Map <Domain.Order>(order);
                var result = MappingService.Map <Order>(OrderService.Create(temp, customerId, sellerId));

                return result;
            }));
        }
        public async Task <CargoAM> GetCargo(int cargoId)
        {
            var domainCargo = await DomainCargoService.Get(cargoId);

            if (domainCargo == null)
            {
                return(null);
            }

            var result = MappingService.Map(domainCargo, new CargoAM());

            return(result);
        }
Пример #15
0
        public MappingModule()
        {
            var mappingService = new MappingService(new LastFmLoader(), "tracks");
            Get["/mbid/{Mbid}"] = req =>
                                  {
                                      var result = mappingService.Map(new Mapping { MusicBrainz = new MusicBrainzId(req.Mbid) });

                                      return((Mapping) result).SevenDigital.ToString();
                                  };

            Get["/7did/{Id}"] = req =>
            {
                                    var result = mappingService.Map(new Mapping { SevenDigital = new SevenDigitalId(req.Id) });
                                    return
                                      Response.AsRedirect(
                                          "http://www.last.fm/mbid/"
                                          +
                                          ((Mapping)result).MusicBrainz.ToString
                                              ());

                                };
            Get["/status"] = _ => DateTime.Now.ToString();
        }
Пример #16
0
        public void TestMapper_NotFound()
        {
            var services        = new ServiceCollection();
            var serviceProvider = services.BuildServiceProvider();

            var mappingService = new MappingService(serviceProvider);

            var source = new SourceModel
            {
                Value = "value",
            };

            Assert.Throws <MapperNotFoundException>(() => mappingService.Map <SourceModel, DestinationModel>(source));
        }
Пример #17
0
        public void TestMapper_Enumerable_Null()
        {
            var services = new ServiceCollection();

            services.AddScoped <IMapper <SourceModel, DestinationModel>, TestMapper>();
            var serviceProvider = services.BuildServiceProvider();

            var mappingService = new MappingService(serviceProvider);

            List <SourceModel> sources = null;
            var destinations           = mappingService.Map <SourceModel, DestinationModel>(sources);

            Assert.Null(destinations);
        }
Пример #18
0
        public async Task <Order> Update(int id, [FromBody] Order order)
        {
            return(await Task.Run(() =>
            {
                if (id == order.Id)
                {
                    var temp = MappingService.Map <Domain.Order>(order);
                    var result = MappingService.Map <Order>(OrderService.Update(temp));
                    return result;
                }

                return order;
            }));
        }
Пример #19
0
        public async Task <Seller> Update(int id, [FromBody] Seller seller)
        {
            return(await Task.Run(() =>
            {
                if (id == seller.Id)
                {
                    var temp = MappingService.Map <Domain.Seller>(seller);
                    var result = MappingService.Map <Seller>(SellerService.Update(temp));
                    return result;
                }

                return seller;
            }));
        }
Пример #20
0
        public async Task <Customer> Update(int id, [FromBody] Customer customer)
        {
            return(await Task.Run(() =>
            {
                if (id == customer.Id)
                {
                    var temp = MappingService.Map <Domain.Customer>(customer);
                    var result = MappingService.Map <Customer>(CustomerService.Update(temp));
                    return result;
                }

                return customer;
            }));
        }
Пример #21
0
 private void CollectClientAssociatedInfo(IdentityUow uow, ClientDto clientDto)
 {
     clientDto.AllowedScopes = uow.Store
                               .List <ClientScope>(set => set.Where(x => x.ClientKey == clientDto.Key))
                               .Select(x => MappingService.Map <ClientScopeDto>(x))
                               .ToList();
     clientDto.ClientSecrets = uow.Store
                               .List <ClientSecret>(set => set.Where(x => x.ClientKey == clientDto.Key))
                               .Select(x => MappingService.Map <ClientSecretDto>(x))
                               .ToList();
     clientDto.RedirectUris = uow.Store
                              .List <ClientRedirectUri>(set => set.Where(x => x.ClientKey == clientDto.Key))
                              .Select(x => MappingService.Map <ClientRedirectUriDto>(x))
                              .ToList();
 }
Пример #22
0
        public UserDto SetVerificationCode(string email, VerificationPurpose verificationPurpose,
                                           string hashedVerificationCode, DateTimeOffset timeVerificationCodeExpires)
        {
            UserDto userDto = null;

            Execute(uow =>
            {
                var user = uow.Store.UpdatePropertiesOnly <User>(x => x.Email.Address == email,
                                                                 x => x.WithVerificationCode(verificationPurpose, hashedVerificationCode,
                                                                                             timeVerificationCodeExpires));
                userDto = MappingService.Map <UserDto>(user);
                CacheUserDto(uow, userDto);
            });

            return(userDto);
        }
        public void ShouldMappFromFrameworkFrameworkViewModelWhenFrameworkIsEmpty()
        {
            var service   = new MappingService(Mock.Of <ILog>());
            var framework = new GetFrameworkResponse
            {
                Framework = new Framework
                {
                    Title = "title1",
                }
            };

            var viewModel = service.Map <GetFrameworkResponse, FrameworkViewModel>(framework);

            viewModel.ExpiryDateString.Should().BeNull();
            viewModel.Should().NotBeNull();
        }
Пример #24
0
        public ActionResult Search()
        {
            var countries = this.countryService.GetAllCountries()
                            .Select(x => MappingService.Map <CountryViewModel>(x))
                            .Select(c => new SelectListItem()
            {
                Text = c.Name, Value = c.Id.ToString()
            })
                            .ToList();

            var viewModel = new SearchViewModel()
            {
                Countries = countries
            };

            return(View(viewModel));
        }
Пример #25
0
        private ClientDto AddOrUpdateClient(IdentityUow uow, ClientDto clientDto)
        {
            var client = MappingService.Map <Client>(clientDto).AsNewEntity();

            client = uow.Store.AddOrUpdate(client, x => x.ClientId == clientDto.ClientId);

            if (clientDto.AllowedScopes != null)
            {
                foreach (var allowedScopeDto in clientDto.AllowedScopes)
                {
                    var allowedScope = MappingService.Map <ClientScope>(allowedScopeDto).WithClient(client);
                    uow.Store.AddOrUpdate(allowedScope,
                                          x => x.ClientKey == client.Key && x.Scope == allowedScopeDto.Scope);
                }
            }

            if (clientDto.ClientSecrets != null)
            {
                foreach (var clientSecretDto in clientDto.ClientSecrets)
                {
                    var clientSecret = MappingService.Map <ClientSecret>(clientSecretDto).WithClient(client);
                    uow.Store.AddOrUpdate(clientSecret,
                                          x => x.ClientKey == client.Key && x.Value == clientSecretDto.Value);
                }
            }

            if (clientDto.RedirectUris != null)
            {
                foreach (var redirectUriDto in clientDto.RedirectUris)
                {
                    var redirectUri = MappingService.Map <ClientRedirectUri>(redirectUriDto).WithClient(client);
                    uow.Store.AddOrUpdate(redirectUri,
                                          x => x.ClientKey == client.Key && x.Uri == redirectUriDto.Uri);
                }
            }

            var updatedClientDto = MappingService.Map <ClientDto>(client);

            CollectClientAssociatedInfo(uow, updatedClientDto);

            var cacheKey = CacheKeyHelper.GetCacheKey <ClientDto>(client.ClientId);

            uow.Cache.SetCachedItemAsync(cacheKey, updatedClientDto).Wait();
            return(updatedClientDto);
        }
Пример #26
0
        public ActionResult AddCity()
        {
            var countries = this.countryServices.GetAllCountries()
                            .AsQueryable()
                            .Select(x => MappingService.Map <CountryViewModel>(x))
                            .Select(c => new SelectListItem()
            {
                Text = c.Name, Value = c.Id.ToString()
            })
                            .ToList();

            var viewModel = new AddCityViewModel()
            {
                Countries = countries
            };

            return(PartialView("_AddCity", viewModel));
        }
Пример #27
0
        public MemberUpdatedEvent CreateOrUpdateMember(IBasicRequestKey request, MemberUpdateDto dto,
                                                       Func <MemberUpdateDto, UserProfileDto> createUserProfileDto)
        {
            var member = MappingService.Map <Member>(dto).AsNewEntity();

            if (dto.Roles == null)
            {
                dto.Roles = new List <RoleDto>();
            }
            if (!dto.Roles.Any())
            {
                dto.Roles.Add(new RoleDto {
                    RoleType = RoleTypeName.BasicMember
                });
            }
            foreach (var roleDto in dto.Roles)
            {
                roleDto.UserKey = member.Key;
            }

            var roles = dto.Roles.Select(x => MappingService.Map <Role>(x).AsNewEntity()).ToList();

            var updatedEvent = new MemberUpdatedEvent().LinkTo(request);

            updatedEvent.WithProcessResult(ExecuteWithProcessResult(uow =>
            {
                var updatedMember = uow.Store.AddOrUpdate(member,
                                                          x => x.Email.Address == member.Email.Address ||
                                                          x.Mobile.LocalNumberWithAreaCodeInDigits == member.Mobile.LocalNumberWithAreaCodeInDigits ||
                                                          x.Username == member.Username
                                                          );
                var updatedMemberDto   = MappingService.Map <MemberUpdateDto>(updatedMember);
                updatedMemberDto.Roles = new List <RoleDto>();
                uow.Store.Delete <Role>(x => x.UserKey == updatedMember.Key);
                foreach (var role in roles)
                {
                    var updatedRole = uow.Store.Add(role);
                    updatedMemberDto.Roles.Add(MappingService.Map <RoleDto>(updatedRole));
                }
                updatedEvent.WithMember(updatedMemberDto)
                .WithUserProfile(createUserProfileDto?.Invoke(updatedMemberDto));
            }));
            return(updatedEvent);
        }
Пример #28
0
        public void TestMapper_Found()
        {
            var services = new ServiceCollection();

            services.AddScoped <IMapper <SourceModel, DestinationModel>, TestMapper>();
            var serviceProvider = services.BuildServiceProvider();

            var mappingService = new MappingService(serviceProvider);

            var source = new SourceModel
            {
                Value = "value",
            };
            var destination = mappingService.Map <SourceModel, DestinationModel>(source);

            Assert.NotNull(destination);
            Assert.IsType <DestinationModel>(destination);
            Assert.Equal("value", destination.Value);
        }
        public void ShouldMapStandardProvidersItemToViewModel()
        {
            var service = new MappingService(Mock.Of <ILog>());

            var response = new ProviderSearchResultItem
            {
                Address = new Address {
                    Address1 = "Address 1", Address2 = "Address 2"
                },
                LocationName = "Location Name",
                LocationId   = 12345
            };

            var viewModel = service.Map <ProviderSearchResultItem, StandardProviderResultItemViewModel>(response);

            viewModel.Should().NotBeNull();
            viewModel.LocationAddressLine.Should().Be("Location Name, Address 1, Address 2");
            viewModel.DeliveryModes.Count.Should().Be(0);
        }
Пример #30
0
        public void Handle(CreateMemberRequest message)
        {
            if (string.IsNullOrWhiteSpace(message.Member.Email?.Address))
            {
                Bus.Publish(new MemberUpdatedEvent().LinkTo(message)
                            .WithProcessResult(new ArgumentException("Email address is required"),
                                               "Email address is required."));
                MarkAsComplete();
            }

            Data.Email = message.Member.Email?.Address;
            DataCache.SetItem(message, Data.Email);
            var createUserRequest = new CreateUserRequest
            {
                UserUpdate = MappingService.Map <UserUpdateDto>(message.Member)
            }.LinkTo(message);

            Bus.Send(_commonBusEndpointSettings.Identity, createUserRequest);
        }
Пример #31
0
        public ActionResult Search(int AirportDepartureId, int AirportArrivalId, DateTime DateOfDeparture, int AvailableSeats)
        {
            var flights = this.flightService.GetFlights(AirportDepartureId, AirportArrivalId, DateOfDeparture, AvailableSeats);

            var flightsViewModel = flights
                                   .Select(f => MappingService.Map <DetailsFlightViewModel>(f))
                                   .ToList();

            if (flightsViewModel.Count == 0)
            {
                this.TempData["Ticket"] = null;
            }
            else
            {
                this.TempData["Ticket"] = flightsViewModel;
            }

            return(PartialView("_FlightSearchResult", flightsViewModel));
        }
Пример #32
0
        private ClientDto GetClient(IdentityUow uow, string clientId)
        {
            var cacheKey  = CacheKeyHelper.GetCacheKey <ClientDto>(clientId);
            var clientDto = uow.Cache.GetCachedItem <ClientDto>(cacheKey);

            if (clientDto != null)
            {
                return(clientDto);
            }

            clientDto = MappingService.Map <ClientDto>(uow.Store.FirstOrDefault <Client>(x => x.ClientId == clientId));
            if (clientDto == null)
            {
                return(null);
            }

            CollectClientAssociatedInfo(uow, clientDto);
            uow.Cache.SetCachedItemAsync(cacheKey, clientDto).Wait();
            return(clientDto);
        }
Пример #33
0
        private UserDto GetUser(IdentityUow uow, string userProfileOriginator, string usernameOrEmailOrMobileNumber)
        {
            var cacheKey = GetUserCacheKey(usernameOrEmailOrMobileNumber);
            var userDto  = uow.Cache.GetCachedItem <UserDto>(cacheKey);

            if (userDto != null)
            {
                userDto.UserProfile = GetUserProfile(uow, userDto.Key, userProfileOriginator);
                return(userDto);
            }

            var localNumberInDigits = usernameOrEmailOrMobileNumber.GetNumberInDigits();

            if (!string.IsNullOrWhiteSpace(localNumberInDigits))
            {
                cacheKey = CacheKeyHelper.GetCacheKey <UserDto>(localNumberInDigits);
                userDto  = uow.Cache.GetCachedItem <UserDto>(cacheKey);
            }
            if (userDto != null)
            {
                userDto.UserProfile = GetUserProfile(uow, userDto.Key, userProfileOriginator);
                return(userDto);
            }

            var user = uow.Store.FirstOrDefault <User>(
                x => x.Email.Address == usernameOrEmailOrMobileNumber ||
                x.Username == usernameOrEmailOrMobileNumber ||
                x.Mobile.LocalNumberWithAreaCode == usernameOrEmailOrMobileNumber ||
                x.Mobile.LocalNumberWithAreaCodeInDigits == localNumberInDigits
                );

            if (user == null)
            {
                return(null);
            }

            userDto             = MappingService.Map <UserDto>(user);
            userDto.UserProfile = GetUserProfile(uow, userDto.Key, userProfileOriginator);
            CacheUserDto(uow, userDto);
            return(userDto);
        }