public void Should_not_throw_exceptions_with_fluent_mapping() { var newMapper = new MyMapper(); newMapper.Map <Banana>("Fruit").Map <Apple>("Fruit"); newMapper.Map <Grape>("Fruit"); }
public void Should_not_throw_exceptions_with_param_vector_mapping() { var newMapper = new MyMapper(); newMapper.Map("Fruit", typeof(Banana), typeof(Apple)); newMapper.Map("Fruit", typeof(Grape)); }
public void UpdateDepartment(DepartmentDTO dep) { Department d = MyMapper <DepartmentDTO, Department> .Map(dep); DB.Departments.Update(d); DB.Commit(); }
public void CreateBrigade(BrigadeDTO brigade) { Brigade newBrigade = MyMapper <BrigadeDTO, Brigade> .Map(brigade); DB.Brigades.Create(newBrigade); DB.Commit(); }
public void UpdateBrigade(BrigadeDTO brigade) { Brigade b = MyMapper <BrigadeDTO, Brigade> .Map(brigade); DB.Brigades.Update(b); DB.Commit(); }
/// <summary> /// MyMapper - Map extension method /// </summary> /// <typeparam name="TSource">The source type</typeparam> /// <typeparam name="TDestination">The destination type</typeparam> /// <param name="obj">The source object</param> /// <param name="map">MyMapper rules for the mapping</param> /// <param name="automap">Flag to indicate if to use automapping</param> /// <returns>The destination object <see cref="TDestination"/></returns> public static TDestination Map <TSource, TDestination>(this TSource obj, Func <IMyMapperRules <TSource, TDestination>, TDestination> map = null, bool automap = true ) where TSource : class where TDestination : class, new() { if (obj == null) { return(null); } IMyMapper <TSource, TDestination> mapper = new MyMapper <TSource, TDestination>(); mapper.Map(obj, automap); if (map != null) { return(map(mapper)); } else { return(mapper.Exec()); } }
/// <summary> /// MyMapper - Map Parallel extension method - Uses PLINQ /// </summary> /// <typeparam name="TSourceList">The source list type</typeparam> /// <typeparam name="TDestinationList">The destination list type</typeparam> /// <param name="source">The source list</param> /// <param name="map">MyMapper rules for the mapping</param> /// <param name="automap">Flag to indicate if to use automapping</param> /// <returns>The destination list <see cref="IEnumerable{TDestinationList}"/></returns> public static IEnumerable <TDestinationList> MapParallel <TSourceList, TDestinationList>( this IEnumerable <TSourceList> source, Func <IMyMapperRules <TSourceList, TDestinationList>, TDestinationList> map = null, bool automap = true ) where TSourceList : class where TDestinationList : class, new() { if (source == null) { return(null); } IMyMapper <TSourceList, TDestinationList> mapper = new MyMapper <TSourceList, TDestinationList>(); return(source.AsParallel().Select(src => { if (src == null) { return null; } mapper.Map(src, automap); if (map != null) { return map(mapper); } else { return mapper.Exec(); } })); }
/// <summary> /// MyMapper - MapAsync extension method /// </summary> /// <typeparam name="TSource">The source type</typeparam> /// <typeparam name="TDestination">The destination type</typeparam> /// <param name="obj">The source object</param> /// <param name="map">MyMapper rules for the mapping</param> /// <param name="automap">Flag to indicate if to use automapping</param> /// <returns>The Task of the destination object <see cref="Task{TDestination}"/></returns> public static async Task <TDestination> MapAsync <TSource, TDestination>(this TSource obj, Func <IMyMapperRules <TSource, TDestination>, TDestination> map = null, bool automap = true ) where TSource : class where TDestination : class, new() { if (obj == null) { return(null); } IMyMapper <TSource, TDestination> mapper = new MyMapper <TSource, TDestination>(); return(await Task.Run(() => { mapper.Map(obj, automap); if (map != null) { return map(mapper); } else { return mapper.Exec(); } })); }
public void UpdateNextRepair(NextRepairDTO nxtRepair) { NextRepair nr = MyMapper <NextRepairDTO, NextRepair> .Map(nxtRepair); DB.NextRepairs.Update(nr); DB.Commit(); }
public ActionResult NextRepairs() { IEnumerable <NextRepairDTO> nextRepairsDto = _nextRepairService.GetAllNextRepairs(); var nextRepairs = MyMapper <NextRepairDTO, NextRepairViewModel> .Map(nextRepairsDto); return(View(nextRepairs)); }
public void UpdateEquipment(EquipmentDTO equip) { Equipment e = MyMapper <EquipmentDTO, Equipment> .Map(equip); DB.Equipments.Update(e); DB.Commit(); }
public override LogDTO Update(int objectId, LogInsertRequest updateRequest) { var res = base.Update(objectId, updateRequest); var includeRes = _context.Log.Include(_ => _.User).FirstOrDefault(_ => _.Id == res.Id); return(MyMapper.Map <LogDTO>(includeRes)); }
public ActionResult LastRepairs() { IEnumerable <LastRepairDTO> lastRepairsDto = _lastRepairService.GetAllLastRepairs(); var lastRepairs = MyMapper <LastRepairDTO, LastRepairViewModel> .Map(lastRepairsDto); return(View(lastRepairs)); }
public ActionResult Brigades() { IEnumerable <BrigadeDTO> brigadesDto = _brigadeService.GetAllBrigades(); var brigades = MyMapper <BrigadeDTO, BrigadeViewModel> .Map(brigadesDto); return(View(brigades)); }
public ActionResult Equipments() { IEnumerable <EquipmentDTO> brigadesDto = _equipmentService.GetAllEquipments(); var equipments = MyMapper <EquipmentDTO, EquipmentViewModel> .Map(brigadesDto); return(View(equipments)); }
public ActionResult <Dictionary <string, Dictionary <string, IEnumerable <string> > > > GetAllAuthorities() { var dispatchedMetas = PermissionMetaHandler.GetAllDispatchedMetas(); var resource = MyMapper.Map <IEnumerable <PermissionMeta>, Dictionary <string, Dictionary <string, IEnumerable <string> > > >(dispatchedMetas); return(Ok(resource)); }
public override LogDTO Insert(LogInsertRequest InsertRequest) { var res = base.Insert(InsertRequest); var includeRes = _context.Log.Include(_ => _.User).FirstOrDefault(_ => _.Id == res.Id); return(MyMapper.Map <LogDTO>(includeRes)); }
/// <summary> /// adds a card /// </summary> /// <param name="card"></param> /// <returns></returns> public Common.Models.Card AddCard(Common.Models.Card card, Guid userId) { using (var context = new PaymentsDbContext(ContextOptions)) { try { var cardnumber = card.CardNumber; card.CardNumber = MaskCardNumber(cardnumber); var dbCard = context.Cards.FirstOrDefault(c => c.CardNumber == card.CardNumber && c.CVC == card.CVC && c.UserId == userId && c.ExpiryDate == card.ExpiryDate); if (dbCard == null || string.IsNullOrWhiteSpace(dbCard.Id.ToString())) { card.Id = Guid.NewGuid(); var newCard = MyMapper.Map <Models.Card>(card); newCard.UserId = userId; context.Cards.Add(newCard); context.SaveChanges(); } else { card.Id = dbCard.Id; } return(card); //var toReturn = MyMapper.Map<Common.Models.Card>(result); //return toReturn; } catch (Exception ex) { Log.LogError(ex, ""); Log.LogError(ex, $"Failed to create user"); throw ex; } } }
/// <summary> /// Adds a new payment /// </summary> public Common.Models.Payment StorePayment(Common.Models.Payment paymentRequest) { using (var context = new PaymentsDbContext(ContextOptions)) { try { var dbPayment = context.Payments.FirstOrDefault(c => c.Id == paymentRequest.PaymentId); if (dbPayment == null || string.IsNullOrWhiteSpace(dbPayment.Id.ToString())) { Log.LogInformation($"Adding the payment to the database: {paymentRequest.PaymentId}"); var newPayment = MyMapper.Map <Models.Payment>(paymentRequest); context.Payments.Add(newPayment); context.SaveChanges(); } else { Log.LogWarning($"Duplicate Payment: {paymentRequest.PaymentId}"); paymentRequest.Status = Common.Enums.PaymentStatus.DuplicateRequest; paymentRequest.IsSuccessful = false; paymentRequest.Message = $"Duplicate payment request"; } return(paymentRequest); } catch (Exception ex) { Log.LogError(ex, "Failed to store payment"); paymentRequest.Status = PaymentStatus.PaymentNotStored; return(paymentRequest); } } }
/// <summary> /// adds a user /// </summary> /// <param name="user"></param> /// <returns></returns> public Common.Models.User AddUser(Common.Models.User user) { using (var context = new PaymentsDbContext(ContextOptions)) { try { var dbUser = context.Users.FirstOrDefault(u => u.Fullname == user.Fullname && u.DateOfBirth == user.DateOfBirth); if (dbUser == null || string.IsNullOrWhiteSpace(dbUser.Id.ToString())) { user.Id = Guid.NewGuid(); context.Users.Add(MyMapper.Map <Models.User>(user)); context.SaveChanges(); } else { user.Id = dbUser.Id; } return(user); } catch (Exception ex) { Log.LogError(ex, $"Failed to create user"); throw ex; } } }
public void UpdateLastRepair(LastRepairDTO lstRepair) { LastRepair lr = MyMapper <LastRepairDTO, LastRepair> .Map(lstRepair); DB.LastRepairs.Update(lr); DB.Commit(); }
public ActionResult Departments() { IEnumerable <DepartmentDTO> departmentsDto = _departmentService.GetAllDepartments(); var departments = MyMapper <DepartmentDTO, DepartmentViewModel> .Map(departmentsDto); return(View(departments)); }
public async Task <ActionResult <OkMsg> > DispatchAuths( LinGroupDispatchAuthsResource linGroupDispatchAuthsResource) { var linAuths = new List <LinAuth>(); var dispatchedMetas = PermissionMetaHandler.GetAllDispatchedMetas(); var auths = (await _adminRepository.GetAllAuthsAsync()).ToList(); foreach (var auth in linGroupDispatchAuthsResource.Auths) { var existedLinAuth = auths.FirstOrDefault(a => a.GroupId == linGroupDispatchAuthsResource.GroupId && a.Auth == auth); if (existedLinAuth == null) { var meta = dispatchedMetas.Where(m => m.Auth == auth).ToList(); if (meta.Any()) { var addLinAuths = MyMapper.Map <IEnumerable <PermissionMeta>, IEnumerable <LinAuth> >(meta); linAuths.AddRange(addLinAuths); } } } _adminRepository.AddRange(linAuths); await UnitOfWork.SaveAsync(); return(Ok(new OkMsg { Msg = "添加权限成功" })); }
public async Task <ActionResult <LinGroupWithAuthsResource> > UpdateGroup(int gid, LinGroupUpdateResource linGroupUpdateResource) { var group = await _adminRepository.GetGroupWithAuthAndUserAsync(gid); if (group == null) { throw new NotFoundException { ErrorCode = ResultCode.GroupNotFoundErrorCode }; } MyMapper.Map(linGroupUpdateResource, group); _adminRepository.Update(group); if (!await UnitOfWork.SaveAsync()) { throw new Exception("Save Failed!"); } var resource = MyMapper.Map <LinGroup, LinGroupWithAuthsResource>(group); return(Ok(resource)); }
public async Task <ActionResult <IEnumerable <BookResource> > > GetAll([FromQuery] BookParameters parameters) { var books = await _bookRepository.GetAllAsync(parameters); var resources = MyMapper.Map <IEnumerable <BookResource> >(books); return(Ok(resources)); }
public async Task <ActionResult <IEnumerable <LinGroupResource> > > GetAllGroups() { var list = await _adminRepository.GetAllGroupsAsync(); var resources = MyMapper.Map <IEnumerable <LinGroup>, IEnumerable <LinGroupResource> >(list); return(Ok(resources)); }
public void MyMapperTest_WithOrder_ShouldMapIdAndDateFields() { // Arrange int orderId = 666; DateTime now = DateTime.Now; var order = new Order() { Id = orderId, Date = now }; // Act OrderDto orderDto = myMapper.Map(order); // Assert Assert.AreEqual(orderId, orderDto.Id); Assert.AreEqual(now, orderDto.Date); }
public async Task <ActionResult <PaginatedResult <LinUserResource> > > GetAllUsers([FromQuery] AdminParameters adminParameters) { var list = await _adminRepository.GetAllUsersWithGroupAsync(adminParameters); var resources = MyMapper.Map <IEnumerable <LinUser>, IEnumerable <LinUserResource> >(list); var result = WrapPaginatedResult(list, resources); return(Ok(result)); }
public async Task <ActionResult <PaginatedResult <LinLogResource> > > GetAllLogs( [FromQuery] LogParameters logParameters) { var list = await _linLogRepository.GetAllLogsAsync(logParameters); var resources = MyMapper.Map <IEnumerable <LinLog>, IEnumerable <LinLogResource> >(list); var result = WrapPaginatedResult(list, resources); return(Ok(result)); }
public ActionResult CreateNextRepair(NextRepairViewModel nextRepair) { if (nextRepair != null) { var nextRepairDTO = MyMapper <NextRepairViewModel, NextRepairDTO> .Map(nextRepair); _nextRepairService.CreateNextRepair(nextRepairDTO); return(RedirectToAction("NextRepairs")); } return(HttpNotFound()); }