public IEnumerable <User> GetByPredicate(Expression <Func <User, bool> > predicate, QueryParams <User> param) { try { //var currentPredicate = predicate.Convert<Entities.User, User>(mapper); var anotherPredicate = Mapper.Map <Expression <Func <User, bool> >, Expression <Func <Entities.User, bool> > >(predicate); param = QueryParams <User> .Validate(param, c => c.UserId, 10); using (Container = new ArticleContext()) { var list = Container.Users .OrderBy(c => c.UserId) .Where(anotherPredicate) .Skip(param.Skip ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Entities.User>, IEnumerable <User> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public async Task <UserModel> RegisterAsync(RegistrationModel model) { var response = new UserModel(); if (model == null) { response.Errors.Add(ErrorConstants.ModelIsNull); return(response); } var existingUser = await this.accountRepository.GetByEmailAsync(model.Email); if (existingUser != null) { response.Errors.Add(ErrorConstants.UserWithSameEmailExists); return(response); } var config = new MapperConfiguration(cfg => cfg.CreateMap <RegistrationModel, ApplicationUser>() .ForMember("UserName", opt => opt.MapFrom(x => x.Login))); var mapper = new AutoMapper.Mapper(config); var applicationUser = mapper.Map <RegistrationModel, ApplicationUser>(model); var result = await this.userManager.CreateAsync(applicationUser, model.Password); if (!result) { response.Errors.Add(ErrorConstants.IncorrectInput); return(response); } await this.userManager.AddToRoleAsync(applicationUser); return(response); }
public User Read(int id) { try { using (Container = new ArticleContext()) { var user = Container.Users.FirstOrDefault(c => c.UserId == id); if (user != null) { return(Mapper.Map <Entities.User, User>(user)); } return(null); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public async Task <UserModel> LogInAsync(LoginModel model, string password) { var response = new UserModel(); if (model == null) { response.Errors.Add(ErrorConstants.ModelIsNull); return(response); } var existingUser = await this.accountRepository.GetByEmailAsync(model.Email); if (existingUser == null) { response.Errors.Add(ErrorConstants.IncorrectInput); return(response); } var result = await this.userManager.LogInAsync(existingUser, password); if (!result) { response.Errors.Add(ErrorConstants.IncorrectPassword); return(response); } var config = new MapperConfiguration(cfg => cfg.CreateMap <ApplicationUser, UserModel>() .ForMember("Login", opt => opt.MapFrom(x => x.UserName))); var mapper = new AutoMapper.Mapper(config); response = mapper.Map <ApplicationUser, UserModel>(existingUser); return(response); }
public ActionResult Save(Movie movie) { if (!ModelState.IsValid) { var viewModel = new MovieFormViewModel(); var config = new MapperConfiguration(cfg => cfg.CreateMap <Movie, MovieFormViewModel>()); var mapper = new AutoMapper.Mapper(config); mapper.Map(movie, viewModel); var genres = _context.Genres.ToList(); viewModel.Genres = genres; return(View("MovieForm", viewModel)); } if (movie.Id == 0) { movie.AddedDate = DateTime.Now; _context.Movies.Add(movie); } else { var moviesInDb = _context.Movies.Single(m => m.Id == movie.Id); var config = new MapperConfiguration(cfg => cfg.CreateMap <Movie, Movie>()); var mapper = new AutoMapper.Mapper(config); mapper.Map(movie, moviesInDb); } _context.SaveChanges(); return(RedirectToAction("Index", "Movies")); }
static Mapper() { TypeMapper.CreateMap <With.Message.IObservation, Observed>(); TypeMapper.CreateMap <With.Message.IStopped, Stopped>(); TypeMapper.CreateMap <With.Message.IStarted, Started>(); TypeMapper.CreateMap <With.Message.IDeregister, Deregistered>(); TypeMapper.CreateMap <With.Message.IRegister, Registered>(); //TypeMapper.CreateMap<With.Component.MeasurementType, Schema.MeasurementType>(); TypeMapper.CreateMap <With.Component.IIdentity, Component.Identity>().ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.ToString())); TypeMapper.CreateMap <With.Component.IDescription, Component.Description>(); TypeMapper.CreateMap <With.Component.IEntity, Component.Entity>().ForMember(dest => dest.Identity, opt => opt.MapFrom(src => src.Identity)); TypeMapper.CreateMap <With.Component.IEntityDescription, Component.EntityDescription>(); TypeMapper.CreateMap <With.Component.IMeasurement, Component.Measurement>(); TypeMapper.CreateMap <With.Component.IValueDescription, Component.ValueDescription>(); TypeMapper.CreateMap <With.Component.IObservable, Component.Observable>().ForMember(dest => dest.Identity, opt => opt.MapFrom(src => src.Identity)); TypeMapper.CreateMap <With.Component.IParameter, Component.Parameter>().ForMember(dest => dest.Identity, opt => opt.MapFrom(src => src.Identity)); TypeMapper.CreateMap <With.Component.IParameterDescription, Component.ParameterDescription>(); TypeMapper.CreateMap <With.Component.IActionable, Component.Actionable>().ForMember(dest => dest.Identity, opt => opt.MapFrom(src => src.Identity)); /* * TypeMapper.CreateMap<With.Component.IParameterValue, Schema.ParameterValue>() * .ForMember(dest => dest.UniqueIdentifier, opt => opt.MapFrom(src => src.Identity)); */ TypeMapper.CreateMap <With.Message.IRegister, Event.Registered>(); TypeMapper.CreateMap <With.Message.IDeregister, Event.Deregistered>(); TypeMapper.CreateMap <With.Message.IObservation, Event.Observed>(); TypeMapper.CreateMap <With.Message.IAction, Event.Action>(); TypeMapper.AssertConfigurationIsValid(); }
public async Task <ActionResult> GetClientCheckups(long customerid) { try { if (!ModelState.IsValid) { return(BadRequest()); } var lst = await _dBRepository.client_periodic_checkups.Where(l => l.account_id == customerid && l.is_deleted == false).AsNoTracking().ToListAsync(); var result = new List <ClientPeriodicCheckupModel>(); var mapper = new AutoMapper.Mapper(new MapperConfiguration(cfg => { cfg.CreateMap <ClientPeriodicCheckUp, ClientPeriodicCheckupModel>(); })); mapper.Map(lst, result); return(Ok(new CoreResponse() { is_success = true, data = result })); } catch (Exception ex) { return(Ok(new CoreResponse() { is_success = false, data = null, dev_message = ex.Message })); } }
public void AutomapperBenchmark() { var mapper = new AutoMapper.Mapper(new MapperConfiguration(config => config.CreateMap <A, A>())); mapper.Map <A, A>(new A(), new A()); }
public static Output Convert <Input, Output>(Input item) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Input, Output>()); var mapper = new AutoMapper.Mapper(config); return(mapper.Map <Output>(item)); }
public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var viewModel = new CustomerFormViewModel { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("CustomerForm", viewModel)); } if (customer.Id == 0) { _context.Customers.Add(customer); } else { var customerInDb = _context.Customers.Single(c => c.Id == customer.Id); var config = new MapperConfiguration(cfg => cfg.CreateMap <Customer, Customer>()); var mapper = new AutoMapper.Mapper(config); mapper.Map(customer, customerInDb); } _context.SaveChanges(); return(RedirectToAction("Index", "Customers")); }
/// <summary> /// 类型映射 /// </summary> //public static T MapTo<T>(this object obj) //{ // var configuration = new AutoMapper.MapperConfiguration(cfg => cfg.AddMaps("Edoc2.Core")); // var mapper = new AutoMapper.Mapper(configuration); // return mapper.Map<T>(obj); //} /// <summary> /// 类型映射 /// </summary> public static T MapTo <T>(this object obj) { if (obj == null) { return(default(T)); } var configuration = new MapperConfiguration(cfg => { cfg.CreateMap(obj.GetType(), typeof(T)); var appServices = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes().Where(t => t.IsInterface == false && t.IsClass == true && t.CustomAttributes.Count() > 0 && t.Name.ToLower().EndsWith("dto"))).ToArray(); foreach (var item in appServices) { if (item.GetCustomAttributesData().Count() > 0 && item.GetCustomAttributesData()[0].AttributeType.Name == "AutoMapAttribute" && item.GetCustomAttributesData()[0].ConstructorArguments.Count() > 0) { Type target = (Type)item.GetCustomAttributesData()[0].ConstructorArguments[0].Value; cfg.CreateMap(target, item); } } }); var mapper = new AutoMapper.Mapper(configuration); return(mapper.Map <T>(obj)); }
public Tdestination Map <Tdestination, TSource>(TSource model) { var config = new MapperConfiguration(config => config.CreateMap(typeof(TSource), typeof(Tdestination))); var mapper = new AutoMapper.Mapper(config); return(mapper.Map <Tdestination>(model)); }
public IEnumerable <User> GetAll(QueryParams <User> param) { try { param = QueryParams <User> .Validate(param, c => c.UserId, 10); using (Container = new ArticleContext()) { var list = Container.Users.OrderBy(c => c.UserId).Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var result = Mapper.Map <IEnumerable <Entities.User>, IEnumerable <User> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public List <DgvDetalleNota> MapDgvVentas(List <DetalleNotaEntity> origen) { var mapper = new AutoMapper.Mapper(datagridVentasConfig); var dgvList = mapper.Map <List <DetalleNotaEntity>, List <DgvDetalleNota> >(origen); dgvList.ForEach(x => x.Total = x.Cantidad * x.PrecioVenta); return(dgvList); }
public void Setup() { _autoMapper = new AutoMapper.Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Complex, Complex>())); _mapping = Mapping <Complex, Complex> .Auto(); ExpressMapper.Mapper.Instance.Register <Complex2, Complex2>(); ExpressMapper.Mapper.Instance.Register <Complex, Complex>(); }
public static TDestiantion Map <TSource, TDestiantion>(TSource source) where TSource : class where TDestiantion : class { var configuration = new MapperConfiguration(cfg => cfg.CreateMap <TSource, TDestiantion>()); var mapper = new AutoMapper.Mapper(configuration); return(mapper.Map <TDestiantion>(source)); }
public ApiKeyController(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; _mapper = new AutoMapper.Mapper(new MapperConfiguration(cfg => { cfg.CreateMap <ApiKey, ApiKeyDto>().ForMember(d => d.Roles, opt => opt.MapFrom(m => m.Roles.Select(r => r.Role).ToList())); cfg.CreateMap <Role, RoleDto>().ReverseMap(); })); }
/// <summary> /// Creates an instance of IMapper /// </summary> /// <returns></returns> protected IMapper CreateMap() { Mapper.Initialize(mappings); var config = new MapperConfiguration(mappings); IMapper mapper = new AutoMapper.Mapper(config); mapper.ConfigurationProvider.AssertConfigurationIsValid(); return(mapper); }
public DataMapper() { var config = new MapperConfiguration(cfg => { cfg.CreateMap <ApplicationDetails, ApplicationDetailsDto>(); }); _mapper = new AutoMapper.Mapper(config); }
internal AutoMapper.Mapper ConfigureAutoMapper() { MapperConfiguration config = new MapperConfiguration(cfg => { cfg.CreateMap <CustomerDto, Customer>(); }); AutoMapper.Mapper mapper = new AutoMapper.Mapper(config); return(mapper); }
/// <summary> /// 初始化需要映射的信息。 /// </summary> /// <param name="mapperCollection">映射信息集合。</param> public void Initialize(IEnumerable <MapperDescriptor> mapperCollection) { M.Initialize(cfg => { foreach (var descriptor in mapperCollection) { cfg.CreateMap(descriptor.SourceType, descriptor.TargetType); cfg.CreateMap(descriptor.TargetType, descriptor.SourceType); } }); }
public void GlobalSetup() { _dto = GetCustomerDto(); _fsMapper = ConfigureFsMapper(); _dataMapper = ConfigureTulurDataMapper(); _autoMapper = ConfigureAutoMapper(); ConfigureExpressMapper(); ConfigureAutoMapper(); }
public static Core.Community Map(CommunityViewModel data) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <CommunityViewModel, Core.Community>(); }); var mapper = new AutoMapper.Mapper(config); Core.Community map = mapper.DefaultContext.Mapper.Map <Core.Community>(data); return(map); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #region егистрация сервисов для уровня представления services.AddSingleton <IChartManager, ChartManager>(); services.AddSingleton <IWorkerServices, WorkerServices>(); services.AddSingleton <IRoleServices, RoleServices>(); services.AddSingleton <IFullUserServices, FullUserServisces>(); services.AddSingleton <IServiceServices, ServiceServices>(); services.AddSingleton <IComponentServices, ComponentServices>(); services.AddSingleton <IBuildStandartService, BuildStandartService>(); services.AddSingleton <IClientServices, ClientServices>(); services.AddSingleton <IOrderServices, OrderServices>(); services.AddSingleton <IOrderInfoServise, OrderInfoServices>(); #endregion #region егистрация сервисов для уровня бизнес логики services.AddSingleton <BL.Services.Abstract.IChartManager, BL.Services.ChartManager>(); services.AddSingleton <BL.Services.Abstract.IBuildStandartServices, BL.Services.BuildStandartServices>(); services.AddSingleton <BL.Services.Abstract.IRoleServices, BL.Services.RoleServices>(); services.AddSingleton <BL.Services.Abstract.IWorkerServices, BL.Services.WorkerServices>(); services.AddSingleton <BL.Services.Abstract.IUserRoleServices, BL.Services.UserRoleServises>(); services.AddSingleton <BL.Services.Abstract.IUserServices, BL.Services.UserServices>(); services.AddSingleton <BL.Services.Abstract.IFullUserServices, BL.Services.FullUserServisces>(); services.AddSingleton <BL.Services.Abstract.IServiceServices, BL.Services.ServiceServices>(); services.AddSingleton <BL.Services.Abstract.IComponetServices, BL.Services.ComponentServices>(); services.AddSingleton <BL.Services.Abstract.IClientServices, BL.Services.ClientServices>(); services.AddSingleton <BL.Services.Abstract.IOrderServices, BL.Services.OrderServices>(); services.AddSingleton <BL.Services.Abstract.IOrderInfoServices, BL.Services.OrderInfoServices>(); #endregion services.AddMemoryCache(); services.AddSession(); services.AddMvc(options => options.EnableEndpointRouting = false); #region регистрация сервисов для уровня доступа к данным var mapperConfigure = new MapperConfiguration(x => x.AddProfiles(new List <AutoMapper.Profile>() { new BL.Mappers.ConfigEntityToDtoAndReverse(), new PL.Infrastructure.Mappers.ConfigModelsToDtoAndReverse() })); var mapper = new AutoMapper.Mapper(mapperConfigure); services.AddSingleton(mapper); #endregion services.AddOptions(); }
public void CreateMapper() { var mapperConfig = new MapperConfiguration(c => { c.AddMaps(typeof(TrainingProviderMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("UserNameResolver") ? new UserNameResolver <UpdateIndustryPlacementQuestionViewModel, UpdateLearnerRecordRequest>(HttpContextAccessor) : null); }); Mapper = new AutoMapper.Mapper(mapperConfig); }
public static Core.Community Map(CommunityViewModel from, Core.Community to) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <CommunityViewModel, Core.Community>(); cfg.CreateMap <CommunityTagViewModel, CommunityTag>(); }); var mapper = new AutoMapper.Mapper(config); Core.Community user = mapper.DefaultContext.Mapper.Map <CommunityViewModel, Core.Community>(from, to); return(to); }
public static User Map(UserViewModel from, User to) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <UserViewModel, User>(); cfg.CreateMap <CommunityViewModel, Core.Community>(); }); var mapper = new AutoMapper.Mapper(config); User user = mapper.DefaultContext.Mapper.Map <UserViewModel, User>(from, to); return(to); }
public static UserViewModel Map(User data) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <User, UserViewModel>(); cfg.CreateMap <Core.Community, CommunityViewModel>(); }); var mapper = new AutoMapper.Mapper(config); UserViewModel user = mapper.DefaultContext.Mapper.Map <UserViewModel>(data); return(user); }
public ItemCategoryServiceMapper() { MapperConfigurationExpression.CreateMap <DAL.App.DTO.Category, BLL.App.DTO.Category>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.Category, DAL.App.DTO.Category>(); MapperConfigurationExpression.CreateMap <DAL.App.DTO.ItemCategory, BLL.App.DTO.ItemCategory>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.ItemCategory, DAL.App.DTO.ItemCategory>(); MapperConfigurationExpression.CreateMap <DAL.App.DTO.Item, BLL.App.DTO.Item>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.Item, DAL.App.DTO.Item>(); Mapper = new AutoMapper.Mapper(new MapperConfiguration(MapperConfigurationExpression)); }
public BrandServiceMapper() { MapperConfigurationExpression.CreateMap <DAL.App.DTO.Item, BLL.App.DTO.Item>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.Item, DAL.App.DTO.Item>(); MapperConfigurationExpression.CreateMap <DAL.App.DTO.ItemInCart, BLL.App.DTO.ItemInCart>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.ItemInCart, DAL.App.DTO.ItemInCart>(); MapperConfigurationExpression.CreateMap <DAL.App.DTO.Brand, BLL.App.DTO.Brand>(); MapperConfigurationExpression.CreateMap <BLL.App.DTO.Brand, DAL.App.DTO.Brand>(); Mapper = new AutoMapper.Mapper(new MapperConfiguration(MapperConfigurationExpression)); }