Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 576 additions & 0 deletions ATX1110-FIX-changes.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions app/Bookstore.Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<Order>().HasOne(x => x.Customer).WithMany().OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity<ShoppingCartItem>()
.Property(e => e.WantToBuy)
.HasConversion<int>();

PopulateDatabase(modelBuilder);

base.OnModelCreating(modelBuilder);
Expand Down
1 change: 1 addition & 0 deletions app/Bookstore.Domain/ReferenceData/ReferenceDataItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public ReferenceDataItem(ReferenceDataType referenceDataType, string text)
Text = text;
}

[Column("datatype")]
public ReferenceDataType DataType { get; set; }

[Column("text")]
Expand Down
67 changes: 31 additions & 36 deletions app/Bookstore.Web/Controllers/AuthorsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ public async Task<bool> EditUsingStoredProcedure(int businessEntityId, string na
{
try
{
string sql = @"DECLARE @rowsAffected INT;EXEC @rowsAffected = [dbo].[uspUpdateAuthorPersonalInfo] @BusinessEntityID, @NationalIDNumber, @BirthDate, @MaritalStatus, @Gender;SELECT @rowsAffected;";

var rowsAffected = await _context.Database.ExecuteSqlRawAsync(sql,
new SqlParameter("@BusinessEntityID", businessEntityId),
new SqlParameter("@NationalIDNumber", nationalIdNumber),
new SqlParameter("@BirthDate", birthDate.ToUniversalTime()),
new SqlParameter("@MaritalStatus", maritalStatus),
new SqlParameter("@Gender", gender)
);

return rowsAffected > 0;
var author = await _context.Author.FindAsync(businessEntityId);
if (author != null)
{
author.NationalIDNumber = nationalIdNumber;
author.BirthDate = birthDate;
author.MaritalStatus = maritalStatus;
author.Gender = gender;
await _context.SaveChangesAsync();
return true;
}
return false;
}
catch (Exception ex)
{
Expand All @@ -184,19 +184,12 @@ public async Task<List<Author>> FindAllAuthorsEmbeddedSql()
{
try
{
// Build the SQL command
string sql = @"SELECT * FROM Author";

// Execute the SQL command and get the number of rows affected
var results = await _context.Database.SqlQueryRaw<Author>(sql).ToListAsync();

return results;
return await _context.Author.ToListAsync();
}
catch (Exception ex)
{
// Log the error or handle it as needed
Console.WriteLine(ex.ToString());
return null;
return new List<Author>();
}
}

Expand All @@ -205,17 +198,17 @@ public async Task<bool> DeleteAuthorEmbeddedSql(int businessEntityId)
{
try
{
// Build the SQL command
string sql = @"DECLARE @rowsAffected INT;EXEC @rowsAffected = [dbo].[uspDeleteAuthor] @BusinessEntityID;SELECT @rowsAffected;";

// Execute the SQL command and get the number of rows affected
var rowsAffected = await _context.Database.ExecuteSqlRawAsync(sql, new SqlParameter("@BusinessEntityID", businessEntityId));

return rowsAffected > 0;
var author = await _context.Author.FindAsync(businessEntityId);
if (author != null)
{
_context.Author.Remove(author);
await _context.SaveChangesAsync();
return true;
}
return false;
}
catch (Exception ex)
{
// Log the error or handle it as needed
Console.WriteLine(ex.ToString());
return false;
}
Expand All @@ -225,19 +218,21 @@ public async Task<List<AuthorAgeResult>> SelectAuthorsByHireYear(int hireYear)
{
try
{
// Build the SQL command
string sql = @"SELECT BusinessEntityID, FORMAT(ModifiedDate, 'yyyy-MM-dd HH:mm:ss') AS FormattedModifiedDate, DATEDIFF(YEAR, BirthDate, GETDATE()) AS Age FROM Author WHERE DATEPART(YEAR, HireDate) = @HireDate;";

// Execute the SQL command and get the number of rows affected
var results = await _context.Database.SqlQueryRaw<AuthorAgeResult>(sql, new SqlParameter("@HireDate", hireYear)).ToListAsync();

var results = await _context.Author
.Where(a => a.HireDate.Year == hireYear)
.Select(a => new AuthorAgeResult
{
BusinessEntityID = a.BusinessEntityID,
FormattedModifiedDate = a.ModifiedDate.ToString("yyyy-MM-dd HH:mm:ss"),
Age = DateTime.Now.Year - a.BirthDate.Year
})
.ToListAsync();
return results;
}
catch (Exception ex)
{
// Log the error or handle it as needed
Console.WriteLine(ex.ToString());
return null;
return new List<AuthorAgeResult>();
}
}

Expand Down
5 changes: 1 addition & 4 deletions app/Bookstore.Web/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ public async Task<List<Product>> FindAllProducts()
{
try
{
string sql = @"EXEC [dbo].[uspGetProductData];";

return await _context.Database.SqlQueryRaw<Product>(sql).ToListAsync();
return await _context.Product.ToListAsync();
}
catch (Exception ex)
{
// Log the error or handle it as needed
Console.WriteLine(ex.ToString());
return new List<Product>();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Bookstore.Web/Startup/ServicesSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static string GetDatabaseConnectionString(ConfigurationManager configura
PropertyNameCaseInsensitive = true
});

connString = $"Host={dbSecrets.Host};Port={dbSecrets.Port};Database=BobsUsedBookStore;Username={dbSecrets.Username};Password={dbSecrets.Password}";
connString = $"Host={dbSecrets.Host};Port={dbSecrets.Port};Database=postgres;Username={dbSecrets.Username};Password={dbSecrets.Password}";
}
catch (AmazonSecretsManagerException e)
{
Expand Down
2 changes: 1 addition & 1 deletion app/Bookstore.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
}
},
"AllowedHosts": "*",
"dbsecretsname": "atx-db-modernization-secret-sql-admin"
"dbsecretsname": "atx-db-modernization-atx-db-modernization-secret-sql-admin-target"
}