Skip to content

Commit

Permalink
Backup Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neojarvis committed Sep 21, 2023
1 parent e529dd5 commit 19e7615
Show file tree
Hide file tree
Showing 23 changed files with 2,344 additions and 63 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using dotnetwebapiAddCustomer.Models;

namespace dotnetwebapiAddCustomer.Controllers;

[ApiController]
[Route("[controller]")]
public class CustomerController : ControllerBase
{
private readonly CustomerDbContext customerDbContext;
public CustomerController(CustomerDbContext _customerDbContext)
{
customerDbContext = _customerDbContext;
}

[HttpPost]
public async Task<ActionResult> AddCustomer(Customer customer)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState); // Return detailed validation errors
}
await customerDbContext.Customers.AddAsync(customer);
await customerDbContext.SaveChangesAsync();
return Ok();
}
}
23 changes: 23 additions & 0 deletions dotnetproject/dotnetmsAddCustomer/Models/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace dotnetmsAddCustomer.Models
{
[Table("customer", Schema ="dbo")]

public class Customer
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("customer_id")]
public int CustomerId {get;set;}
[Column("customer_name")]
public string CustomerName {get;set;}
[Column("customer_mobilenumber")]
public string MobileNumber {get;set;}
[Column("customer_email")]
public string Email {get;set;}
}

}
31 changes: 31 additions & 0 deletions dotnetproject/dotnetmsAddCustomer/Models/CustomerDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

using Microsoft.EntityFrameworkCore.Infrastructure;

namespace dotnetmsAddCustomer.Models;

public class CustomerDbContext : DbContext
{

public CustomerDbContext(DbContextOptions<CustomerDbContext> options) : base(options)
{
// try
// {
// var dbCreator= Database.GetService<IDatabaseCreator>() as RelationalDatabaseCreator;
// if(dbCreator != null)
// {
// if(!dbCreator.CanConnect())dbCreator.Create();
// if(!dbCreator.HasTables())dbCreator.CreateTables();
// }

// }
// catch(Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
}
public DbSet<Customer> Customers {get; set;}
}
7 changes: 6 additions & 1 deletion dotnetproject/dotnetmsAddCustomer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using dotnetmsAddCustomer.Models;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
Expand All @@ -6,7 +9,9 @@
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<CustomerDbContext>(options =>{
options.UseSqlServer(builder.Configuration.GetConnectionString("MyConnString"));
});
var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down
5 changes: 4 additions & 1 deletion dotnetproject/dotnetmsAddCustomer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"MyConnString":"User ID=sa;password=examlyMssql@123;server=dffafdafebcfacbdcbaeadbebabcdebdca-0;Database=CheckDB;trusted_connection=false;Persist Security Info=False;Encrypt=False;"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("dotnetmsAddCustomer")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("dotnetmsAddCustomer")]
[assembly: System.Reflection.AssemblyTitleAttribute("dotnetmsAddCustomer")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2c29f5b19fcb0450a12d9add17e5c8646559c45
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb = true
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = dotnetmsAddCustomer
build_property.RootNamespace = dotnetmsAddCustomer
build_property.ProjectDir = /home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/
build_property.RazorLangVersion = 6.0
build_property.SupportLocalizedComponentNames =
build_property.GenerateRazorMetadataSourceChecksumAttributes =
build_property.MSBuildProjectDirectory = /home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer
build_property._RazorSourceGeneratorDebug =
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// <auto-generated/>
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading;
global using global::System.Threading.Tasks;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("Swashbuckle.AspNetCore.SwaggerGen")]

// Generated by the MSBuild WriteCodeFragment class.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e63075c3c4154acafa89362d54ef9ddb3976fe87
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.csproj.AssemblyReference.cache
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.GeneratedMSBuildEditorConfig.editorconfig
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.AssemblyInfoInputs.cache
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.AssemblyInfo.cs
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.csproj.CoreCompileInputs.cache
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.MvcApplicationPartsAssemblyInfo.cs
/home/coder/project/workspace/dotnetproject/dotnetmsAddCustomer/obj/Debug/net6.0/dotnetmsAddCustomer.MvcApplicationPartsAssemblyInfo.cache
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,33 @@
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Microsoft.EntityFrameworkCore": {
"target": "Package",
"version": "[6.0.0, )"
},
"Microsoft.EntityFrameworkCore.Design": {
"include": "Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive",
"suppressParent": "All",
"target": "Package",
"version": "[6.0.0, )"
},
"Microsoft.EntityFrameworkCore.InMemory": {
"target": "Package",
"version": "[6.0.0, )"
},
"Microsoft.EntityFrameworkCore.SqlServer": {
"target": "Package",
"version": "[6.0.0, )"
},
"Microsoft.EntityFrameworkCore.Tools": {
"include": "Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive",
"suppressParent": "All",
"target": "Package",
"version": "[6.0.0, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[6.2.3, )"
"version": "[6.0.0, )"
}
},
"imports": [
Expand All @@ -62,7 +86,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.408/RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.414/RuntimeIdentifierGraph.json"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/coder/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/coder/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.2</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.3</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/coder/.nuget/packages/" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.props" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.props')" />
<Import Project="$(NuGetPackageRoot)swashbuckle.aspnetcore/6.2.3/build/Swashbuckle.AspNetCore.props" Condition="Exists('$(NuGetPackageRoot)swashbuckle.aspnetcore/6.2.3/build/Swashbuckle.AspNetCore.props')" />
<Import Project="$(NuGetPackageRoot)swashbuckle.aspnetcore/6.0.0/build/Swashbuckle.AspNetCore.props" Condition="Exists('$(NuGetPackageRoot)swashbuckle.aspnetcore/6.0.0/build/Swashbuckle.AspNetCore.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.entityframeworkcore.design/6.0.0/build/net6.0/Microsoft.EntityFrameworkCore.Design.props" Condition="Exists('$(NuGetPackageRoot)microsoft.entityframeworkcore.design/6.0.0/build/net6.0/Microsoft.EntityFrameworkCore.Design.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_Extensions_ApiDescription_Server Condition=" '$(PkgMicrosoft_Extensions_ApiDescription_Server)' == '' ">/home/coder/.nuget/packages/microsoft.extensions.apidescription.server/3.0.0</PkgMicrosoft_Extensions_ApiDescription_Server>
<PkgMicrosoft_EntityFrameworkCore_Tools Condition=" '$(PkgMicrosoft_EntityFrameworkCore_Tools)' == '' ">/home/coder/.nuget/packages/microsoft.entityframeworkcore.tools/6.0.0</PkgMicrosoft_EntityFrameworkCore_Tools>
</PropertyGroup>
</Project>
Loading

0 comments on commit 19e7615

Please sign in to comment.