Added RMDataManageLibrary project

Added a way to communicate with database
This commit is contained in:
s459315 2022-07-14 19:41:50 +02:00
parent 7bbae1b17c
commit aa98988db1
15 changed files with 247 additions and 2 deletions

View File

@ -49,4 +49,18 @@
<Property Name="ParentElementType" Value="SqlTable" /> <Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="PurchasePrice" /> <Property Name="NewName" Value="PurchasePrice" />
</Operation> </Operation>
<Operation Name="Rename Refactor" Key="bcd94488-d937-495b-89f6-73b1e73b40cb" ChangeDateTime="07/14/2022 16:44:16">
<Property Name="ElementName" Value="[dbo].[Product].[CreateDate]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[Product]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="CreatedDate" />
</Operation>
<Operation Name="Rename Refactor" Key="99ed8c7b-5779-4b29-ab9c-0860a5c55a93" ChangeDateTime="07/14/2022 16:44:32">
<Property Name="ElementName" Value="[dbo].[User].[CreateDate]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[User]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="CreatedDate" />
</Operation>
</Operations> </Operations>

View File

@ -71,6 +71,7 @@
<Build Include="dbo\Tables\SaleDetail.sql" /> <Build Include="dbo\Tables\SaleDetail.sql" />
<Build Include="dbo\Tables\Product.sql" /> <Build Include="dbo\Tables\Product.sql" />
<Build Include="dbo\Tables\Inventory.sql" /> <Build Include="dbo\Tables\Inventory.sql" />
<Build Include="dbo\Stored Procedures\spUserLookup.sql" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<RefactorLog Include="RMData.refactorlog" /> <RefactorLog Include="RMData.refactorlog" />

View File

@ -0,0 +1,10 @@
CREATE PROCEDURE [dbo].[spUserLookup]
@Id nvarchar(128)
AS
BEGIN
SET NOCOUNT ON;
SELECT Id, FirstName, LastName, EmailAddress, CreatedDate
from [dbo].[User]
where Id = @Id
END

View File

@ -4,7 +4,7 @@
[ProductName] NVARCHAR(100) NOT NULL, [ProductName] NVARCHAR(100) NOT NULL,
[Description] NVARCHAR(MAX) NOT NULL, [Description] NVARCHAR(MAX) NOT NULL,
[RetailPrice] MONEY NOT NULL, [RetailPrice] MONEY NOT NULL,
[CreateDate] DATETIME2 NOT NULL DEFAULT getutcdate(), [CreatedDate] DATETIME2 NOT NULL DEFAULT getutcdate(),
[LastModified] DATETIME2 NOT NULL DEFAULT getutcdate(), [LastModified] DATETIME2 NOT NULL DEFAULT getutcdate(),
) )

View File

@ -4,5 +4,5 @@
[FirstName] NVARCHAR(50) NOT NULL, [FirstName] NVARCHAR(50) NOT NULL,
[LastName] NVARCHAR(50) NOT NULL, [LastName] NVARCHAR(50) NOT NULL,
[EmailAddress] NVARCHAR(256) NOT NULL, [EmailAddress] NVARCHAR(256) NOT NULL,
[CreateDate] DATETIME2 NOT NULL DEFAULT getutcdate() [CreatedDate] DATETIME2 NOT NULL DEFAULT getutcdate()
) )

View File

@ -0,0 +1,22 @@
using RMDataManagerLibrary.DataAcccess;
using System.Collections.Generic;
using System.Web.Http;
using RMDataManagerLibrary.Models;
using System.Web;
using Microsoft.AspNet.Identity;
namespace RMDataManager.Controllers
{
[Authorize]
public class UserController : ApiController
{
public List<UserModel> GetById()
{
string userId = RequestContext.Principal.Identity.GetUserId();
UserData data = new UserData();
return data.GetUserById(userId);
}
}
}

View File

@ -213,6 +213,7 @@
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" /> <Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Controllers\AccountController.cs" /> <Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="Controllers\ValuesController.cs" /> <Compile Include="Controllers\ValuesController.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>
@ -283,6 +284,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="Views\User\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="fonts\glyphicons-halflings-regular.woff2" /> <Content Include="fonts\glyphicons-halflings-regular.woff2" />
@ -313,6 +315,12 @@
<Content Include="Scripts\jquery-3.6.0.slim.min.map" /> <Content Include="Scripts\jquery-3.6.0.slim.min.map" />
<Content Include="Scripts\jquery-3.6.0.min.map" /> <Content Include="Scripts\jquery-3.6.0.min.map" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RMDataManagerLibrary\RMDataManagerLibrary.csproj">
<Project>{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}</Project>
<Name>RMDataManagerLibrary</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -10,6 +10,7 @@
</configSections> </configSections>
<connectionStrings> <connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-RMDataManager-20220630092827.mdf;Initial Catalog=aspnet-RMDataManager-20220630092827;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-RMDataManager-20220630092827.mdf;Initial Catalog=aspnet-RMDataManager-20220630092827;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="RMData" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RMData;Integrated Security=True;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
</connectionStrings> </connectionStrings>
<appSettings> <appSettings>
</appSettings> </appSettings>

View File

@ -0,0 +1,24 @@
using RMDataManagerLibrary.Internal.DataAccess;
using RMDataManagerLibrary.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.DataAcccess
{
public class UserData
{
public List<UserModel> GetUserById(string Id)
{
SqlDataAccess sql = new SqlDataAccess();
var p = new { Id = Id };
var output = sql.LoadData<UserModel, dynamic>("dbo.spUserLookup", p, "RMData");
return output;
}
}
}

View File

@ -0,0 +1,44 @@
using Dapper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.Internal.DataAccess
{
public class SqlDataAccess
{
public string GetConnectionString(string name)
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
public List<T> LoadData<T, U>(string storedProcedure, U parameters, string connectionStringName)
{
string connectionString = GetConnectionString(connectionStringName);
using (IDbConnection connection = new SqlConnection(connectionString))
{
List<T> rows = connection.Query<T>(storedProcedure, parameters,
commandType: CommandType.StoredProcedure).ToList();
return rows;
}
}
public void SaveData<T>(string storedProcedure, T parameters, string connectionStringName)
{
string connectionString = GetConnectionString(connectionStringName);
using (IDbConnection connection = new SqlConnection(connectionString))
{
connection.Execute(storedProcedure, parameters,
commandType: CommandType.StoredProcedure);
}
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.Models
{
public class UserModel
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public DateTime CreatedDate { get; set; }
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RMDataManagerLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RMDataManagerLibrary")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6669f7dc-4b07-497f-bdee-5333db3edbf4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RMDataManagerLibrary</RootNamespace>
<AssemblyName>RMDataManagerLibrary</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.2.0.123\lib\net461\Dapper.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataAcccess\UserData.cs" />
<Compile Include="Models\UserModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Internal\DataAccess\SqlDataAccess.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapper" version="2.0.123" targetFramework="net472" />
</packages>

View File

@ -9,6 +9,8 @@ Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "RMData", "RMData\RMData.sql
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RMWPFUserInterface", "RMWPFUserInterface\RMWPFUserInterface.csproj", "{90936557-936E-4310-90C1-45254FEEA7B1}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RMWPFUserInterface", "RMWPFUserInterface\RMWPFUserInterface.csproj", "{90936557-936E-4310-90C1-45254FEEA7B1}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RMDataManagerLibrary", "RMDataManagerLibrary\RMDataManagerLibrary.csproj", "{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -29,6 +31,10 @@ Global
{90936557-936E-4310-90C1-45254FEEA7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU {90936557-936E-4310-90C1-45254FEEA7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90936557-936E-4310-90C1-45254FEEA7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU {90936557-936E-4310-90C1-45254FEEA7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90936557-936E-4310-90C1-45254FEEA7B1}.Release|Any CPU.Build.0 = Release|Any CPU {90936557-936E-4310-90C1-45254FEEA7B1}.Release|Any CPU.Build.0 = Release|Any CPU
{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6669F7DC-4B07-497F-BDEE-5333DB3EDBF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE