From c77b96073a13c70122d782fcb40240aee2a8c37b Mon Sep 17 00:00:00 2001 From: Bruno de Souza Melo Date: Mon, 27 Feb 2023 00:50:17 -0300 Subject: [PATCH] Initial version. --- .editorconfig | 7 ++ .gitignore | 52 +++++---------- LICENSE | 8 ++- NuvTools.AspNetCore.sln | 44 +++++++++++++ README.md | 11 +++- docs/Publishing.txt | 2 + icon.png | Bin 0 -> 2168 bytes .../ApplicationBuilderExtensions.cs | 20 ++++++ .../Mapper/ServiceWithCrudBase.cs | 57 ++++++++++++++++ ...ools.AspNetCore.EntityFrameworkCore.csproj | 54 +++++++++++++++ ...uvTools.AspNetCore.EntityFrameworkCore.snk | Bin 0 -> 596 bytes .../JSInterop/ClipboardService.cs | 31 +++++++++ .../Mapper/ServiceWithMapperBase.cs | 62 ++++++++++++++++++ .../NuvTools.AspNetCore.csproj | 57 ++++++++++++++++ .../NuvTools.AspNetCore.snk | Bin 0 -> 596 bytes .../WebUtilities/ObjectExtensions.cs | 30 +++++++++ 16 files changed, 395 insertions(+), 40 deletions(-) create mode 100644 .editorconfig create mode 100644 NuvTools.AspNetCore.sln create mode 100644 docs/Publishing.txt create mode 100644 icon.png create mode 100644 src/NuvTools.AspNetCore.EntityFrameworkCore/Extensions/ApplicationBuilderExtensions.cs create mode 100644 src/NuvTools.AspNetCore.EntityFrameworkCore/Mapper/ServiceWithCrudBase.cs create mode 100644 src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.csproj create mode 100644 src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.snk create mode 100644 src/NuvTools.AspNetCore/JSInterop/ClipboardService.cs create mode 100644 src/NuvTools.AspNetCore/Mapper/ServiceWithMapperBase.cs create mode 100644 src/NuvTools.AspNetCore/NuvTools.AspNetCore.csproj create mode 100644 src/NuvTools.AspNetCore/NuvTools.AspNetCore.snk create mode 100644 src/NuvTools.AspNetCore/WebUtilities/ObjectExtensions.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..49ac99c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*.cs] + +# CS1591: Missing XML comment for publicly visible type or member +dotnet_diagnostic.CS1591.severity = none + +# IDE0063: Use simple 'using' statement +dotnet_diagnostic.IDE0063.severity = none diff --git a/.gitignore b/.gitignore index dfcfd56..3e759b7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files -*.rsuser *.suo *.user *.userosscache @@ -13,9 +12,6 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs -# Mono auto generated files -mono_crash.* - # Build results [Dd]ebug/ [Dd]ebugPublic/ @@ -23,13 +19,10 @@ mono_crash.* [Rr]eleases/ x64/ x86/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ -[Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ @@ -43,10 +36,9 @@ Generated\ Files/ [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -# NUnit +# NUNIT *.VisualState.xml TestResult.xml -nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ @@ -60,6 +52,7 @@ BenchmarkDotNet.Artifacts/ project.lock.json project.fragment.lock.json artifacts/ +**/Properties/launchSettings.json # StyleCop StyleCopReport.xml @@ -67,7 +60,7 @@ StyleCopReport.xml # Files built by Visual Studio *_i.c *_p.c -*_h.h +*_i.h *.ilk *.meta *.obj @@ -84,7 +77,6 @@ StyleCopReport.xml *.tlh *.tmp *.tmp_proj -*_wpftmp.csproj *.log *.vspscc *.vssscc @@ -127,6 +119,9 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +# JustCode is a .NET coding add-in +.JustCode + # TeamCity is a build add-in _TeamCity* @@ -184,8 +179,6 @@ PublishScripts/ # NuGet Packages *.nupkg -# NuGet Symbol Packages -*.snupkg # The packages folder can be ignored because of Package Restore **/[Pp]ackages/* # except build/, which is used as an MSBuild target. @@ -210,14 +203,12 @@ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt *.appx -*.appxbundle -*.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache -!?*.[Cc]ache/ +!*.[Cc]ache/ # Others ClientBin/ @@ -230,7 +221,7 @@ ClientBin/ *.publishsettings orleans.codegen.cs -# Including strong name files can present a security risk +# Including strong name files can present a security risk # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk @@ -261,9 +252,6 @@ ServiceFabricBackup/ *.bim.layout *.bim_*.settings *.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ @@ -299,8 +287,12 @@ paket-files/ # FAKE - F# Make .fake/ -# CodeRush personal settings -.cr/personal +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ # Python Tools for Visual Studio (PTVS) __pycache__/ @@ -325,7 +317,7 @@ __pycache__/ # OpenCover UI analysis results OpenCover/ -# Azure Stream Analytics local run output +# Azure Stream Analytics local run output ASALocalRun/ # MSBuild Binary and Structured Log @@ -334,17 +326,5 @@ ASALocalRun/ # NVidia Nsight GPU debugger configuration file *.nvuser -# MFractors (Xamarin productivity tool) working folder +# MFractors (Xamarin productivity tool) working folder .mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ diff --git a/LICENSE b/LICENSE index 03986f2..028c4d9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2023 Nuv Tools +Copyright (c) Nuv Tools + +All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/NuvTools.AspNetCore.sln b/NuvTools.AspNetCore.sln new file mode 100644 index 0000000..05f37d4 --- /dev/null +++ b/NuvTools.AspNetCore.sln @@ -0,0 +1,44 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFE8529B-55C4-4E15-B937-A6FEE1E9C5BA}" + ProjectSection(SolutionItems) = preProject + docs\Publishing.txt = docs\Publishing.txt + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0553FC7C-D8CC-444A-970D-CB3B064020F5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{3BD96AEC-23A5-44DF-ABBE-82E683AB587E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuvTools.AspNetCore", "src\NuvTools.AspNetCore\NuvTools.AspNetCore.csproj", "{77571ABE-3EF7-403F-ACCC-68B539B02AB6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuvTools.AspNetCore.EntityFrameworkCore", "src\NuvTools.AspNetCore.EntityFrameworkCore\NuvTools.AspNetCore.EntityFrameworkCore.csproj", "{A4C3BE0D-A233-4026-9AE9-8B1395418E1A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77571ABE-3EF7-403F-ACCC-68B539B02AB6}.Release|Any CPU.Build.0 = Release|Any CPU + {A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4C3BE0D-A233-4026-9AE9-8B1395418E1A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {77571ABE-3EF7-403F-ACCC-68B539B02AB6} = {0553FC7C-D8CC-444A-970D-CB3B064020F5} + {A4C3BE0D-A233-4026-9AE9-8B1395418E1A} = {0553FC7C-D8CC-444A-970D-CB3B064020F5} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BF8E6A9B-D224-46ED-9C99-E6DD796B4CC9} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index c19b44b..c0836e1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -# nuvtools-aspnetcore +# Nuv Tools ASP.NET Core Libraries + Libraries with helpers to use with ASP.NET Aplications. + +## NuvTools.AspNetCore + +Common library with helpers to use with ASP.NET Aplications. + +## NuvTools.AspNetCore.EntityFramework + +EntityFramework Core helper library to use with ASP.NET Aplications. \ No newline at end of file diff --git a/docs/Publishing.txt b/docs/Publishing.txt new file mode 100644 index 0000000..1ccade0 --- /dev/null +++ b/docs/Publishing.txt @@ -0,0 +1,2 @@ +nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.AspNetCore.7.0.0.nupkg +nuget.exe push -Source "nuvtools" -ApiKey az NuvTools.AspNetCore.EntityFrameworkCore.7.0.0.nupkg \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..526b425e613dced6a963faaea5af7189cd5aa635 GIT binary patch literal 2168 zcmV-;2#5EHP)a<0O$pP zs{qiK?&!478xn(3L#2NNI-P3(lb~Gq}yXXgBj~_P2~YqH$&Lw1ygEPuG$ng=P{KR` z3ZOAY=$?+*28Aeq&Jd3Q)wMHL9jPF|&n}2TS=hAkObbXV2r%b$bE;$1)IUGnsXzq* z4!a-*rJ+^TMrOsM7mBsP^#bGyCBJn+C`v*rsvx!G0mwAoSLb=-ix&&qpvoX{cdmjK zu|YohKs?!hq793_Dg19G1jzLQ?JfvK848onptX%Pg}s0>mx1Y?ZdN&Af`tlzavaHq>~-pRdaQuG~Zr+fJ44>0S;1Z=wj3nJxKQ zhzF>@rYrxe>&wDt!?SjC3jnkMKrH~YqEPT^XB;*^v8ER})R0T+YRrtIXi|E;Ni0#E>T zaguxntqxTH3ZN!Vlb?lnz_abE4irE!xFkQ1uktw*Kq0s$pJ7%kLje?ld-B<9211Kb z00j_{{45?XK>=Kju;jDXuJoe-ZboGC^Pm7OMMm-g1#l;_lF#s}`4;I54c6DEB_*HX z9o@BRo0Auyl%5Xmy@c!XoG_xp!(?m(GQoN&$MgC^RkoHMi*P9M@#B!O(y?^H`YDsj z91QNgB=qKny5qTd`|~720&ZgfVtT5~>dJK$wf=Ks`&RcxJDa)O#cIC7Bp}gY;jI@k z2s8r~t!AL&a&*_K^&(z>z92&aVOIgHNAT5Dov-iUgGnf5q%up5ha0?i6GPOYl(I?3%ld>d_jZ+(q;mQ&-Px`6>V<(2m(8n0gtA z5@^Rv5)_{YKnb*CItiwq2to<8qnHFU&jg|b+EFOM>{G!gfp*+2L1}9ND1mn5B`AF{ z2qn;ttOT|ig%W6o{pDbkKr70t2S5q5q5Ognlt2*ly3C_Fs|Z2~xMLmP_k+yiIWGxA z3AjTiqBmq6i%(4;O2C(7{H&})@hb{N3AkY$+r1T1$&`#^@vRC*3AjO{!*9zt4*#-n zlzWbkXz#}TtH043l8I~CCAkkF^6i`y825^%x#Zf6_4b@KpZ(n6l@C3a^J zO27r{`#sy~@QtQyZ@_tQC_Xbe2{J?Y>}MxfC-+~=Js%OwO*_|v$GZUxQs?w_<$N@A z5|D|coZDY&PHwi4%Z#D4&7m}&gv>-j{GAUGTSyUrP9%UvMlmxkM7RK$e0L*M08GC7 zA&^Q72@;d9285>4+!q}%`Rc#~i1CaTldl#`0B)CNn0)mhnMCSG9#LcR)r9o`UpkE( zldmo$@Ye4asg=r<+X76!+GOVeGO^@PIjz9ttIur#CK3njwgi)}2L`3L>kO=8&r&zStOX&nqVIeIF)ET#y+dI2^wh{<=15`)5`6+za&!}~G$jtLEho7&wT zWKjVE9e;GD;+C{M>Ke1o?M<7uCNLeho}?KnWINJ4qRs71omPP0-b>f4vG|8_!_khA z+Z!}vRdCJji`!GNE>Hw#V)yC2G zaCUVNc=y60Yb>tJ`ZqEeF82qh?)>Y8#7Jxdo)Xl9+YKVvDWR(4Pe1DoaDb=|-0u*= zdV^#%)?`g2wWyod9U-@fVPk{p_xjc(A`?$D5wJ&aFO$l`MG@_6UPip+aAG9>a5`Z< zIG^6&#;yUw1z}8!6ansLFx=Dv0PVSAiPcgMJ_n!xGcXu#TAmZ3CHK`jXTb=(this IApplicationBuilder app) where TContext : DbContext + { + using var serviceScope = app.ApplicationServices.CreateScope(); + var context = serviceScope.ServiceProvider.GetService(); + if (context != null && context.Database != null) + { + context.Database.Migrate(); + } + + return app; + } +} \ No newline at end of file diff --git a/src/NuvTools.AspNetCore.EntityFrameworkCore/Mapper/ServiceWithCrudBase.cs b/src/NuvTools.AspNetCore.EntityFrameworkCore/Mapper/ServiceWithCrudBase.cs new file mode 100644 index 0000000..0a54846 --- /dev/null +++ b/src/NuvTools.AspNetCore.EntityFrameworkCore/Mapper/ServiceWithCrudBase.cs @@ -0,0 +1,57 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using NuvTools.AspNetCore.Mapper; +using NuvTools.Common.ResultWrapper; +using NuvTools.Data.EntityFrameworkCore.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +namespace NuvTools.AspNetCore.EntityFrameworkCore.Mapper; + +public abstract class ServiceWithCrudBase : ServiceWithMapperBase + where TForm : class + where TData : class + where TContext : DbContext +{ + protected readonly TContext Context; + + public ServiceWithCrudBase(TContext context, IMapper mapper) : base(mapper) + { + Context = context; + } + + public DbSet Dataset { get { return Context.Set(); } } + + public async Task FindAsync(TKey id) + { + return ConvertToForm(await Context.FindAsync(id)); + } + + public async Task FindAsync(object[] keys) + { + return ConvertToForm(await Context.FindAsync(keys)); + } + + public async Task> FindFromExpressionAsync(Expression>> expression) + { + return ConvertToForm(await Context.FromExpression(expression).ToListAsync()); + } + + public virtual async Task> AddAndSaveAsync(TForm model) + { + return await Context.AddAndSaveAsync(ConvertToData(model)); + } + + public virtual async Task UpdateAndSaveAsync(TKey id, TForm model) + { + return await Context.UpdateAndSaveAsync(ConvertToData(model), id); + } + + public virtual async Task RemoveAndSaveAsync(TKey id) + { + return await Context.RemoveAndSaveAsync(id); + } +} diff --git a/src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.csproj b/src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.csproj new file mode 100644 index 0000000..1377960 --- /dev/null +++ b/src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.csproj @@ -0,0 +1,54 @@ + + + + net6;net7 + true + Nuv Tools + Copyright © 2023 Nuv Tools + https://nuv.tools + True + NuvTools.AspNetCore.EntityFrameworkCore.snk + EntityFramework Core helper library to use with ASP.NET Aplications. + 7.0.0 + True + True + icon.png + False + True + LICENSE + https://github.com/nuvtools/nuvtools-aspnetcore + git + latest + README.md + Nuv Tools AspNetCore Entity Framework Core + true + + + + + + + + + + + icon.png + True + + + + LICENSE + True + + + + True + \ + + + + + + + + diff --git a/src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.snk b/src/NuvTools.AspNetCore.EntityFrameworkCore/NuvTools.AspNetCore.EntityFrameworkCore.snk new file mode 100644 index 0000000000000000000000000000000000000000..510ac2e522a7af6f1a1f70d9b559ba8979e503e9 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50097{m9}lg4~}~pq)~kyZE?)VdU(VkUrO-l zj%nJx%qZPqb4tlo^dpGu3Wlp{FI$EDvML3xk12J4yD35CE}Vr&&EH+uxlR9HCAufJhUwHIjQnO*+-5xnDwk z#&PO%6+bob6A;HUo1qq3B%p(y7Yz&hfB?yEM$VV};1ZXvx!VlJGd;NO|V<4wR2}*iLzIMNu1xfYnJfZ2^ZCmJ4 zE5iWs0zZL7t`5P|_rM#Mss!e(rX`uIl~$@=y(u}a zk3Ao95L>&v>Ct}gvDb>NHCU_TN ReadTextAsync() + { + return _jsRuntime.InvokeAsync("navigator.clipboard.readText"); + } + + public ValueTask WriteTextAsync(string text) + { + try + { + return _jsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } +} diff --git a/src/NuvTools.AspNetCore/Mapper/ServiceWithMapperBase.cs b/src/NuvTools.AspNetCore/Mapper/ServiceWithMapperBase.cs new file mode 100644 index 0000000..ac0496b --- /dev/null +++ b/src/NuvTools.AspNetCore/Mapper/ServiceWithMapperBase.cs @@ -0,0 +1,62 @@ +using AutoMapper; + +namespace NuvTools.AspNetCore.Mapper; + +public abstract class ServiceWithMapperBase where TForm : class + where TData : class +{ + private readonly IMapper _mapper; + + protected IMapper Mapper + { + get + { + return _mapper; + } + } + + public ServiceWithMapperBase(IMapper mapper) + { + _mapper = mapper; + } + + #region Converter + + protected TReturn ConvertTo(TData model) + { + return _mapper.Map(model); + } + + protected IEnumerable ConvertTo(IEnumerable models) + { + return _mapper.Map>(models); + } + + protected TData ConvertToData(TForm model) + { + return _mapper.Map(model); + } + + protected TForm ConvertToForm(TData model) + { + return _mapper.Map(model); + } + + protected IEnumerable ConvertToForm(IEnumerable models) + { + return _mapper.Map>(models); + } + + protected IList ConvertToForm(IList models) + { + return _mapper.Map>(models); + } + + protected TForm[] ConvertToForm(TData[] models) + { + return _mapper.Map(models); + } + + #endregion + +} diff --git a/src/NuvTools.AspNetCore/NuvTools.AspNetCore.csproj b/src/NuvTools.AspNetCore/NuvTools.AspNetCore.csproj new file mode 100644 index 0000000..1e10c03 --- /dev/null +++ b/src/NuvTools.AspNetCore/NuvTools.AspNetCore.csproj @@ -0,0 +1,57 @@ + + + + net6;net7 + true + Nuv Tools + Copyright © 2023 Nuv Tools + https://nuv.tools + True + NuvTools.AspNetCore.snk + Common library with helpers to use with ASP.NET Aplications. + 7.0.0 + True + True + icon.png + False + True + LICENSE + https://github.com/nuvtools/nuvtools-aspnetcore + git + latest + README.md + Nuv Tools AspNetCore + true + + + + + icon.png + True + + + + LICENSE + True + + + + True + \ + + + + + + + + + + + + + + + + + diff --git a/src/NuvTools.AspNetCore/NuvTools.AspNetCore.snk b/src/NuvTools.AspNetCore/NuvTools.AspNetCore.snk new file mode 100644 index 0000000000000000000000000000000000000000..8f246f8e4d0db52d476dc6e7086cc5689cf1afa0 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50097D7E5YOzpiU^weS;f1!#5}TT z1e3dFz#JjY>5kQ+{S}f9Nh#fhuKYuYA@*DgPm@%Ke>}(pK^ocBF$(V>bqN9}s+Y72 z-3g+c1hu9D#!U06^pB2yeND3aQ}sWbDJ|=KFrqo9gAXlGz~kfs+(Ja43v$C=7`Sjp5sSw^Ju+MV_OOQ&^cAh9=gr580FWWFqFwYU(sIX8 zTzWrl<~`t-7HF0prbubAa$%bc!5r_By*jnFrzo13Y%UoIReg~)ihsn&OoZKeTCEM; zBgbBu_+0~%GVr}l`-Y{vyn3xu3dcEVJ>>>p!|T$XIR-e=Kf~sgL6^3v;j;|pQyuvK z;&()MtI|)ZC56odI8=^=#h8(d@iF{>JQEEDg^@+@7o&>m_GI7Xh*Ai&9Vn1@in!^# z%=W@LgQeuT+Ta~Yu~`pjJ5M^J%z4NCR!`{2Cxiy5Lq=@rX0k)>VCk7;Vr4vS%y^@9 z##xpRgS_^^@LX&NYRxADL{{&D-WyyulR=s)x606>}r)a|OiXL1R2>N=x1PxxfI5-TMD literal 0 HcmV?d00001 diff --git a/src/NuvTools.AspNetCore/WebUtilities/ObjectExtensions.cs b/src/NuvTools.AspNetCore/WebUtilities/ObjectExtensions.cs new file mode 100644 index 0000000..9a153b1 --- /dev/null +++ b/src/NuvTools.AspNetCore/WebUtilities/ObjectExtensions.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.WebUtilities; +using System.Globalization; + +namespace NuvTools.AspNetCore.WebUtilities; + +public static class ObjectExtensions +{ + public static string GetQueryString(this T value, string uriBase) where T : class + { + var properties = from p in value.GetType().GetProperties() + where p.GetValue(value, null) != null + select + new + { + p.Name, + Value = p.GetValue(value, null).GetType() == typeof(DateTime) ? + ((DateTime)p.GetValue(value, null)).ToString("yyyy-MM-ddThh:mm:ss", CultureInfo.InvariantCulture) + : p.GetValue(value, null).ToString() + }; + + //2021-11-12T00:25:15.723Z + //yyyy-MM-ddThh:mm:ss.zzz + var queryString = properties.ToDictionary(a => a.Name, b => b.Value); + + if (queryString.Count == 0) + return uriBase; + + return QueryHelpers.AddQueryString(uriBase, queryString); + } +}