Advertisement
FoxTuGa

Cast and map

Apr 7th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.70 KB | None | 0 0
  1. [ChildActionOnly]
  2. public Expression<Func<TModel, dynamic>>[] GetMapping<TModel>()
  3. {
  4.     Expression<Func<TModel, dynamic>>[] map = null;
  5.     Type modelType = typeof(TModel);
  6.  
  7.     object auxMap = null;
  8.     if (modelType == typeof(AssiduityCodesViewModel))
  9.     {
  10.         auxMap =
  11.             CSVMapper.RawMap<AssiduityCodesViewModel>(
  12.                 x => x.AssiduityCode
  13.                 , x => x.AssiduityCodeErp
  14.                 , x => x.AssiduityTypeCode
  15.                 , x => x.AssiduityCodeDesc
  16.                 , x => x.CompanyName
  17.                 , x => x.Vacation
  18.                 , x => x.NeedsProof
  19.                 , x => x.Active
  20.             );
  21.     }
  22.     else if (modelType == typeof(HolidayViewModel))
  23.     {
  24.         auxMap =
  25.             CSVMapper.RawMap<HolidayViewModel>(
  26.                 x => x.HolidayId
  27.                 , x => x.HolidayTypeCode
  28.                 , x => x.HolidayDay
  29.                 , x => x.CompanyCode
  30.                 , x => x.MunicipalityCode
  31.                 , x => x.CountyCode
  32.                 , x => x.CountryCode
  33.                 , x => x.Description
  34.                 , x => x.YearPlanner
  35.                 , x => x.FixedHoliday
  36.                 , x => x.Active
  37.             );
  38.     }
  39.     else if (modelType == typeof(HolidayTypeViewModel))
  40.     {
  41.         auxMap =
  42.             CSVMapper.RawMap<HolidayTypeViewModel>(
  43.                 x => x.IdHolidayTypeCode
  44.                 , x => x.Description
  45.                 , x => x.Active
  46.             );
  47.     }
  48.     else if (modelType == typeof(FringeBenefitsViewModel))
  49.     {
  50.         auxMap =
  51.             CSVMapper.RawMap<FringeBenefitsViewModel>(
  52.                 x => x.Code
  53.                 , x => x.CompanyCode
  54.                 , x => x.ErpCode
  55.                 , x => x.Description
  56.                 , x => x.Value
  57.                 , x => x.Limit
  58.                 , x => x.IsActive
  59.             );
  60.     }
  61.     else if (modelType == typeof(RelativeViewModel))
  62.     {
  63.         auxMap =
  64.             CSVMapper.RawMap<RelativeViewModel>(
  65.                 x => x.RelativeCode
  66.                 , x => x.CompanyCode
  67.                 , x => x.ErpCode
  68.                 , x => x.Description
  69.                 , x => x.Active
  70.             );
  71.     }
  72.     else if (modelType == typeof(CountyViewModel))
  73.     {
  74.         auxMap =
  75.             CSVMapper.RawMap<CountyViewModel>(
  76.                 x => x.CountyCode
  77.                 , x => x.CountryCode
  78.                 , x => x.ErpCode
  79.                 , x => x.Description
  80.                 , x => x.Active
  81.             );
  82.     }
  83.     else if (modelType == typeof(CountryViewModel))
  84.     {
  85.         auxMap =
  86.             CSVMapper.RawMap<CountryViewModel>(
  87.                 x => x.CountryCode
  88.                 , x => x.ErpCode
  89.                 , x => x.Description
  90.                 , x => x.Active
  91.             );
  92.     }
  93.     else if (modelType == typeof(RequestTypeViewModel))
  94.     {
  95.         auxMap =
  96.             CSVMapper.RawMap<RequestTypeViewModel>(
  97.                 x => x.Id
  98.                 , x => x.Name
  99.                 , x => x.Description
  100.                 , x => x.CompanyCode
  101.                 , x => x.Active
  102.             );
  103.     }
  104.     else if (modelType == typeof(FinancialOfficeViewModel))
  105.     {
  106.         auxMap =
  107.             CSVMapper.RawMap<FinancialOfficeViewModel>(
  108.                 x => x.FinancialOfficeCode
  109.                 , x => x.ErpCode
  110.                 , x => x.Description
  111.                 , x => x.CompanyCode
  112.                 , x => x.Active
  113.             );
  114.     }
  115.     else if (modelType == typeof(IncomeCategoryViewModel))
  116.     {
  117.         auxMap =
  118.             CSVMapper.RawMap<IncomeCategoryViewModel>(
  119.                 x => x.IncomeCategoryCode
  120.                 , x => x.ErpCode
  121.                 , x => x.Description
  122.                 , x => x.CompanyCode
  123.                 , x => x.Active
  124.             );
  125.     }
  126.     else if (modelType == typeof(IdCardTypeViewModel))
  127.     {
  128.         auxMap =
  129.             CSVMapper.RawMap<IdCardTypeViewModel>(
  130.                 x => x.IdCardTypeCode
  131.                 , x => x.ErpCode
  132.                 , x => x.Description
  133.                 , x => x.CompanyCode
  134.                 , x => x.Active
  135.             );
  136.     }
  137.     else if (modelType == typeof(DistrictViewModel))
  138.     {
  139.         auxMap =
  140.             CSVMapper.RawMap<DistrictViewModel>(
  141.                 x => x.DistrictCode
  142.                 , x => x.ErpCode
  143.                 , x => x.Description
  144.                 , x => x.CountryCode
  145.                 , x => x.Active
  146.             );
  147.     }
  148.     else if (modelType == typeof(MunicipalityViewModel))
  149.     {
  150.         auxMap =
  151.             CSVMapper.RawMap<MunicipalityViewModel>(
  152.                 x => x.MunicipalityCode
  153.                 , x => x.ErpCode
  154.                 , x => x.Description
  155.                 , x => x.CountryCode
  156.                 , x => x.Active
  157.             );
  158.     }
  159.     else if (modelType == typeof(ResidenceViewModel))
  160.     {
  161.         auxMap =
  162.             CSVMapper.RawMap<ResidenceViewModel>(
  163.                 x => x.ResidenceCode
  164.                 , x => x.ErpCode
  165.                 , x => x.Description
  166.                 , x => x.CompanyCode
  167.                 , x => x.Active
  168.             );
  169.     }
  170.     else if (modelType == typeof(CategoryViewModel))
  171.     {
  172.         auxMap =
  173.             CSVMapper.RawMap<CategoryViewModel>(
  174.                 x => x.CategoryCode
  175.                 , x => x.ErpCode
  176.                 , x => x.Description
  177.                 , x => x.CompanyCode
  178.                 , x => x.Active
  179.             );
  180.     }
  181.     else if (modelType == typeof(AccountTypeViewModel))
  182.     {
  183.         auxMap =
  184.             CSVMapper.RawMap<AccountTypeViewModel>(
  185.                 x => x.AccountTypeCode
  186.                 , x => x.ErpCode
  187.                 , x => x.Description
  188.                 , x => x.CompanyCode
  189.                 , x => x.Active
  190.             );
  191.     }
  192.     else if (modelType == typeof(CurrentAccountTypeViewModel))
  193.     {
  194.         auxMap =
  195.             CSVMapper.RawMap<CurrentAccountTypeViewModel>(
  196.                 x => x.CurrentAccountTypeCode
  197.                 , x => x.AccountTypeCode
  198.                 , x => x.ErpCode
  199.                 , x => x.Description
  200.                 , x => x.CompanyCode
  201.                 , x => x.Active
  202.             );
  203.     }
  204.     else if (modelType == typeof(MaritalsViewModel))
  205.     {
  206.         auxMap =
  207.             CSVMapper.RawMap<MaritalsViewModel>(
  208.                 x => x.MaritalCode
  209.                 , x => x.IrsMaritalCode
  210.                 , x => x.ErpCode
  211.                 , x => x.Description
  212.                 , x => x.CompanyCode
  213.                 , x => x.Active
  214.             );
  215.     }
  216.     else if (modelType == typeof(IRSMaritalsViewModel))
  217.     {
  218.         auxMap =
  219.             CSVMapper.RawMap<IRSMaritalsViewModel>(
  220.                 x => x.IrsMaritalCode
  221.                 , x => x.ErpCode
  222.                 , x => x.Description
  223.                 , x => x.CompanyCode
  224.                 , x => x.Active
  225.             );
  226.     }
  227.     else if (modelType == typeof(CitiesViewModel))
  228.     {
  229.         auxMap =
  230.             CSVMapper.RawMap<CitiesViewModel>(
  231.                 x => x.CityCode
  232.                 , x => x.ErpCode
  233.                 , x => x.Description
  234.                 , x => x.CountryCode
  235.                 , x => x.Active
  236.             );
  237.     }
  238.     else if (modelType == typeof(BankListViewModel))
  239.     {
  240.         auxMap =
  241.             CSVMapper.RawMap<BankListViewModel>(
  242.                  x => x.BankCode
  243.                 , x => x.SwiftCode
  244.                 , x => x.ErpCode
  245.                 , x => x.Description
  246.                 , x => x.CompanyCode
  247.                 , x => x.Active
  248.             );
  249.     }
  250.  
  251.     Type type = typeof(Expression<Func<TModel, dynamic>>[]);
  252.     map = (Expression<Func<TModel, dynamic>>[])Convert.ChangeType(auxMap, type);
  253.  
  254.     return map;
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement