本文整理汇总了C#中MapperConfiguration.Map方法的典型用法代码示例。如果您正苦于以下问题:C# MapperConfiguration.Map方法的具体用法?C# MapperConfiguration.Map怎么用?C# MapperConfiguration.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapperConfiguration
的用法示例。
在下文中一共展示了MapperConfiguration.Map方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserInfo
//
// GET: /Account/UserInfo
public ActionResult UserInfo()
{
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<ApplicationUser, UserModel>()).CreateMapper();
var user = mapper.Map<ApplicationUser, UserModel>(UserManager.FindById(User.Identity.GetUserId()));
return View(user);
}
示例2: Init
public void Init()
{
IRepository repo = new Repository();
var list = repo.Query<OrderItem>(x => x.OrderID == ID)
.FindAll(x => x.IsActive && Product.Cache.Load(x.ProductGuid) != null);
if (list.Any())
{
var oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.MembershipCore));
if (oiBase != null)
{
var mapperMemShipCore = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmMemShipCore>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIMembershipCore = mapperMemShipCore.Map<OrdrItmMemShipCore>(oiBase);
}
oiBase =
list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.MembershipPremier));
if (oiBase != null)
{
var mapperMemShipPremier = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmMemShipPremier>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIMembershipPremier = mapperMemShipPremier.Map<OrdrItmMemShipPremier>(oiBase);
}
if (OIMembershipCore != null || OIMembershipPremier != null)
{
UrlOrderView = "iArsenalOrderView_Membership.aspx";
}
else
{
throw new Exception("Unable to init Order_Membership.");
}
}
#region Order Status Workflow Info
var strWorkflow = "{{ \"StatusType\": \"{0}\", \"StatusInfo\": \"{1}\" }}";
string[] workflowInfo =
{
string.Format(strWorkflow, ((int) OrderStatusType.Draft), "未提交"),
string.Format(strWorkflow, ((int) OrderStatusType.Submitted), "审核中"),
string.Format(strWorkflow, ((int) OrderStatusType.Confirmed), "已确认")
};
StatusWorkflowInfo = workflowInfo;
#endregion
}
示例3: GetResults
private async Task GetResults()
{
var mapper = new MapperConfiguration(cfg => cfg.CreateMissingTypeMaps = true).CreateMapper();
var nQuery = mapper.Map<QueryViewModel, AzureNLogQueryDefinition>(this.Query);
var queryer = new TableQueryer(this.Connection.ConnectionString, this.Connection.TableName);
this.Message = "Getting logs";
var rSet = (await queryer.GetLogsAsync(nQuery, this.Query.MaxResults)).ToArray();
this.Message = $"{rSet.Length} logs found";
this.Results = new ObservableCollection<LogEntity>(rSet);
}
示例4: Should_resolve_using_custom_func
public void Should_resolve_using_custom_func()
{
var mapper = new MapperConfiguration(
cfg => cfg.CreateMap<Source, Dest>().ForCtorParam("thing", opt => opt.ResolveUsing(src =>
{
var rev = src.Value + 3;
return rev;
})))
.CreateMapper();
var dest = mapper.Map<Source, Dest>(new Source { Value = 5 });
dest.Value1.ShouldEqual(8);
}
示例5: MyAvatar
// 我的用户切换
// GET: /Account/MyAvatar
public ActionResult MyAvatar()
{
var model = new MyAvatarDto();
// 判断当前用户是否有马甲
var user = UserDto.GetSession();
// 如果超过一个相同的微信OpenID账号,则跳转MyAvatar
if (!string.IsNullOrEmpty(user.WeChatOpenID))
{
var query = _repo.Query<User>(x => x.WeChatOpenID == user.WeChatOpenID);
if (query.Count > 1)
{
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<User, UserDto>()).CreateMapper();
var list = mapper.Map<IEnumerable<UserDto>>(query.AsEnumerable());
model.Avatars = list;
return View(model);
}
}
TempData["DataUrl"] = "data-url=/Account";
return RedirectToAction("Index", "Account");
}
示例6: Must_throw_exception_if_base_class_properties_are_not_mapped
public void Must_throw_exception_if_base_class_properties_are_not_mapped()
{
var barSubClassConfiguration = new MapperConfiguration<Foo, BarSubClass>();
barSubClassConfiguration.Map(target => target.SubClassProperty).From(source => false);
var systemUnderTest = new MappingMethodGenerator();
Assert.Throws<Exception>(
() => systemUnderTest.GenerateMappingMethod(barSubClassConfiguration),
String.Format(
"Mapping configuration is invalid.{0}A mapping was not provided for target property 'BarSubClass.A' from source 'Foo'.{0}A mapping was not provided for target property 'BarSubClass.B' from source 'Foo'.{0}A mapping was not provided for read-only target property 'BarSubClass.C' from source 'Foo'.",
Environment.NewLine));
}
示例7: CreateStudent
public ActionResult CreateStudent(NewStudent newStudent)
{
try
{
CheckModelState(ModelState, "Students.CreateStudent");
newStudent.Password = AESCrypt.EncryptString(newStudent.Password, "SSWSecretKey");
var Mapper = new MapperConfiguration(cfg => cfg.CreateMap<NewStudent, Students>()).CreateMapper();
Students student = Mapper.Map<Students>(newStudent);
var Id = DBHelper.Instance.CreateStudent(student);
return Json(new { success = "Студент успешно добавлен", Id = Id });
}
catch (Exception ex)
{
return Json(new { errors = ex.Message });
}
}
示例8: Init
public void Init()
{
IRepository repo = new Repository();
var list = repo.Query<OrderItem>(x => x.OrderID == ID)
.FindAll(x => x.IsActive && Product.Cache.Load(x.ProductGuid) != null);
if (list.Any())
{
var oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.MatchTicket));
if (oiBase != null)
{
var mapperMatchTicket = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmMatchTicket>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIMatchTicket = mapperMatchTicket.Map<OrdrItmMatchTicket>(oiBase);
}
oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.TicketBeijing));
if (oiBase != null)
{
var mapperTicketBeijing = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItm2012TicketBeijing>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OITicketBeijing = mapperTicketBeijing.Map<OrdrItm2012TicketBeijing>(oiBase);
}
// Set the value of URLOrderView;
if (OIMatchTicket != null)
{
UrlOrderView = "iArsenalOrderView_MatchTicket.aspx";
}
else if (OITicketBeijing != null)
{
UrlOrderView = "iArsenalOrderView_TicketBeijing.aspx";
}
else
{
throw new Exception("Unable to init Order_Ticket.");
}
}
#region Order Status Workflow Info
var strWorkflow = "{{ \"StatusType\": \"{0}\", \"StatusInfo\": \"{1}\" }}";
string[] workflowInfo =
{
string.Format(strWorkflow, ((int) OrderStatusType.Draft), "未提交"),
string.Format(strWorkflow, ((int) OrderStatusType.Submitted), "后台审核"),
string.Format(strWorkflow, ((int) OrderStatusType.Confirmed), "已付款"),
string.Format(strWorkflow, ((int) OrderStatusType.Ordered), "预定成功"),
string.Format(strWorkflow, ((int) OrderStatusType.Delivered), "已出票")
};
StatusWorkflowInfo = workflowInfo;
#endregion
}
示例9: Init
public void Init()
{
IRepository repo = new Repository();
var list = repo.Query<OrderItem>(x => x.OrderID == ID)
.FindAll(x => x.IsActive && Product.Cache.Load(x.ProductGuid) != null);
if (list.Any())
{
var oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.TravelPlan));
if (oiBase != null)
{
var mapperTravelPlan = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmTravelPlan>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OITravelPlan = mapperTravelPlan.Map<OrdrItmTravelPlan>(oiBase);
}
if (OITravelPlan != null)
{
var oiPartnerList =
list.FindAll(
x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.TravelPartner));
var mapperTravelPartner = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmTravelPartner>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OITravelPartnerList = mapperTravelPartner.Map<List<OrdrItmTravelPartner>>(oiPartnerList);
#region Generate UrlOrderView by Product Code
var p = Product.Cache.Load(OITravelPlan.ProductGuid);
if (p != null && p.ProductType.Equals(ProductType.TravelPlan))
{
if (p.Code.Equals("iETPL", StringComparison.OrdinalIgnoreCase))
{
UrlOrderView = "iArsenalOrderView_LondonTravel.aspx";
}
else if (p.Code.Equals("2015ATPL", StringComparison.OrdinalIgnoreCase))
{
UrlOrderView = "iArsenalOrderView_AsiaTrophy2015.aspx";
}
else
{
throw new Exception("Unable to init Order_Travel.");
}
}
else
{
throw new Exception("Unable to init Order_Travel.");
}
#endregion
}
else
{
throw new Exception("Unable to init Order_Travel.");
}
}
#region Order Status Workflow Info
var strWorkflow = "{{ \"StatusType\": \"{0}\", \"StatusInfo\": \"{1}\" }}";
string[] workflowInfo =
{
string.Format(strWorkflow, ((int) OrderStatusType.Draft), "未提交"),
string.Format(strWorkflow, ((int) OrderStatusType.Submitted), "审核中"),
string.Format(strWorkflow, ((int) OrderStatusType.Confirmed), "已确认"),
string.Format(strWorkflow, ((int) OrderStatusType.Delivered), "已完成")
};
StatusWorkflowInfo = workflowInfo;
#endregion
}
示例10: Init
public void Init()
{
IRepository repo = new Repository();
var list = repo.Query<OrderItem>(x => x.OrderID == ID)
.FindAll(x => x.IsActive && Product.Cache.Load(x.ProductGuid) != null);
if (list.Count > 0)
{
var oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ReplicaKitHome));
if (oiBase != null)
{
var mapperReplicakitHome = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmReplicaKitHome>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIReplicaKitHome = mapperReplicakitHome.Map<OrdrItmReplicaKitHome>(oiBase);
}
oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ReplicaKitAway));
if (oiBase != null)
{
var mapperReplicakitAway = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmReplicaKitAway>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIReplicaKitAway = mapperReplicakitAway.Map<OrdrItmReplicaKitAway>(oiBase);
}
oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ReplicaKitCup));
if (oiBase != null)
{
var mapperReplicakitCup = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmReplicaKitCup>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIReplicaKitCup = mapperReplicakitCup.Map<OrdrItmReplicaKitCup>(oiBase);
}
if (OIReplicaKitHome != null || OIReplicaKitAway != null || OIReplicaKitCup != null)
{
UrlOrderView = "iArsenalOrderView_ReplicaKit.aspx";
oiBase =
list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PlayerNumber));
if (oiBase != null)
{
var mapperPlayerNumber = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmPlayerNumber>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIPlayerNumber = mapperPlayerNumber.Map<OrdrItmPlayerNumber>(oiBase);
}
oiBase = list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PlayerName));
if (oiBase != null)
{
var mapperPlayerName = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmPlayerName>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIPlayerName = mapperPlayerName.Map<OrdrItmPlayerName>(oiBase);
}
oiBase =
list.Find(x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ArsenalFont));
if (oiBase != null)
{
var mapperArsenalFont = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmArsenalFont>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIArsenalFont = mapperArsenalFont.Map<OrdrItmArsenalFont>(oiBase);
}
oiBase =
list.Find(
x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.PremiershipPatch));
if (oiBase != null)
{
var mapperPremiershipPatch = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmPremiershipPatch>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIPremiershipPatch = mapperPremiershipPatch.Map<OrdrItmPremiershipPatch>(oiBase);
}
oiBase =
list.Find(
x => Product.Cache.Load(x.ProductGuid).ProductType.Equals(ProductType.ChampionshipPatch));
if (oiBase != null)
{
var mapperChampionshipPatch = new MapperConfiguration(cfg =>
cfg.CreateMap<OrderItem, OrdrItmChampionshipPatch>().AfterMap((s, d) => d.Init()))
.CreateMapper();
OIChampionshipPatch = mapperChampionshipPatch.Map<OrdrItmChampionshipPatch>(oiBase);
}
}
else
//.........这里部分代码省略.........
示例11: MyCoupon
// 比分投注单
// GET: /Casino/MyCoupon
public ActionResult MyCoupon()
{
var model = new MyCouponDto();
var days = ConfigGlobal_AcnCasino.CasinoValidDays;
var query = _repo.Query<MatchView>(
x => x.PlayTime > DateTime.Now && x.PlayTime < DateTime.Now.AddDays(days))
.FindAll(x => !x.ResultHome.HasValue && !x.ResultAway.HasValue)
.OrderBy(x => x.PlayTime)
.Many<MatchView, ChoiceOption, Guid>(t => t.CasinoItem.ID);
var mapper = MatchDto.ConfigMapper().CreateMapper();
var mList = mapper.Map<IEnumerable<MatchDto>>(query.AsEnumerable());
mapper = new MapperConfiguration(cfg => cfg.CreateMap<MatchDto, CouponDto>()
.ForMember(d => d.MatchGuid, opt => opt.MapFrom(s => s.ID))).CreateMapper();
var list = mapper.Map<IEnumerable<CouponDto>>(mList).ToList();
if (list.Count > 0)
{
// 查找当前用户的比分投注项
var coupons = _repo.Query<CouponView>(x => x.UserID == AcnID);
if (coupons.Count > 0)
{
mapper = CouponDto.ConfigMapper().CreateMapper();
foreach (var c in coupons)
{
var i = list.FindIndex(x => x.MatchGuid.Equals(c.MatchGuid));
if (i >= 0)
{
list[i] = mapper.Map<CouponDto>(c);
}
}
}
}
model.Coupons = list;
model.CasinoValidDays = days;
model.IsShowSubmitButton = list.Count > 0 && list.Any(x => !x.BetResultHome.HasValue && !x.BetResultAway.HasValue);
return View(model);
}
示例12: CreateTeacher
public ActionResult CreateTeacher(NewTeacher newTeacher)
{
try
{
CheckModelState(ModelState, "Teachers.CreateTeacher");
newTeacher.Password = AESCrypt.EncryptString(newTeacher.Password, "SSWSecretKey");
var Mapper = new MapperConfiguration(cfg => cfg.CreateMap<NewTeacher, Teachers>()).CreateMapper();
Teachers teacher = Mapper.Map<Teachers>(newTeacher);
var Id = DBHelper.Instance.CreateTeacher(teacher);
return Json(new { success = "Преподаватель успешно добавлен", Id = Id });
}
catch (Exception ex)
{
return Json(new { errors = ex.Message });
}
}