├── .config └── dotnet-tools.json ├── .gitattributes ├── .gitignore ├── Container ├── CustomerService.cs ├── EmailService.cs ├── RefreshHandler.cs ├── UserRoleService.cs └── UserService.cs ├── Controllers ├── AssociateController.cs ├── AuthorizeController.cs ├── CustomerController.cs ├── ProductController.cs ├── UserController.cs ├── UserRoleController.cs └── WeatherForecastController.cs ├── Helper ├── APIResponse.cs ├── AutoMapperHandler.cs └── BasicAuthenticationHandler.cs ├── LearnAPI.csproj ├── LearnAPI.sln ├── Modal ├── Appmenucs.cs ├── Customermodal.cs ├── EmailSettings.cs ├── JwtSettings.cs ├── Mailrequest.cs ├── Menupermission.cs ├── TokenResponse.cs ├── UserCred.cs ├── UserModel.cs └── UserRegister.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Repos ├── LearndataContext.cs └── Models │ ├── TblCustomer.cs │ ├── TblMenu.cs │ ├── TblOtpManager.cs │ ├── TblProduct.cs │ ├── TblProductimage.cs │ ├── TblPwdManger.cs │ ├── TblRefreshtoken.cs │ ├── TblRole.cs │ ├── TblRolemenumap.cs │ ├── TblRolepermission.cs │ ├── TblSubtable.cs │ ├── TblTempuser.cs │ └── TblUser.cs ├── Service ├── ICustomerService.cs ├── IEmailService.cs ├── IRefreshHandler.cs ├── IUserRoleServicecs.cs └── IUserService.cs ├── WeatherForecast.cs ├── appsettings.Development.json ├── appsettings.json └── wwwroot └── Export └── customerinfo.xlsx /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "7.0.5", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /Container/CustomerService.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using LearnAPI.Helper; 3 | using LearnAPI.Modal; 4 | using LearnAPI.Repos; 5 | using LearnAPI.Repos.Models; 6 | using LearnAPI.Service; 7 | using Microsoft.EntityFrameworkCore; 8 | using static System.Runtime.InteropServices.JavaScript.JSType; 9 | 10 | namespace LearnAPI.Container 11 | { 12 | public class CustomerService : ICustomerService 13 | { 14 | private readonly LearndataContext context; 15 | private readonly IMapper mapper; 16 | private readonly ILogger logger; 17 | public CustomerService(LearndataContext context,IMapper mapper,ILogger logger) { 18 | this.context = context; 19 | this.mapper = mapper; 20 | this.logger = logger; 21 | } 22 | 23 | public async Task Create(Customermodal data) 24 | { 25 | APIResponse response = new APIResponse(); 26 | try 27 | { 28 | this.logger.LogInformation("Create Begins"); 29 | TblCustomer _customer = this.mapper.Map(data); 30 | await this.context.TblCustomers.AddAsync(_customer); 31 | await this.context.SaveChangesAsync(); 32 | response.ResponseCode = 201; 33 | response.Result = "pass"; 34 | } 35 | catch(Exception ex) 36 | { 37 | response.ResponseCode = 400; 38 | response.Message = ex.Message; 39 | this.logger.LogError(ex.Message,ex); 40 | } 41 | return response; 42 | } 43 | 44 | public async Task> Getall() 45 | { 46 | List _response=new List(); 47 | var _data = await this.context.TblCustomers.ToListAsync(); 48 | if(_data != null ) 49 | { 50 | _response=this.mapper.Map,List>(_data); 51 | } 52 | return _response; 53 | } 54 | 55 | public async Task Getbycode(string code) 56 | { 57 | Customermodal _response = new Customermodal(); 58 | var _data = await this.context.TblCustomers.FindAsync(code); 59 | if (_data != null) 60 | { 61 | _response = this.mapper.Map(_data); 62 | } 63 | return _response; 64 | } 65 | 66 | public async Task Remove(string code) 67 | { 68 | APIResponse response = new APIResponse(); 69 | try 70 | { 71 | var _customer = await this.context.TblCustomers.FindAsync(code); 72 | if(_customer != null) 73 | { 74 | this.context.TblCustomers.Remove(_customer); 75 | await this.context.SaveChangesAsync(); 76 | response.ResponseCode = 200; 77 | response.Result = "pass"; 78 | } 79 | else 80 | { 81 | response.ResponseCode = 404; 82 | response.Message = "Data not found"; 83 | } 84 | 85 | } 86 | catch (Exception ex) 87 | { 88 | response.ResponseCode = 400; 89 | response.Message = ex.Message; 90 | } 91 | return response; 92 | } 93 | 94 | public async Task Update(Customermodal data, string code) 95 | { 96 | APIResponse response = new APIResponse(); 97 | try 98 | { 99 | var _customer = await this.context.TblCustomers.FindAsync(code); 100 | if (_customer != null) 101 | { 102 | _customer.Name = data.Name; 103 | _customer.Email = data.Email; 104 | _customer.Phone=data.Phone; 105 | _customer.IsActive=data.IsActive; 106 | _customer.Creditlimit = data.Creditlimit; 107 | await this.context.SaveChangesAsync(); 108 | response.ResponseCode = 200; 109 | response.Result = "pass"; 110 | } 111 | else 112 | { 113 | response.ResponseCode = 404; 114 | response.Message = "Data not found"; 115 | } 116 | 117 | } 118 | catch (Exception ex) 119 | { 120 | response.ResponseCode = 400; 121 | response.Message = ex.Message; 122 | } 123 | return response; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Container/EmailService.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Modal; 2 | using LearnAPI.Service; 3 | using MailKit.Net.Smtp; 4 | using MailKit.Security; 5 | using Microsoft.Extensions.Options; 6 | using MimeKit; 7 | 8 | namespace LearnAPI.Container 9 | { 10 | public class EmailService : IEmailService 11 | { 12 | private readonly EmailSettings emailSettings; 13 | public EmailService(IOptions options) { 14 | this.emailSettings = options.Value; 15 | } 16 | public async Task SendEmail(Mailrequest mailrequest) 17 | { 18 | var email = new MimeMessage(); 19 | email.Sender = MailboxAddress.Parse(emailSettings.Email); 20 | email.To.Add(MailboxAddress.Parse(mailrequest.Email)); 21 | email.Subject=mailrequest.Subject; 22 | var builder=new BodyBuilder(); 23 | builder.HtmlBody = mailrequest.Emailbody; 24 | email.Body = builder.ToMessageBody(); 25 | 26 | using var smptp = new SmtpClient(); 27 | smptp.Connect(emailSettings.Host, emailSettings.Port,SecureSocketOptions.StartTls); 28 | smptp.Authenticate(emailSettings.Email, emailSettings.Password); 29 | await smptp.SendAsync(email); 30 | smptp.Disconnect(true); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Container/RefreshHandler.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Repos; 2 | using LearnAPI.Repos.Models; 3 | using LearnAPI.Service; 4 | using Microsoft.EntityFrameworkCore; 5 | using System.Security.Cryptography; 6 | 7 | namespace LearnAPI.Container 8 | { 9 | public class RefreshHandler : IRefreshHandler 10 | { 11 | private readonly LearndataContext context; 12 | public RefreshHandler(LearndataContext context) { 13 | this.context = context; 14 | } 15 | public async Task GenerateToken(string username) 16 | { 17 | var randomnumber = new byte[32]; 18 | using(var randomnumbergenerator= RandomNumberGenerator.Create()) 19 | { 20 | randomnumbergenerator.GetBytes(randomnumber); 21 | string refreshtoken=Convert.ToBase64String(randomnumber); 22 | var Existtoken = this.context.TblRefreshtokens.FirstOrDefaultAsync(item=>item.Userid==username).Result; 23 | if (Existtoken != null) 24 | { 25 | Existtoken.Refreshtoken = refreshtoken; 26 | } 27 | else 28 | { 29 | await this.context.TblRefreshtokens.AddAsync(new TblRefreshtoken 30 | { 31 | Userid=username, 32 | Tokenid= new Random().Next().ToString(), 33 | Refreshtoken=refreshtoken 34 | }); 35 | } 36 | await this.context.SaveChangesAsync(); 37 | 38 | return refreshtoken; 39 | 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Container/UserRoleService.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Helper; 2 | using LearnAPI.Modal; 3 | using LearnAPI.Repos; 4 | using LearnAPI.Repos.Models; 5 | using LearnAPI.Service; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | namespace LearnAPI.Container 9 | { 10 | public class UserRoleService : IUserRoleServicecs 11 | { 12 | private readonly LearndataContext context; 13 | public UserRoleService(LearndataContext learndata) { 14 | this.context = learndata; 15 | } 16 | public async Task AssignRolePermission(List _data) 17 | { 18 | APIResponse response = new APIResponse(); 19 | int processcount = 0; 20 | try 21 | { 22 | using(var dbtransaction=await this.context.Database.BeginTransactionAsync()) 23 | { 24 | if (_data.Count > 0) 25 | { 26 | _data.ForEach(item => 27 | { 28 | var userdata = this.context.TblRolepermissions.FirstOrDefault(item1 => item1.Userrole == item.Userrole && 29 | item1.Menucode == item.Menucode); 30 | if(userdata != null ) 31 | { 32 | userdata.Haveview = item.Haveview; 33 | userdata.Haveadd = item.Haveadd; 34 | userdata.Havedelete= item.Havedelete; 35 | userdata.Haveedit= item.Haveedit; 36 | processcount++; 37 | } 38 | else 39 | { 40 | this.context.TblRolepermissions.Add(item); 41 | processcount++; 42 | 43 | } 44 | 45 | }); 46 | 47 | if (_data.Count == processcount) 48 | { 49 | await this.context.SaveChangesAsync(); 50 | await dbtransaction.CommitAsync(); 51 | response.Result = "pass"; 52 | response.Message = "Saved successfully."; 53 | } 54 | else 55 | { 56 | await dbtransaction.RollbackAsync(); 57 | } 58 | 59 | } 60 | else 61 | { 62 | response.Result = "fail"; 63 | response.Message = "Failed"; 64 | } 65 | } 66 | 67 | } 68 | catch(Exception ex) 69 | { 70 | response = new APIResponse(); 71 | } 72 | 73 | return response; 74 | } 75 | 76 | public async Task> GetAllMenus() 77 | { 78 | return await this.context.TblMenus.ToListAsync(); 79 | } 80 | 81 | public async Task> GetAllRoles() 82 | { 83 | return await this.context.TblRoles.ToListAsync(); 84 | } 85 | 86 | public async Task> GetAllMenubyrole(string userrole) 87 | { 88 | List appmenus = new List(); 89 | 90 | var accessdata = (from menu in this.context.TblRolepermissions.Where(o => o.Userrole == userrole && o.Haveview) 91 | join m in this.context.TblMenus on menu.Menucode equals m.Code into _jointable 92 | from p in _jointable.DefaultIfEmpty() 93 | select new { code = menu.Menucode, name = p.Name }).ToList(); 94 | if (accessdata.Any()) 95 | { 96 | accessdata.ForEach(item => 97 | { 98 | appmenus.Add(new Appmenu() 99 | { 100 | code = item.code, 101 | Name = item.name 102 | }); 103 | }); 104 | } 105 | 106 | return appmenus; 107 | } 108 | 109 | public async Task GetMenupermissionbyrole(string userrole, string menucode) 110 | { 111 | Menupermission menupermission =new Menupermission(); 112 | var _data = await this.context.TblRolepermissions.FirstOrDefaultAsync(o => o.Userrole == userrole && o.Haveview 113 | && o.Menucode == menucode); 114 | if (_data != null) 115 | { 116 | menupermission.code = _data.Menucode; 117 | menupermission.Haveview = _data.Haveview; 118 | menupermission.Haveadd = _data.Haveadd; 119 | menupermission.Haveedit = _data.Haveedit; 120 | menupermission.Havedelete = _data.Havedelete; 121 | } 122 | return menupermission; 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Container/UserService.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using DocumentFormat.OpenXml.Wordprocessing; 3 | using LearnAPI.Helper; 4 | using LearnAPI.Modal; 5 | using LearnAPI.Repos; 6 | using LearnAPI.Repos.Models; 7 | using LearnAPI.Service; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | namespace LearnAPI.Container 11 | { 12 | public class UserService : IUserService 13 | { 14 | private readonly LearndataContext context; 15 | private readonly IMapper mapper; 16 | private readonly IEmailService emailService; 17 | public UserService(LearndataContext learndata, IMapper mapper, IEmailService emailService) 18 | { 19 | this.context = learndata; 20 | this.mapper = mapper; 21 | this.emailService = emailService; 22 | } 23 | public async Task ConfirmRegister(int userid, string username, string otptext) 24 | { 25 | APIResponse response = new APIResponse(); 26 | bool otpresponse= await ValidateOTP(username,otptext); 27 | if (!otpresponse) 28 | { 29 | response.Result = "fail"; 30 | response.Message = "Invalid OTP or Expired"; 31 | } 32 | else 33 | { 34 | var _tempdata = await this.context.TblTempusers.FirstOrDefaultAsync(item => item.Id == userid); 35 | var _user = new TblUser() 36 | { 37 | Username = username, 38 | Name = _tempdata.Name, 39 | Password = _tempdata.Password, 40 | Email = _tempdata.Email, 41 | Phone = _tempdata.Phone, 42 | Failattempt = 0, 43 | Isactive = true, 44 | Islocked = false, 45 | Role = "user" 46 | }; 47 | await this.context.TblUsers.AddAsync(_user); 48 | await this.context.SaveChangesAsync(); 49 | await UpdatePWDManager(username, _tempdata.Password); 50 | response.Result = "pass"; 51 | response.Message = "Registered successfully."; 52 | } 53 | 54 | return response; 55 | } 56 | 57 | public async Task UserRegisteration(UserRegister userRegister) 58 | { 59 | APIResponse response=new APIResponse(); 60 | int userid = 0; 61 | bool isvalid = true; 62 | 63 | try 64 | { 65 | // duplicate user 66 | var _user = await this.context.TblUsers.Where(item => item.Username == userRegister.UserName).ToListAsync(); 67 | if (_user.Count > 0) 68 | { 69 | isvalid = false; 70 | response.Result = "fail"; 71 | response.Message = "Duplicate username"; 72 | } 73 | 74 | // duplicate Email 75 | var _useremail = await this.context.TblUsers.Where(item => item.Email == userRegister.Email).ToListAsync(); 76 | if (_useremail.Count > 0) 77 | { 78 | isvalid = false; 79 | response.Result = "fail"; 80 | response.Message = "Duplicate Email"; 81 | } 82 | 83 | 84 | if (userRegister != null && isvalid) 85 | { 86 | var _tempuser = new TblTempuser() 87 | { 88 | Code = userRegister.UserName, 89 | Name = userRegister.Name, 90 | Email = userRegister.Email, 91 | Password= userRegister.Password, 92 | Phone = userRegister.Phone, 93 | }; 94 | await this.context.TblTempusers.AddAsync(_tempuser); 95 | await this.context.SaveChangesAsync(); 96 | userid = _tempuser.Id; 97 | string OTPText = Generaterandomnumber(); 98 | await UpdateOtp(userRegister.UserName, OTPText, "register"); 99 | await SendOtpMail(userRegister.Email, OTPText, userRegister.Name); 100 | response.Result = "pass"; 101 | response.Message = userid.ToString(); 102 | } 103 | 104 | }catch(Exception ex) 105 | { 106 | response.Result = "fail"; 107 | } 108 | 109 | return response; 110 | 111 | } 112 | 113 | public async Task ResetPassword(string username, string oldpassword, string newpassword) 114 | { 115 | APIResponse response = new APIResponse(); 116 | var _user = await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == username && 117 | item.Password == oldpassword && item.Isactive == true); 118 | if(_user != null) 119 | { 120 | var _pwdhistory = await Validatepwdhistory(username, newpassword); 121 | if (_pwdhistory) 122 | { 123 | response.Result = "fail"; 124 | response.Message = "Don't use the same password that used in last 3 transaction"; 125 | } 126 | else 127 | { 128 | _user.Password = newpassword; 129 | await this.context.SaveChangesAsync(); 130 | await UpdatePWDManager(username, newpassword); 131 | response.Result = "pass"; 132 | response.Message = "Password changed."; 133 | } 134 | } 135 | else 136 | { 137 | response.Result = "fail"; 138 | response.Message = "Failed to validate old password."; 139 | } 140 | return response; 141 | } 142 | 143 | public async Task ForgetPassword(string username) 144 | { 145 | APIResponse response = new APIResponse(); 146 | var _user=await this.context.TblUsers.FirstOrDefaultAsync(item=>item.Username==username && item.Isactive==true); 147 | if (_user != null) 148 | { 149 | string otptext = Generaterandomnumber(); 150 | await UpdateOtp(username, otptext,"forgetpassword"); 151 | await SendOtpMail(_user.Email, otptext, _user.Name); 152 | response.Result = "pass"; 153 | response.Message = "OTP sent"; 154 | 155 | } 156 | else 157 | { 158 | response.Result = "fail"; 159 | response.Message = "Invalid User"; 160 | } 161 | return response; 162 | } 163 | 164 | public async Task UpdatePassword(string username, string Password, string Otptext) 165 | { 166 | APIResponse response = new APIResponse(); 167 | 168 | bool otpvalidation = await ValidateOTP(username, Otptext); 169 | if (otpvalidation) 170 | { 171 | bool pwdhistory=await Validatepwdhistory(username, Password); 172 | if(pwdhistory) 173 | { 174 | response.Result = "fail"; 175 | response.Message = "Don't use the same password that used in last 3 transaction"; 176 | } 177 | else 178 | { 179 | var _user = await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == username && item.Isactive == true); 180 | if (_user != null) 181 | { 182 | _user.Password = Password; 183 | await this.context.SaveChangesAsync(); 184 | await UpdatePWDManager(username, Password); 185 | response.Result = "pass"; 186 | response.Message = "Password changed"; 187 | } 188 | } 189 | } 190 | else 191 | { 192 | response.Result = "fail"; 193 | response.Message = "Invalid OTP"; 194 | } 195 | return response; 196 | } 197 | private async Task UpdateOtp(string username,string otptext,string otptype) 198 | { 199 | var _opt = new TblOtpManager() 200 | { 201 | Username = username, 202 | Otptext = otptext, 203 | Expiration = DateTime.Now.AddMinutes(30), 204 | Createddate = DateTime.Now, 205 | Otptype = otptype 206 | }; 207 | await this.context.TblOtpManagers.AddAsync(_opt); 208 | await this.context.SaveChangesAsync(); 209 | } 210 | 211 | private async Task ValidateOTP(string username,string OTPText) 212 | { 213 | bool response = false; 214 | var _data=await this.context.TblOtpManagers.FirstOrDefaultAsync(item=>item.Username== username 215 | && item.Otptext==OTPText && item.Expiration>DateTime.Now); 216 | if (_data != null) 217 | { 218 | response = true; 219 | } 220 | return response; 221 | } 222 | 223 | private async Task UpdatePWDManager(string username, string password) 224 | { 225 | var _opt = new TblPwdManger() 226 | { 227 | Username = username, 228 | Password= password, 229 | ModifyDate=DateTime.Now 230 | }; 231 | await this.context.TblPwdMangers.AddAsync(_opt); 232 | await this.context.SaveChangesAsync(); 233 | } 234 | 235 | private string Generaterandomnumber() 236 | { 237 | Random random = new Random(); 238 | string randomno = random.Next(0, 1000000).ToString("D6"); 239 | return randomno; 240 | } 241 | 242 | private async Task SendOtpMail(string useremail,string OtpText,string Name) 243 | { 244 | var mailrequest = new Mailrequest(); 245 | mailrequest.Email = useremail; 246 | mailrequest.Subject = "Thanks for registering : OTP"; 247 | mailrequest.Emailbody = GenerateEmailBody(Name, OtpText); 248 | await this.emailService.SendEmail(mailrequest); 249 | 250 | } 251 | 252 | private string GenerateEmailBody(string name,string otptext) 253 | { 254 | string emailbody = "
"; 255 | emailbody += "

Hi " + name + ", Thanks for registering

"; 256 | emailbody += "

Please enter OTP text and complete the registeration

"; 257 | emailbody += "

OTP Text is :" + otptext + "

"; 258 | emailbody += "
"; 259 | 260 | return emailbody; 261 | } 262 | 263 | private async Task Validatepwdhistory(string Username, string password) 264 | { 265 | bool response=false; 266 | var _pwd = await this.context.TblPwdMangers.Where(item => item.Username == Username). 267 | OrderByDescending(p => p.ModifyDate).Take(3).ToListAsync(); 268 | if (_pwd.Count > 0) 269 | { 270 | var validate = _pwd.Where(o => o.Password == password); 271 | if (validate.Any()) 272 | { 273 | response = true; 274 | } 275 | } 276 | 277 | return response; 278 | 279 | } 280 | 281 | public async TaskUpdateStatus(string username, bool userstatus) 282 | { 283 | APIResponse response = new APIResponse(); 284 | var _user = await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == username); 285 | if(_user != null) 286 | { 287 | _user.Isactive = userstatus; 288 | await this.context.SaveChangesAsync(); 289 | response.Result = "pass"; 290 | response.Message = "User Status changed"; 291 | } 292 | else 293 | { 294 | response.Result = "fail"; 295 | response.Message = "Invalid User"; 296 | } 297 | return response; 298 | } 299 | 300 | public async Task UpdateRole(string username, string userrole) 301 | { 302 | APIResponse response = new APIResponse(); 303 | var _user = await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == username && item.Isactive == true); 304 | if (_user != null) 305 | { 306 | _user.Role = userrole; 307 | await this.context.SaveChangesAsync(); 308 | response.Result = "pass"; 309 | response.Message = "User Role changed"; 310 | } 311 | else 312 | { 313 | response.Result = "fail"; 314 | response.Message = "Invalid User"; 315 | } 316 | return response; 317 | } 318 | 319 | public async Task> Getall() 320 | { 321 | List _response = new List(); 322 | var _data = await this.context.TblUsers.ToListAsync(); 323 | if (_data != null) 324 | { 325 | _response = this.mapper.Map, List>(_data); 326 | } 327 | return _response; 328 | } 329 | public async Task Getbycode(string code) 330 | { 331 | UserModel _response = new UserModel(); 332 | var _data = await this.context.TblUsers.FindAsync(code); 333 | if (_data != null) 334 | { 335 | _response = this.mapper.Map(_data); 336 | } 337 | return _response; 338 | } 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /Controllers/AssociateController.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Repos; 2 | using LearnAPI.Repos.Models; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Data.SqlClient; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | namespace LearnAPI.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class AssociateController : ControllerBase 13 | { 14 | private readonly LearndataContext learndata; 15 | public AssociateController(LearndataContext context) { 16 | this.learndata = context; 17 | } 18 | 19 | [HttpGet("getall")] 20 | public async Task Getall() 21 | { 22 | string sqlquery = "exec sp_getcustomer"; 23 | var data = await this.learndata.TblCustomers.FromSqlRaw(sqlquery).ToListAsync(); 24 | if(data==null) 25 | { 26 | return NotFound(); 27 | } 28 | return Ok(data); 29 | 30 | } 31 | 32 | [HttpGet("Getallcustom")] 33 | public async Task Getallcustom() 34 | { 35 | string sqlquery = "exec sp_getcustomer_custom"; 36 | var data = await this.learndata.customerdetail.FromSqlRaw(sqlquery).ToListAsync(); 37 | if (data == null) 38 | { 39 | return NotFound(); 40 | } 41 | return Ok(data); 42 | 43 | } 44 | 45 | [HttpGet("Getallcustomq")] 46 | public async Task Getallcustomq() 47 | { 48 | string sqlquery = "Select *,'Active' as Statusname from tbl_customer"; 49 | var data = await this.learndata.customerdetail.FromSqlRaw(sqlquery).ToListAsync(); 50 | if (data == null) 51 | { 52 | return NotFound(); 53 | } 54 | return Ok(data); 55 | 56 | } 57 | 58 | [HttpGet("getbycode")] 59 | public async Task getbycode(string code) 60 | { 61 | string sqlquery = "Select *,'Active' as Statusname from tbl_customer where code=@code"; 62 | SqlParameter parameter = new SqlParameter("@code", code); 63 | var data = await this.learndata.customerdetail.FromSqlRaw(sqlquery, parameter).FirstOrDefaultAsync(); 64 | if (data == null) 65 | { 66 | return NotFound(); 67 | } 68 | return Ok(data); 69 | 70 | } 71 | 72 | [HttpPost("create")] 73 | public async Task create(TblCustomer tblCustomer) 74 | { 75 | string sqlquery = "Insert Into tbl_customer values(@code,@name,@email,@phone,@creditlimit,@active,@taxcode)"; 76 | SqlParameter[] parameter = 77 | { 78 | new SqlParameter("@code",tblCustomer.Code), 79 | new SqlParameter("@name",tblCustomer.Name), 80 | new SqlParameter("@email",tblCustomer.Email), 81 | new SqlParameter("@phone",tblCustomer.Phone), 82 | new SqlParameter("@creditlimit",tblCustomer.Creditlimit), 83 | new SqlParameter("@active",tblCustomer.IsActive), 84 | new SqlParameter("@taxcode",tblCustomer.Taxcode) 85 | }; 86 | var data = await this.learndata.Database.ExecuteSqlRawAsync(sqlquery, parameter); 87 | return Ok(data); 88 | 89 | } 90 | 91 | [HttpPut("Update")] 92 | public async Task Update(string code,TblCustomer tblCustomer) 93 | { 94 | string sqlquery = "exec sp_createcustomer @code,@name,@email,@phone,@creditlimit,@active,@taxcode,@type"; 95 | SqlParameter[] parameter = 96 | { 97 | new SqlParameter("@code",code), 98 | new SqlParameter("@name",tblCustomer.Name), 99 | new SqlParameter("@email",tblCustomer.Email), 100 | new SqlParameter("@phone",tblCustomer.Phone), 101 | new SqlParameter("@creditlimit",tblCustomer.Creditlimit), 102 | new SqlParameter("@active",tblCustomer.IsActive), 103 | new SqlParameter("@taxcode",tblCustomer.Taxcode), 104 | new SqlParameter("@type","update") 105 | }; 106 | var data = await this.learndata.Database.ExecuteSqlRawAsync(sqlquery, parameter); 107 | return Ok(data); 108 | 109 | } 110 | 111 | [HttpDelete("delete")] 112 | public async Task delete(string code) 113 | { 114 | string sqlquery = "exec sp_deletecustomer @code"; 115 | SqlParameter[] parameter = 116 | { 117 | new SqlParameter("@code",code) 118 | }; 119 | var data = await this.learndata.Database.ExecuteSqlRawAsync(sqlquery, parameter); 120 | return Ok(data); 121 | 122 | } 123 | 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Controllers/AuthorizeController.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Modal; 2 | using LearnAPI.Repos; 3 | using LearnAPI.Service; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.EntityFrameworkCore; 7 | using Microsoft.Extensions.Options; 8 | using Microsoft.IdentityModel.Tokens; 9 | using System.IdentityModel.Tokens.Jwt; 10 | using System.Security.Claims; 11 | using System.Text; 12 | 13 | namespace LearnAPI.Controllers 14 | { 15 | [Route("api/[controller]")] 16 | [ApiController] 17 | public class AuthorizeController : ControllerBase 18 | { 19 | private readonly LearndataContext context; 20 | private readonly JwtSettings jwtSettings; 21 | private readonly IRefreshHandler refresh; 22 | public AuthorizeController(LearndataContext context,IOptions options,IRefreshHandler refresh) 23 | { 24 | this.context = context; 25 | this.jwtSettings = options.Value; 26 | this.refresh = refresh; 27 | } 28 | [HttpPost("GenerateToken")] 29 | public async Task GenerateToken([FromBody] UserCred userCred) 30 | { 31 | var user = await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == userCred.username && item.Password == userCred.password && item.Isactive==true); 32 | if (user != null) 33 | { 34 | //generate token 35 | var tokenhandler = new JwtSecurityTokenHandler(); 36 | var tokenkey = Encoding.UTF8.GetBytes(this.jwtSettings.securitykey); 37 | var tokendesc = new SecurityTokenDescriptor 38 | { 39 | Subject=new ClaimsIdentity(new Claim[] 40 | { 41 | new Claim(ClaimTypes.Name,user.Username), 42 | new Claim(ClaimTypes.Role,user.Role) 43 | }), 44 | Expires=DateTime.UtcNow.AddSeconds(3000), 45 | SigningCredentials=new SigningCredentials(new SymmetricSecurityKey(tokenkey),SecurityAlgorithms.HmacSha256) 46 | }; 47 | var token = tokenhandler.CreateToken(tokendesc); 48 | var finaltoken = tokenhandler.WriteToken(token); 49 | return Ok(new TokenResponse() { Token=finaltoken,RefreshToken= await this.refresh.GenerateToken(userCred.username),UserRole=user.Role}); 50 | 51 | } 52 | else 53 | { 54 | return Unauthorized(); 55 | } 56 | 57 | } 58 | 59 | [HttpPost("GenerateRefreshToken")] 60 | public async Task GenerateToken([FromBody] TokenResponse token) 61 | { 62 | var _refreshtoken = await this.context.TblRefreshtokens.FirstOrDefaultAsync(item => item.Refreshtoken == token.RefreshToken); 63 | if (_refreshtoken != null) 64 | { 65 | //generate token 66 | var tokenhandler = new JwtSecurityTokenHandler(); 67 | var tokenkey = Encoding.UTF8.GetBytes(this.jwtSettings.securitykey); 68 | SecurityToken securityToken; 69 | var principal = tokenhandler.ValidateToken(token.Token, new TokenValidationParameters() 70 | { 71 | ValidateIssuerSigningKey = true, 72 | IssuerSigningKey = new SymmetricSecurityKey(tokenkey), 73 | ValidateIssuer = false, 74 | ValidateAudience = false, 75 | 76 | }, out securityToken); 77 | 78 | var _token = securityToken as JwtSecurityToken; 79 | if(_token != null && _token.Header.Alg.Equals(SecurityAlgorithms.HmacSha256)) 80 | { 81 | string username = principal.Identity?.Name; 82 | var _existdata=await this.context.TblRefreshtokens.FirstOrDefaultAsync(item=>item.Userid==username 83 | && item.Refreshtoken==token.RefreshToken); 84 | if (_existdata != null) 85 | { 86 | var _newtoken = new JwtSecurityToken( 87 | claims:principal.Claims.ToArray(), 88 | expires:DateTime.Now.AddSeconds(30), 89 | signingCredentials:new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.jwtSettings.securitykey)), 90 | SecurityAlgorithms.HmacSha256) 91 | ); 92 | 93 | var _finaltoken = tokenhandler.WriteToken(_newtoken); 94 | return Ok(new TokenResponse() { Token = _finaltoken, RefreshToken = await this.refresh.GenerateToken(username),UserRole=token.UserRole }); 95 | } 96 | else 97 | { 98 | return Unauthorized(); 99 | } 100 | } 101 | else 102 | { 103 | return Unauthorized(); 104 | } 105 | 106 | //var tokendesc = new SecurityTokenDescriptor 107 | //{ 108 | // Subject = new ClaimsIdentity(new Claim[] 109 | // { 110 | // new Claim(ClaimTypes.Name,user.Code), 111 | // new Claim(ClaimTypes.Role,user.Role) 112 | // }), 113 | // Expires = DateTime.UtcNow.AddSeconds(30), 114 | // SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(tokenkey), SecurityAlgorithms.HmacSha256) 115 | //}; 116 | //var token = tokenhandler.CreateToken(tokendesc); 117 | //var finaltoken = tokenhandler.WriteToken(token); 118 | //return Ok(new TokenResponse() { Token = finaltoken, RefreshToken = await this.refresh.GenerateToken(userCred.username) }); 119 | 120 | } 121 | else 122 | { 123 | return Unauthorized(); 124 | } 125 | 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Controllers/CustomerController.cs: -------------------------------------------------------------------------------- 1 | using ClosedXML.Excel; 2 | using LearnAPI.Modal; 3 | using LearnAPI.Service; 4 | using Microsoft.AspNetCore.Authorization; 5 | using Microsoft.AspNetCore.Cors; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.AspNetCore.RateLimiting; 9 | using System.Data; 10 | 11 | namespace LearnAPI.Controllers 12 | { 13 | [Authorize] 14 | //[DisableCors] 15 | // [EnableRateLimiting("fixedwindow")] 16 | [Route("api/[controller]")] 17 | [ApiController] 18 | public class CustomerController : ControllerBase 19 | { 20 | private readonly ICustomerService service; 21 | private readonly IWebHostEnvironment environment; 22 | public CustomerController(ICustomerService service, IWebHostEnvironment environment) { 23 | this.service = service; 24 | this.environment = environment; 25 | } 26 | 27 | //[AllowAnonymous] 28 | // [EnableCors("corspolicy1")] 29 | [HttpGet("GetAll")] 30 | public async Task GetAll() 31 | { 32 | var data =await this.service.Getall(); 33 | if(data == null) 34 | { 35 | return NotFound(); 36 | } 37 | return Ok(data); 38 | } 39 | 40 | [DisableRateLimiting] 41 | 42 | [HttpGet("Getbycode")] 43 | public async Task Getbycode(string code) 44 | { 45 | var data = await this.service.Getbycode(code); 46 | if (data == null) 47 | { 48 | return NotFound(); 49 | } 50 | return Ok(data); 51 | } 52 | 53 | [HttpPost("Create")] 54 | public async Task Create(Customermodal _data) 55 | { 56 | var data = await this.service.Create(_data); 57 | return Ok(data); 58 | } 59 | [HttpPut("Update")] 60 | public async Task Update(Customermodal _data,string code) 61 | { 62 | var data = await this.service.Update(_data,code); 63 | return Ok(data); 64 | } 65 | 66 | [HttpDelete("Remove")] 67 | public async Task Remove(string code) 68 | { 69 | var data = await this.service.Remove(code); 70 | return Ok(data); 71 | } 72 | 73 | [AllowAnonymous] 74 | [HttpGet("Exportexcel")] 75 | public async Task Exportexcel() 76 | { 77 | try 78 | { 79 | string Filepath=GetFilepath(); 80 | string excelpath = Filepath + "\\customerinfo.xlsx"; 81 | DataTable dt = new DataTable(); 82 | dt.Columns.Add("Code", typeof(string)); 83 | dt.Columns.Add("Name", typeof(string)); 84 | dt.Columns.Add("Email", typeof(string)); 85 | dt.Columns.Add("Phone", typeof(string)); 86 | dt.Columns.Add("CreditLimit", typeof(int)); 87 | var data = await this.service.Getall(); 88 | if (data != null && data.Count > 0) 89 | { 90 | data.ForEach(item => 91 | { 92 | dt.Rows.Add(item.Code, item.Name, item.Email, item.Phone, item.Creditlimit); 93 | }); 94 | } 95 | using (XLWorkbook wb = new XLWorkbook()) 96 | { 97 | wb.AddWorksheet(dt, "Customer Info"); 98 | using(MemoryStream stream=new MemoryStream()) 99 | { 100 | wb.SaveAs(stream); 101 | 102 | if (System.IO.File.Exists(excelpath)) 103 | { 104 | System.IO.File.Delete(excelpath); 105 | } 106 | wb.SaveAs(excelpath); 107 | 108 | return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Customer.xlsx"); 109 | } 110 | } 111 | } 112 | catch (Exception ex) 113 | { 114 | return NotFound(); 115 | } 116 | } 117 | 118 | [NonAction] 119 | private string GetFilepath() 120 | { 121 | return this.environment.WebRootPath + "\\Export"; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Controllers/ProductController.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Helper; 2 | using LearnAPI.Repos; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.EntityFrameworkCore; 6 | using System.IO; 7 | 8 | namespace LearnAPI.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class ProductController : ControllerBase 13 | { 14 | private readonly IWebHostEnvironment environment; 15 | private readonly LearndataContext context; 16 | public ProductController(IWebHostEnvironment environment,LearndataContext context) { 17 | this.environment = environment; 18 | this.context = context; 19 | } 20 | 21 | [HttpPut("UploadImage")] 22 | public async Task UploadImage(IFormFile formFile,string productcode) 23 | { 24 | APIResponse response=new APIResponse(); 25 | try 26 | { 27 | string Filepath = GetFilepath(productcode); 28 | if (!System.IO.Directory.Exists(Filepath)) 29 | { 30 | System.IO.Directory.CreateDirectory(Filepath); 31 | } 32 | 33 | string imagepath = Filepath + "\\" + productcode + ".png"; 34 | if (System.IO.File.Exists(imagepath)) 35 | { 36 | System.IO.File.Delete(imagepath); 37 | } 38 | using (FileStream stream=System.IO.File.Create(imagepath)) 39 | { 40 | await formFile.CopyToAsync(stream); 41 | response.ResponseCode = 200; 42 | response.Result = "pass"; 43 | } 44 | } 45 | catch (Exception ex) 46 | { 47 | response.Message=ex.Message; 48 | } 49 | return Ok(response); 50 | } 51 | 52 | [HttpPut("MultiUploadImage")] 53 | public async Task MultiUploadImage(IFormFileCollection filecollection, string productcode) 54 | { 55 | APIResponse response = new APIResponse(); 56 | int passcount = 0;int errorcount = 0; 57 | try 58 | { 59 | string Filepath = GetFilepath(productcode); 60 | if (!System.IO.Directory.Exists(Filepath)) 61 | { 62 | System.IO.Directory.CreateDirectory(Filepath); 63 | } 64 | foreach (var file in filecollection) 65 | { 66 | string imagepath = Filepath + "\\" + file.FileName; 67 | if (System.IO.File.Exists(imagepath)) 68 | { 69 | System.IO.File.Delete(imagepath); 70 | } 71 | using (FileStream stream = System.IO.File.Create(imagepath)) 72 | { 73 | await file.CopyToAsync(stream); 74 | passcount++; 75 | 76 | } 77 | } 78 | 79 | 80 | } 81 | catch (Exception ex) 82 | { 83 | errorcount++; 84 | response.Message = ex.Message; 85 | } 86 | response.ResponseCode = 200; 87 | response.Result = passcount + " Files uploaded &" + errorcount + " files failed"; 88 | return Ok(response); 89 | } 90 | 91 | [HttpGet("GetImage")] 92 | public async Task GetImage(string productcode) 93 | { 94 | string Imageurl = string.Empty; 95 | string hosturl= $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 96 | try 97 | { 98 | string Filepath = GetFilepath(productcode); 99 | string imagepath = Filepath + "\\" + productcode + ".png"; 100 | if (System.IO.File.Exists(imagepath)) 101 | { 102 | Imageurl = hosturl + "/Upload/product/" + productcode + "/" + productcode + ".png"; 103 | } 104 | else 105 | { 106 | return NotFound(); 107 | } 108 | } 109 | catch(Exception ex) 110 | { 111 | } 112 | return Ok(Imageurl); 113 | 114 | } 115 | 116 | [HttpGet("GetMultiImage")] 117 | public async Task GetMultiImage(string productcode) 118 | { 119 | List Imageurl = new List(); 120 | string hosturl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 121 | try 122 | { 123 | string Filepath = GetFilepath(productcode); 124 | 125 | if(System.IO.Directory.Exists(Filepath)) 126 | { 127 | DirectoryInfo directoryInfo = new DirectoryInfo(Filepath); 128 | FileInfo[] fileInfos=directoryInfo.GetFiles(); 129 | foreach (FileInfo fileInfo in fileInfos) 130 | { 131 | string filename = fileInfo.Name; 132 | string imagepath = Filepath + "\\" + filename; 133 | if (System.IO.File.Exists(imagepath)) 134 | { 135 | string _Imageurl = hosturl + "/Upload/product/" + productcode + "/" + filename; 136 | Imageurl.Add(_Imageurl); 137 | } 138 | } 139 | } 140 | 141 | } 142 | catch (Exception ex) 143 | { 144 | } 145 | return Ok(Imageurl); 146 | 147 | } 148 | 149 | [HttpGet("download")] 150 | public async Task download(string productcode) 151 | { 152 | // string Imageurl = string.Empty; 153 | //string hosturl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 154 | try 155 | { 156 | string Filepath = GetFilepath(productcode); 157 | string imagepath = Filepath + "\\" + productcode + ".png"; 158 | if (System.IO.File.Exists(imagepath)) 159 | { 160 | MemoryStream stream = new MemoryStream(); 161 | using(FileStream fileStream=new FileStream(imagepath, FileMode.Open)) 162 | { 163 | await fileStream.CopyToAsync(stream); 164 | } 165 | stream.Position = 0; 166 | return File(stream, "image/png", productcode + ".png"); 167 | //Imageurl = hosturl + "/Upload/product/" + productcode + "/" + productcode + ".png"; 168 | } 169 | else 170 | { 171 | return NotFound(); 172 | } 173 | } 174 | catch (Exception ex) 175 | { 176 | return NotFound(); 177 | } 178 | 179 | 180 | } 181 | 182 | [HttpGet("remove")] 183 | public async Task remove(string productcode) 184 | { 185 | // string Imageurl = string.Empty; 186 | //string hosturl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 187 | try 188 | { 189 | string Filepath = GetFilepath(productcode); 190 | string imagepath = Filepath + "\\" + productcode + ".png"; 191 | if (System.IO.File.Exists(imagepath)) 192 | { 193 | System.IO.File.Delete(imagepath); 194 | return Ok("pass"); 195 | } 196 | else 197 | { 198 | return NotFound(); 199 | } 200 | } 201 | catch (Exception ex) 202 | { 203 | return NotFound(); 204 | } 205 | 206 | 207 | } 208 | 209 | [HttpGet("multiremove")] 210 | public async Task multiremove(string productcode) 211 | { 212 | // string Imageurl = string.Empty; 213 | //string hosturl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 214 | try 215 | { 216 | string Filepath = GetFilepath(productcode); 217 | if (System.IO.Directory.Exists(Filepath)) 218 | { 219 | DirectoryInfo directoryInfo = new DirectoryInfo(Filepath); 220 | FileInfo[] fileInfos = directoryInfo.GetFiles(); 221 | foreach (FileInfo fileInfo in fileInfos) 222 | { 223 | fileInfo.Delete(); 224 | } 225 | return Ok("pass"); 226 | } 227 | else 228 | { 229 | return NotFound(); 230 | } 231 | } 232 | catch (Exception ex) 233 | { 234 | return NotFound(); 235 | } 236 | 237 | 238 | } 239 | 240 | [HttpPut("DBMultiUploadImage")] 241 | public async Task DBMultiUploadImage(IFormFileCollection filecollection, string productcode) 242 | { 243 | APIResponse response = new APIResponse(); 244 | int passcount = 0; int errorcount = 0; 245 | try 246 | { 247 | foreach (var file in filecollection) 248 | { 249 | using(MemoryStream stream=new MemoryStream()) 250 | { 251 | await file.CopyToAsync(stream); 252 | this.context.TblProductimages.Add(new Repos.Models.TblProductimage() 253 | { 254 | Productcode = productcode, 255 | Productimage=stream.ToArray() 256 | }); 257 | await this.context.SaveChangesAsync(); 258 | passcount++; 259 | } 260 | } 261 | 262 | 263 | } 264 | catch (Exception ex) 265 | { 266 | errorcount++; 267 | response.Message = ex.Message; 268 | } 269 | response.ResponseCode = 200; 270 | response.Result = passcount + " Files uploaded &" + errorcount + " files failed"; 271 | return Ok(response); 272 | } 273 | 274 | 275 | [HttpGet("GetDBMultiImage")] 276 | public async Task GetDBMultiImage(string productcode) 277 | { 278 | List Imageurl = new List(); 279 | //string hosturl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; 280 | try 281 | { 282 | var _productimage=this.context.TblProductimages.Where(item=>item.Productcode==productcode).ToList(); 283 | if(_productimage!=null && _productimage.Count>0) 284 | { 285 | _productimage.ForEach(item => 286 | { 287 | Imageurl.Add(Convert.ToBase64String(item.Productimage)); 288 | }); 289 | } 290 | else 291 | { 292 | return NotFound(); 293 | } 294 | //string Filepath = GetFilepath(productcode); 295 | 296 | //if (System.IO.Directory.Exists(Filepath)) 297 | //{ 298 | // DirectoryInfo directoryInfo = new DirectoryInfo(Filepath); 299 | // FileInfo[] fileInfos = directoryInfo.GetFiles(); 300 | // foreach (FileInfo fileInfo in fileInfos) 301 | // { 302 | // string filename = fileInfo.Name; 303 | // string imagepath = Filepath + "\\" + filename; 304 | // if (System.IO.File.Exists(imagepath)) 305 | // { 306 | // string _Imageurl = hosturl + "/Upload/product/" + productcode + "/" + filename; 307 | // Imageurl.Add(_Imageurl); 308 | // } 309 | // } 310 | //} 311 | 312 | } 313 | catch (Exception ex) 314 | { 315 | } 316 | return Ok(Imageurl); 317 | 318 | } 319 | 320 | 321 | [HttpGet("dbdownload")] 322 | public async Task dbdownload(string productcode) 323 | { 324 | 325 | try 326 | { 327 | 328 | var _productimage = await this.context.TblProductimages.FirstOrDefaultAsync(item => item.Productcode == productcode); 329 | if (_productimage != null ) 330 | { 331 | return File(_productimage.Productimage, "image/png", productcode + ".png"); 332 | } 333 | 334 | 335 | //string Filepath = GetFilepath(productcode); 336 | //string imagepath = Filepath + "\\" + productcode + ".png"; 337 | //if (System.IO.File.Exists(imagepath)) 338 | //{ 339 | // MemoryStream stream = new MemoryStream(); 340 | // using (FileStream fileStream = new FileStream(imagepath, FileMode.Open)) 341 | // { 342 | // await fileStream.CopyToAsync(stream); 343 | // } 344 | // stream.Position = 0; 345 | // return File(stream, "image/png", productcode + ".png"); 346 | // //Imageurl = hosturl + "/Upload/product/" + productcode + "/" + productcode + ".png"; 347 | //} 348 | else 349 | { 350 | return NotFound(); 351 | } 352 | } 353 | catch (Exception ex) 354 | { 355 | return NotFound(); 356 | } 357 | 358 | 359 | } 360 | 361 | [NonAction] 362 | private string GetFilepath(string productcode) 363 | { 364 | return this.environment.WebRootPath + "\\Upload\\product\\" + productcode; 365 | } 366 | 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Modal; 2 | using LearnAPI.Service; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace LearnAPI.Controllers 7 | { 8 | [Route("api/[controller]")] 9 | [ApiController] 10 | public class UserController : ControllerBase 11 | { 12 | private readonly IUserService userService; 13 | public UserController(IUserService service) { 14 | this.userService = service; 15 | } 16 | 17 | [HttpPost("userregisteration")] 18 | public async Task UserRegisteration(UserRegister userRegister) 19 | { 20 | var data= await this.userService.UserRegisteration(userRegister); 21 | return Ok(data); 22 | } 23 | 24 | [HttpPost("confirmregisteration")] 25 | public async Task confirmregisteration(Confirmpassword _data) 26 | { 27 | var data = await this.userService.ConfirmRegister(_data.userid, _data.username, _data.otptext); 28 | return Ok(data); 29 | } 30 | 31 | [HttpPost("resetpassword")] 32 | public async Task resetpassword(Resetpassword _data) 33 | { 34 | var data = await this.userService.ResetPassword(_data.username, _data.oldpassword, _data.newpassword); 35 | return Ok(data); 36 | } 37 | 38 | [HttpGet("forgetpassword")] 39 | public async Task forgetpassword(string username) 40 | { 41 | var data = await this.userService.ForgetPassword(username); 42 | return Ok(data); 43 | } 44 | 45 | [HttpPost("updatepassword")] 46 | public async Task updatepassword(Updatepassword _data) 47 | { 48 | var data = await this.userService.UpdatePassword(_data.username,_data.password,_data.otptext); 49 | return Ok(data); 50 | } 51 | 52 | [HttpPost("updatestatus")] 53 | public async Task updatestatus(Updatestatus _data) 54 | { 55 | var data = await this.userService.UpdateStatus(_data.username, _data.status); 56 | return Ok(data); 57 | } 58 | 59 | [HttpPost("updaterole")] 60 | public async Task updaterole(UpdateRole _data) 61 | { 62 | var data = await this.userService.UpdateRole(_data.username, _data.role); 63 | return Ok(data); 64 | } 65 | 66 | [HttpGet("GetAll")] 67 | public async Task GetAll() 68 | { 69 | var data = await this.userService.Getall(); 70 | if (data == null) 71 | { 72 | return NotFound(); 73 | } 74 | return Ok(data); 75 | } 76 | [HttpGet("Getbycode")] 77 | public async Task Getbycode(string code) 78 | { 79 | var data = await this.userService.Getbycode(code); 80 | if (data == null) 81 | { 82 | return NotFound(); 83 | } 84 | return Ok(data); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Controllers/UserRoleController.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Modal; 2 | using LearnAPI.Repos.Models; 3 | using LearnAPI.Service; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace LearnAPI.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class UserRoleController : ControllerBase 12 | { 13 | private readonly IUserRoleServicecs userRole; 14 | public UserRoleController(IUserRoleServicecs roleServicecs) { 15 | this.userRole = roleServicecs; 16 | } 17 | 18 | [HttpPost("assignrolepermission")] 19 | public async Task assignrolepermission(List rolepermissions) 20 | { 21 | var data = await this.userRole.AssignRolePermission(rolepermissions); 22 | return Ok(data); 23 | } 24 | 25 | [HttpGet("GetAllRoles")] 26 | public async Task GetAllRoles() 27 | { 28 | var data = await this.userRole.GetAllRoles(); 29 | if(data==null) 30 | { 31 | return NotFound(); 32 | } 33 | return Ok(data); 34 | } 35 | 36 | [HttpGet("GetAllMenus")] 37 | public async Task GetAllMenus() 38 | { 39 | var data = await this.userRole.GetAllMenus(); 40 | if (data == null) 41 | { 42 | return NotFound(); 43 | } 44 | return Ok(data); 45 | } 46 | 47 | [HttpGet("GetAllMenusbyrole")] 48 | public async Task GetAllMenusbyrole(string userrole) 49 | { 50 | var data = await this.userRole.GetAllMenubyrole(userrole); 51 | if (data == null) 52 | { 53 | return NotFound(); 54 | } 55 | return Ok(data); 56 | } 57 | 58 | [HttpGet("GetMenupermissionbyrole")] 59 | public async Task GetMenupermissionbyrole(string userrole,string menucode) 60 | { 61 | var data = await this.userRole.GetMenupermissionbyrole(userrole, menucode); 62 | if (data == null) 63 | { 64 | return NotFound(); 65 | } 66 | return Ok(data); 67 | } 68 | 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace LearnAPI.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Helper/APIResponse.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Helper 2 | { 3 | public class APIResponse 4 | { 5 | public int ResponseCode { get; set; } 6 | public string Result { get; set; } 7 | public string Message { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Helper/AutoMapperHandler.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using LearnAPI.Modal; 3 | using LearnAPI.Repos.Models; 4 | 5 | namespace LearnAPI.Helper 6 | { 7 | public class AutoMapperHandler:Profile 8 | { 9 | public AutoMapperHandler() { 10 | CreateMap().ForMember(item => item.Statusname, opt => opt.MapFrom( 11 | item => (item.IsActive != null && item.IsActive.Value) ? "Active" : "In active")).ReverseMap() ; 12 | CreateMap().ForMember(item => item.Statusname, opt => opt.MapFrom( 13 | item => (item.Isactive != null && item.Isactive.Value) ? "Active" : "In active")).ReverseMap(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Helper/BasicAuthenticationHandler.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Repos; 2 | using Microsoft.AspNetCore.Authentication; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.Extensions.Options; 5 | using System.Linq; 6 | using System.Net.Http.Headers; 7 | using System.Security.Claims; 8 | using System.Text; 9 | using System.Text.Encodings.Web; 10 | 11 | namespace LearnAPI.Helper 12 | { 13 | public class BasicAuthenticationHandler : AuthenticationHandler 14 | { 15 | private readonly LearndataContext context; 16 | public BasicAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock,LearndataContext context) : base(options, logger, encoder, clock) 17 | { 18 | this.context = context; 19 | } 20 | 21 | protected async override Task HandleAuthenticateAsync() 22 | { 23 | if (!Request.Headers.ContainsKey("Authorization")) 24 | { 25 | return AuthenticateResult.Fail("No header found"); 26 | } 27 | var headervalue = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); 28 | if (headervalue != null) 29 | { 30 | var bytes = Convert.FromBase64String(headervalue.Parameter); 31 | string credentials=Encoding.UTF8.GetString(bytes); 32 | string[] array = credentials.Split(":"); 33 | string username = array[0]; 34 | string password = array[1]; 35 | var user =await this.context.TblUsers.FirstOrDefaultAsync(item => item.Username == username && item.Password == password); 36 | if (user != null) 37 | { 38 | var claim = new[] { new Claim(ClaimTypes.Name, user.Username) }; 39 | var identity = new ClaimsIdentity(claim, Scheme.Name); 40 | var principal = new ClaimsPrincipal(identity); 41 | var ticket = new AuthenticationTicket(principal, Scheme.Name); 42 | return AuthenticateResult.Success(ticket); 43 | } 44 | else 45 | { 46 | return AuthenticateResult.Fail("UnAutorized"); 47 | } 48 | } 49 | else 50 | { 51 | return AuthenticateResult.Fail("Empty header"); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /LearnAPI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | all 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | 20 | 21 | 22 | all 23 | runtime; build; native; contentfiles; analyzers; buildtransitive 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /LearnAPI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33103.201 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LearnAPI", "LearnAPI.csproj", "{C7888EDB-D928-4063-A8EC-4308E1275C98}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C7888EDB-D928-4063-A8EC-4308E1275C98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C7888EDB-D928-4063-A8EC-4308E1275C98}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C7888EDB-D928-4063-A8EC-4308E1275C98}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C7888EDB-D928-4063-A8EC-4308E1275C98}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {183290FD-B4A1-4E83-9AED-E8A5BC8339B6} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Modal/Appmenucs.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class Appmenu 4 | { 5 | public string code { get; set; } 6 | public string Name { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Modal/Customermodal.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Internal; 2 | using Microsoft.EntityFrameworkCore; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.ComponentModel.DataAnnotations; 5 | 6 | namespace LearnAPI.Modal 7 | { 8 | [Keyless] 9 | public class Customermodal 10 | { 11 | [StringLength(50)] 12 | [Unicode(false)] 13 | public string Code { get; set; } = null!; 14 | 15 | [StringLength(50)] 16 | [Unicode(false)] 17 | public string Name { get; set; } = null!; 18 | 19 | [StringLength(50)] 20 | [Unicode(false)] 21 | public string? Email { get; set; } 22 | 23 | [StringLength(50)] 24 | [Unicode(false)] 25 | public string? Phone { get; set; } 26 | 27 | [Column(TypeName = "decimal(18, 2)")] 28 | public decimal? Creditlimit { get; set; } 29 | 30 | public bool? IsActive { get; set; } 31 | 32 | public string? Statusname { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Modal/EmailSettings.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class EmailSettings 4 | { 5 | public string Email { get; set; } 6 | public string Password { get; set; } 7 | public string Host { get; set; } 8 | public string DisplayName { get; set; } 9 | public int Port { get; set; } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Modal/JwtSettings.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class JwtSettings 4 | { 5 | public string securitykey { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Modal/Mailrequest.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class Mailrequest 4 | { 5 | public string Email { get; set; } 6 | public string Subject { get; set; } 7 | public string Emailbody { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Modal/Menupermission.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class Menupermission 4 | { 5 | public string code { get; set; } 6 | public string Name { get; set; } 7 | public bool Haveview { get; set; } 8 | public bool Haveadd { get; set; } 9 | public bool Haveedit { get; set; } 10 | public bool Havedelete { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Modal/TokenResponse.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class TokenResponse 4 | { 5 | public string Token { get; set; } 6 | public string RefreshToken { get; set; } 7 | public string UserRole { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Modal/UserCred.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class UserCred 4 | { 5 | public string username { get; set; } 6 | public string password { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Modal/UserModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace LearnAPI.Modal 6 | { 7 | public class UserModel 8 | { 9 | public string Username { get; set; } 10 | public string Name { get; set; } 11 | public string? Email { get; set; } 12 | public string? Phone { get; set; } 13 | public bool? Isactive { get; set; } 14 | public string? Statusname { get; set; } 15 | public string Role { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Modal/UserRegister.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Modal 2 | { 3 | public class UserRegister 4 | { 5 | public string UserName { get; set; } 6 | public string Name { get; set; } 7 | public string Email { get; set; } 8 | public string Phone { get; set; } 9 | public string Password { get; set; } 10 | } 11 | 12 | public class Confirmpassword 13 | { 14 | public int userid { get; set; } 15 | public string username { get; set; } 16 | public string otptext { get; set; } 17 | } 18 | 19 | public class Resetpassword 20 | { 21 | public string username { get; set; } 22 | public string oldpassword { get; set; } 23 | public string newpassword { get; set; } 24 | } 25 | 26 | public class Updatepassword 27 | { 28 | public string username { get; set; } 29 | public string password { get; set; } 30 | public string otptext { get; set; } 31 | } 32 | 33 | public class Updatestatus 34 | { 35 | public string username { get; set; } 36 | public bool status { get; set; } 37 | } 38 | 39 | public class UpdateRole 40 | { 41 | public string username { get; set; } 42 | public string role { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using LearnAPI.Container; 3 | using LearnAPI.Helper; 4 | using LearnAPI.Modal; 5 | using LearnAPI.Repos; 6 | using LearnAPI.Repos.Models; 7 | using LearnAPI.Service; 8 | using Microsoft.AspNetCore.Authentication; 9 | using Microsoft.AspNetCore.Authentication.JwtBearer; 10 | using Microsoft.AspNetCore.Builder; 11 | using Microsoft.AspNetCore.RateLimiting; 12 | using Microsoft.EntityFrameworkCore; 13 | using Microsoft.Extensions.Options; 14 | using Microsoft.IdentityModel.Tokens; 15 | using Serilog; 16 | using System.Text; 17 | 18 | var builder = WebApplication.CreateBuilder(args); 19 | 20 | // Add services to the container. 21 | 22 | builder.Services.AddControllers(); 23 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 24 | builder.Services.AddEndpointsApiExplorer(); 25 | builder.Services.AddSwaggerGen(); 26 | builder.Services.Configure(builder.Configuration.GetSection("EmailSettings")); 27 | builder.Services.AddTransient(); 28 | builder.Services.AddTransient(); 29 | builder.Services.AddTransient(); 30 | builder.Services.AddTransient(); 31 | builder.Services.AddTransient(); 32 | builder.Services.AddDbContext(o => 33 | o.UseSqlServer(builder.Configuration.GetConnectionString("apicon"))); 34 | 35 | //builder.Services.AddAuthentication("BasicAuthentication").AddScheme("BasicAuthentication", null); 36 | 37 | var _authkey = builder.Configuration.GetValue("JwtSettings:securitykey"); 38 | builder.Services.AddAuthentication(item => 39 | { 40 | item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 41 | item.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 42 | }).AddJwtBearer(item => 43 | { 44 | item.RequireHttpsMetadata = true; 45 | item.SaveToken = true; 46 | item.TokenValidationParameters = new TokenValidationParameters() 47 | { 48 | ValidateIssuerSigningKey = true, 49 | IssuerSigningKey=new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_authkey)), 50 | ValidateIssuer = false, 51 | ValidateAudience = false, 52 | ClockSkew = TimeSpan.Zero 53 | }; 54 | 55 | }); 56 | 57 | var automapper = new MapperConfiguration(item => item.AddProfile(new AutoMapperHandler())); 58 | IMapper mapper = automapper.CreateMapper(); 59 | builder.Services.AddSingleton(mapper); 60 | builder.Services.AddCors(p => p.AddPolicy("corspolicy", build => 61 | { 62 | build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader(); 63 | })); 64 | 65 | builder.Services.AddCors(p => p.AddPolicy("corspolicy1", build => 66 | { 67 | build.WithOrigins("https://localhost:7249").AllowAnyMethod().AllowAnyHeader(); 68 | })); 69 | 70 | builder.Services.AddCors(p => p.AddDefaultPolicy(build => 71 | { 72 | build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader(); 73 | })); 74 | 75 | builder.Services.AddRateLimiter(_ => _.AddFixedWindowLimiter(policyName: "fixedwindow", options => 76 | { 77 | options.Window = TimeSpan.FromSeconds(10); 78 | options.PermitLimit = 1; 79 | options.QueueLimit = 0; 80 | options.QueueProcessingOrder = System.Threading.RateLimiting.QueueProcessingOrder.OldestFirst; 81 | }).RejectionStatusCode=401); 82 | 83 | string logpath = builder.Configuration.GetSection("Logging:Logpath").Value; 84 | var _logger = new LoggerConfiguration() 85 | .MinimumLevel.Information() 86 | .MinimumLevel.Override("microsoft", Serilog.Events.LogEventLevel.Warning) 87 | .Enrich.FromLogContext() 88 | .WriteTo.File(logpath) 89 | .CreateLogger(); 90 | builder.Logging.AddSerilog(_logger); 91 | 92 | var _jwtsetting = builder.Configuration.GetSection("JwtSettings"); 93 | builder.Services.Configure(_jwtsetting); 94 | 95 | 96 | var app = builder.Build(); 97 | 98 | app.MapGet("/minimalapi", () => "Nihira Techiees"); 99 | 100 | app.MapGet("/getchannel", (string channelname) => "Welcome to " + channelname).WithOpenApi(opt => 101 | { 102 | var parameter = opt.Parameters[0]; 103 | parameter.Description = "Enter Channel Name"; 104 | return opt; 105 | }); 106 | 107 | app.MapGet("/getcustomer",async (LearndataContext db) => { 108 | return await db.TblCustomers.ToListAsync(); 109 | }); 110 | 111 | app.MapGet("/getcustomerbycode/{code}", async (LearndataContext db,string code) => { 112 | return await db.TblCustomers.FindAsync(code); 113 | }); 114 | 115 | app.MapPost("/createcustomer", async (LearndataContext db, TblCustomer customer) => { 116 | await db.TblCustomers.AddAsync(customer); 117 | await db.SaveChangesAsync(); 118 | }); 119 | 120 | app.MapPut("/updatecustomer/{code}", async (LearndataContext db, TblCustomer customer,string code) => { 121 | var existdata = await db.TblCustomers.FindAsync(code); 122 | if(existdata != null) 123 | { 124 | existdata.Name = customer.Name; 125 | existdata.Email = customer.Email; 126 | } 127 | await db.SaveChangesAsync(); 128 | }); 129 | 130 | app.MapDelete("/removecustomer/{code}", async (LearndataContext db, string code) => { 131 | var existdata = await db.TblCustomers.FindAsync(code); 132 | if (existdata != null) 133 | { 134 | db.TblCustomers.Remove(existdata); 135 | } 136 | await db.SaveChangesAsync(); 137 | }); 138 | 139 | app.UseRateLimiter(); 140 | // Configure the HTTP request pipeline. 141 | //if (app.Environment.IsDevelopment()) 142 | //{ 143 | app.UseSwagger(); 144 | app.UseSwaggerUI(); 145 | //} 146 | 147 | app.UseStaticFiles(); 148 | 149 | app.UseCors(); 150 | 151 | app.UseHttpsRedirection(); 152 | 153 | app.UseAuthentication(); 154 | 155 | app.UseAuthorization(); 156 | 157 | app.MapControllers(); 158 | 159 | app.Run(); 160 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40952", 8 | "sslPort": 44389 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5211", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7143;http://localhost:5211", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Repos/LearndataContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using LearnAPI.Modal; 4 | using LearnAPI.Repos.Models; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos; 8 | 9 | public partial class LearndataContext : DbContext 10 | { 11 | public LearndataContext() 12 | { 13 | } 14 | 15 | public LearndataContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | } 19 | 20 | public virtual DbSet TblCustomers { get; set; } 21 | 22 | public virtual DbSet TblMenus { get; set; } 23 | 24 | public virtual DbSet TblOtpManagers { get; set; } 25 | 26 | public virtual DbSet TblProducts { get; set; } 27 | 28 | public virtual DbSet TblProductimages { get; set; } 29 | 30 | public virtual DbSet TblPwdMangers { get; set; } 31 | 32 | public virtual DbSet TblRefreshtokens { get; set; } 33 | 34 | public virtual DbSet TblRoles { get; set; } 35 | 36 | public virtual DbSet TblRolepermissions { get; set; } 37 | 38 | public virtual DbSet TblTempusers { get; set; } 39 | 40 | public virtual DbSet TblUsers { get; set; } 41 | public virtual DbSet customerdetail { get; set; } 42 | 43 | 44 | protected override void OnModelCreating(ModelBuilder modelBuilder) 45 | { 46 | modelBuilder.Entity(entity => 47 | { 48 | entity.HasKey(e => e.Id).HasName("tbl_tempuser1"); 49 | }); 50 | 51 | OnModelCreatingPartial(modelBuilder); 52 | } 53 | 54 | partial void OnModelCreatingPartial(ModelBuilder modelBuilder); 55 | } 56 | -------------------------------------------------------------------------------- /Repos/Models/TblCustomer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_customer")] 10 | public partial class TblCustomer 11 | { 12 | [Key] 13 | [StringLength(50)] 14 | [Unicode(false)] 15 | public string Code { get; set; } = null!; 16 | 17 | [StringLength(50)] 18 | [Unicode(false)] 19 | public string Name { get; set; } = null!; 20 | 21 | [StringLength(50)] 22 | [Unicode(false)] 23 | public string? Email { get; set; } 24 | 25 | [StringLength(50)] 26 | [Unicode(false)] 27 | public string? Phone { get; set; } 28 | 29 | [Column(TypeName = "decimal(18, 2)")] 30 | public decimal? Creditlimit { get; set; } 31 | 32 | public bool? IsActive { get; set; } 33 | 34 | public int? Taxcode { get; set; } 35 | } 36 | -------------------------------------------------------------------------------- /Repos/Models/TblMenu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_menu")] 10 | public partial class TblMenu 11 | { 12 | [Key] 13 | [Column("code")] 14 | [StringLength(50)] 15 | public string Code { get; set; } = null!; 16 | 17 | [Column("name")] 18 | [StringLength(200)] 19 | public string Name { get; set; } = null!; 20 | 21 | [Column("status")] 22 | public bool? Status { get; set; } 23 | } 24 | -------------------------------------------------------------------------------- /Repos/Models/TblOtpManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_otpManager")] 10 | public partial class TblOtpManager 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("username")] 17 | [StringLength(50)] 18 | [Unicode(false)] 19 | public string? Username { get; set; } 20 | 21 | [Column("otptext")] 22 | [StringLength(10)] 23 | [Unicode(false)] 24 | public string Otptext { get; set; } = null!; 25 | 26 | [Column("otptype")] 27 | [StringLength(20)] 28 | [Unicode(false)] 29 | public string? Otptype { get; set; } 30 | 31 | [Column("expiration", TypeName = "datetime")] 32 | public DateTime Expiration { get; set; } 33 | 34 | [Column("createddate", TypeName = "datetime")] 35 | public DateTime? Createddate { get; set; } 36 | } 37 | -------------------------------------------------------------------------------- /Repos/Models/TblProduct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_product")] 10 | public partial class TblProduct 11 | { 12 | [Key] 13 | [Column("code")] 14 | [StringLength(50)] 15 | [Unicode(false)] 16 | public string Code { get; set; } = null!; 17 | 18 | [Column("name")] 19 | [Unicode(false)] 20 | public string? Name { get; set; } 21 | 22 | [Column("price", TypeName = "decimal(18, 2)")] 23 | public decimal? Price { get; set; } 24 | } 25 | -------------------------------------------------------------------------------- /Repos/Models/TblProductimage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_productimage")] 10 | public partial class TblProductimage 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("productcode")] 17 | [StringLength(50)] 18 | [Unicode(false)] 19 | public string? Productcode { get; set; } 20 | 21 | [Column("productimage", TypeName = "image")] 22 | public byte[]? Productimage { get; set; } 23 | } 24 | -------------------------------------------------------------------------------- /Repos/Models/TblPwdManger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_pwdManger")] 10 | public partial class TblPwdManger 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("username")] 17 | [StringLength(50)] 18 | public string Username { get; set; } = null!; 19 | 20 | [Column("password")] 21 | [StringLength(200)] 22 | public string Password { get; set; } = null!; 23 | 24 | [Column(TypeName = "datetime")] 25 | public DateTime? ModifyDate { get; set; } 26 | } 27 | -------------------------------------------------------------------------------- /Repos/Models/TblRefreshtoken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_refreshtoken")] 10 | public partial class TblRefreshtoken 11 | { 12 | [Key] 13 | [Column("userid")] 14 | [StringLength(50)] 15 | [Unicode(false)] 16 | public string Userid { get; set; } = null!; 17 | 18 | [Column("tokenid")] 19 | [StringLength(50)] 20 | [Unicode(false)] 21 | public string? Tokenid { get; set; } 22 | 23 | [Column("refreshtoken")] 24 | [Unicode(false)] 25 | public string? Refreshtoken { get; set; } 26 | } 27 | -------------------------------------------------------------------------------- /Repos/Models/TblRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_role")] 10 | public partial class TblRole 11 | { 12 | [Key] 13 | [Column("code")] 14 | [StringLength(50)] 15 | public string Code { get; set; } = null!; 16 | 17 | [Column("name")] 18 | [StringLength(200)] 19 | public string Name { get; set; } = null!; 20 | 21 | [Column("status")] 22 | public bool? Status { get; set; } 23 | } 24 | -------------------------------------------------------------------------------- /Repos/Models/TblRolemenumap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_rolemenumap")] 10 | public partial class TblRolemenumap 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("userrole")] 17 | [StringLength(20)] 18 | public string Userrole { get; set; } = null!; 19 | 20 | [Column("menucode")] 21 | [StringLength(50)] 22 | public string Menucode { get; set; } = null!; 23 | } 24 | -------------------------------------------------------------------------------- /Repos/Models/TblRolepermission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_rolepermission")] 10 | public partial class TblRolepermission 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("userrole")] 17 | [StringLength(50)] 18 | public string Userrole { get; set; } = null!; 19 | 20 | [Column("menucode")] 21 | [StringLength(50)] 22 | public string Menucode { get; set; } = null!; 23 | 24 | [Column("haveview")] 25 | public bool Haveview { get; set; } 26 | 27 | [Column("haveadd")] 28 | public bool Haveadd { get; set; } 29 | 30 | [Column("haveedit")] 31 | public bool Haveedit { get; set; } 32 | 33 | [Column("havedelete")] 34 | public bool Havedelete { get; set; } 35 | } 36 | -------------------------------------------------------------------------------- /Repos/Models/TblSubtable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_subtable")] 10 | public partial class TblSubtable 11 | { 12 | [Key] 13 | [Column("code")] 14 | [StringLength(50)] 15 | public string Code { get; set; } = null!; 16 | 17 | [Column("menucode")] 18 | [StringLength(50)] 19 | public string Menucode { get; set; } = null!; 20 | 21 | [StringLength(200)] 22 | public string Name { get; set; } = null!; 23 | 24 | [Column("status")] 25 | public bool? Status { get; set; } 26 | } 27 | -------------------------------------------------------------------------------- /Repos/Models/TblTempuser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_tempuser")] 10 | public partial class TblTempuser 11 | { 12 | [Key] 13 | [Column("id")] 14 | public int Id { get; set; } 15 | 16 | [Column("code")] 17 | [StringLength(50)] 18 | [Unicode(false)] 19 | public string Code { get; set; } = null!; 20 | 21 | [Column("name")] 22 | [StringLength(250)] 23 | [Unicode(false)] 24 | public string Name { get; set; } = null!; 25 | 26 | [Column("email")] 27 | [StringLength(100)] 28 | [Unicode(false)] 29 | public string? Email { get; set; } 30 | 31 | [Column("phone")] 32 | [StringLength(20)] 33 | [Unicode(false)] 34 | public string? Phone { get; set; } 35 | 36 | [Column("password")] 37 | [StringLength(50)] 38 | [Unicode(false)] 39 | public string? Password { get; set; } 40 | } 41 | -------------------------------------------------------------------------------- /Repos/Models/TblUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace LearnAPI.Repos.Models; 8 | 9 | [Table("tbl_user")] 10 | public partial class TblUser 11 | { 12 | [Key] 13 | [Column("username")] 14 | [StringLength(50)] 15 | [Unicode(false)] 16 | public string Username { get; set; } = null!; 17 | 18 | [Column("name")] 19 | [StringLength(250)] 20 | [Unicode(false)] 21 | public string Name { get; set; } = null!; 22 | 23 | [Column("email")] 24 | [StringLength(100)] 25 | [Unicode(false)] 26 | public string? Email { get; set; } 27 | 28 | [Column("phone")] 29 | [StringLength(20)] 30 | [Unicode(false)] 31 | public string? Phone { get; set; } 32 | 33 | [Column("password")] 34 | [StringLength(50)] 35 | [Unicode(false)] 36 | public string? Password { get; set; } 37 | 38 | [Column("isactive")] 39 | public bool? Isactive { get; set; } 40 | 41 | [Column("role")] 42 | [StringLength(50)] 43 | [Unicode(false)] 44 | public string? Role { get; set; } 45 | 46 | [Column("islocked")] 47 | public bool? Islocked { get; set; } 48 | 49 | [Column("failattempt")] 50 | public int? Failattempt { get; set; } 51 | } 52 | -------------------------------------------------------------------------------- /Service/ICustomerService.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Helper; 2 | using LearnAPI.Modal; 3 | using LearnAPI.Repos.Models; 4 | 5 | namespace LearnAPI.Service 6 | { 7 | public interface ICustomerService 8 | { 9 | Task> Getall(); 10 | Task Getbycode(string code); 11 | Task Remove(string code); 12 | Task Create(Customermodal data); 13 | 14 | Task Update(Customermodal data,string code); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Service/IEmailService.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Modal; 2 | 3 | namespace LearnAPI.Service 4 | { 5 | public interface IEmailService 6 | { 7 | Task SendEmail(Mailrequest mailrequest); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Service/IRefreshHandler.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI.Service 2 | { 3 | public interface IRefreshHandler 4 | { 5 | Task GenerateToken(string username); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Service/IUserRoleServicecs.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Helper; 2 | using LearnAPI.Modal; 3 | using LearnAPI.Repos.Models; 4 | 5 | namespace LearnAPI.Service 6 | { 7 | public interface IUserRoleServicecs 8 | { 9 | Task AssignRolePermission(List _data); 10 | Task> GetAllRoles(); 11 | Task> GetAllMenus(); 12 | Task> GetAllMenubyrole(string userrole); 13 | Task GetMenupermissionbyrole(string userrole,string menucode); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Service/IUserService.cs: -------------------------------------------------------------------------------- 1 | using LearnAPI.Helper; 2 | using LearnAPI.Modal; 3 | 4 | namespace LearnAPI.Service 5 | { 6 | public interface IUserService 7 | { 8 | Task UserRegisteration(UserRegister userRegister); 9 | Task ConfirmRegister(int userid, string username, string otptext); 10 | Task ResetPassword(string username, string oldpassword,string newpassword); 11 | Task ForgetPassword(string username); 12 | Task UpdatePassword(string username,string Password,string Otptext); 13 | Task UpdateStatus(string username, bool userstatus); 14 | Task UpdateRole(string username, string userrole); 15 | Task> Getall(); 16 | Task Getbycode(string code); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace LearnAPI 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateOnly Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "JwtSettings": { 3 | "securitykey": "thisismyapikeythisismyapikeythisismyapikey" 4 | }, 5 | "Logging": { 6 | "Logpath": "F:\\LaernCore\\Logs\\Log.txt", 7 | "LogLevel": { 8 | "Default": "Information", 9 | "Microsoft.AspNetCore": "Warning" 10 | } 11 | }, 12 | "AllowedHosts": "*", 13 | "ConnectionStrings": { 14 | "apicon": "Server=LAPTOP-4K7AS2ME\\SQLEXPRESS;Database=test_db;Trusted_Connection=True;TrustServerCertificate=True;" 15 | }, 16 | "EmailSettings": { 17 | "Email": "test@gmail.com", 18 | "Password": "password", 19 | "Host": "smtp.gmail.com", 20 | "DisplayName": "Nihira Techiees", 21 | "Port": 587 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /wwwroot/Export/customerinfo.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihira2020/WEBAPI_CORE_7/30463030dbaca178fdc4f1981b54f2bd1a60bce2/wwwroot/Export/customerinfo.xlsx --------------------------------------------------------------------------------