-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51e62d3
commit b1bad43
Showing
106 changed files
with
3,487 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-6.32 KB
.vs/TaylorLE2/FileContentIndex/04efa7a0-932d-4266-83e2-9d79dadb9f0a.vsidx
Binary file not shown.
Binary file removed
BIN
-9.65 KB
.vs/TaylorLE2/FileContentIndex/1adcee24-176a-4481-a524-fbd4e820ebd6.vsidx
Binary file not shown.
Binary file added
BIN
+27.2 KB
.vs/TaylorLE2/FileContentIndex/27457f73-096e-4dd2-9e00-4110cfbecccf.vsidx
Binary file not shown.
Binary file added
BIN
+3.91 KB
.vs/TaylorLE2/FileContentIndex/8a3cfe8f-bc32-4fdc-be09-00b2eb9398a7.vsidx
Binary file not shown.
Binary file added
BIN
+4.45 KB
.vs/TaylorLE2/FileContentIndex/91c12318-53d5-4a3e-9676-e954e5996a50.vsidx
Binary file not shown.
Binary file removed
BIN
-7.33 KB
.vs/TaylorLE2/FileContentIndex/ce6a1694-5607-4505-a08f-e1e77b1268ed.vsidx
Binary file not shown.
Binary file removed
BIN
-6.9 KB
.vs/TaylorLE2/FileContentIndex/d590926b-5173-4df5-8f5f-fe8fb3961684.vsidx
Binary file not shown.
Binary file added
BIN
+5.13 KB
.vs/TaylorLE2/FileContentIndex/e05164b4-188c-44f5-b58b-ede2ea3b4665.vsidx
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using BlogDataLibrary.Models; | ||
|
||
namespace BlogDataLibrary.Data | ||
{ | ||
public interface ISqlData | ||
{ | ||
void AddPost(PostModel post); | ||
UserModel Authenticate(string username, string password); | ||
List<ListPostModel> ListPosts(); | ||
void Register(string username, string firstName, string lastName, string password); | ||
ListPostModel ShowPostDetails(int id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
BlogDataLibrary/obj/Debug/net6.0/BlogDataLibrary.csproj.AssemblyReference.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
BlogDataLibrary/obj/Debug/net6.0/BlogDataLibrary.csproj.CoreCompileInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7bf2bb5f4c5008b7b10de4f0c1c5eb4823da8b23 | ||
379d4d320222f608ba031de30d83c3f39d57ec42 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,133 @@ | ||
namespace BlogTestUI; | ||
using BlogDataLibrary.Data; | ||
using BlogDataLibrary.Database; | ||
using BlogDataLibrary.Models; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace BlogTestUI; | ||
|
||
internal class Program | ||
{ | ||
static SqlData GetConnection() | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json"); | ||
|
||
IConfiguration config = builder.Build(); | ||
ISqlDataAccess dbAccess = new SqlDataAccess(config); | ||
SqlData db = new SqlData(dbAccess); | ||
|
||
return db; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
SqlData db = GetConnection(); | ||
|
||
Authenticate(db); | ||
|
||
Register(db); | ||
|
||
AddPost(db); | ||
|
||
ListPosts(db); | ||
|
||
ShowPostDetails(db); | ||
|
||
Console.WriteLine("Press Enter to exit..."); | ||
Console.ReadLine(); | ||
} | ||
|
||
private static UserModel GetCurrentUser(SqlData db) | ||
{ | ||
Console.Write("Username: "); | ||
string username = Console.ReadLine(); | ||
|
||
Console.Write("Password: "); | ||
string password = Console.ReadLine(); | ||
|
||
UserModel user = db.Authenticate(username, password); | ||
|
||
return user; | ||
} | ||
|
||
public static void Authenticate(SqlData db) | ||
{ | ||
UserModel user = GetCurrentUser(db); | ||
|
||
if (user == null) | ||
{ | ||
Console.WriteLine("Invalid credentials."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Welcome, {user.UserName}"); | ||
} | ||
} | ||
|
||
public static void Register(SqlData db) | ||
{ | ||
Console.Write("Enter new username: "); | ||
var username = Console.ReadLine(); | ||
|
||
Console.Write("Enter new password: "); | ||
var password = Console.ReadLine(); | ||
|
||
Console.Write("Enter first name: "); | ||
var firstName = Console.ReadLine(); | ||
|
||
Console.Write("Enter last name: "); | ||
var lastName = Console.ReadLine(); | ||
|
||
db.Register(username, firstName, lastName, password); | ||
} | ||
|
||
private static void AddPost(SqlData db) | ||
{ | ||
UserModel user = GetCurrentUser(db); | ||
|
||
Console.Write("Title: "); | ||
string title = Console.ReadLine(); | ||
|
||
Console.WriteLine("Write body: "); | ||
string body = Console.ReadLine(); | ||
|
||
PostModel post = new PostModel | ||
{ | ||
Title = title, | ||
Body = body, | ||
DateCreated = DateTime.Now, | ||
UserId = user.Id | ||
}; | ||
|
||
db.AddPost(post); | ||
} | ||
|
||
private static void ListPosts(SqlData db) | ||
{ | ||
List<ListPostModel> posts = db.ListPosts(); | ||
|
||
foreach (ListPostModel post in posts) | ||
{ | ||
Console.WriteLine($"{post.Id}. Title: {post.Title} by {post.UserName} [{post.DateCreated.ToString("yyyy-MM-dd")}]"); | ||
Console.WriteLine($"{post.Body.Substring(0, 20)}..."); | ||
Console.WriteLine(); | ||
} | ||
} | ||
|
||
private static void ShowPostDetails(SqlData db) | ||
{ | ||
Console.Write("Enter a post ID: "); | ||
int id = Int32.Parse(Console.ReadLine()); | ||
|
||
ListPostModel post = db.ShowPostDetails(id); | ||
Console.WriteLine(post.Title); | ||
Console.WriteLine($"by {post.FirstName} {post.LastName} [{post.UserName}]"); | ||
|
||
Console.WriteLine(); | ||
|
||
Console.WriteLine(post.Body); | ||
|
||
Console.WriteLine(post.DateCreated.ToString("MMM d yyyy")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"exclude": [ | ||
"**/bin", | ||
"**/bower_components", | ||
"**/jspm_packages", | ||
"**/node_modules", | ||
"**/obj", | ||
"**/platforms" | ||
], | ||
"ConnectionStrings": { | ||
"SqlDb": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BlogDB;Integrated Security=True;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;MultiSubnetFailover=False" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.