-
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
475857d
commit 1674843
Showing
148 changed files
with
7,713 additions
and
105 deletions.
There are no files selected for viewing
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,22 @@ | ||
| ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace CoreBusiness | ||
{ | ||
|
||
|
||
public class Category | ||
{ | ||
public int CategoryId { get; set; } | ||
[Required] | ||
public string Name { get; set; } = string.Empty; | ||
|
||
public string? Description { get; set; } = string.Empty; | ||
|
||
|
||
//navigation prop for ef core | ||
public List<Product>? Products { get; set; } | ||
|
||
} | ||
} | ||
|
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,28 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace CoreBusiness | ||
{ | ||
|
||
public class Product | ||
{ | ||
public int ProductId { get; set; } | ||
|
||
[Required] | ||
[Display(Name = "Category")] | ||
public int? CategoryId { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } = string.Empty; | ||
|
||
[Required] | ||
public int? Quantity { get; set; } | ||
|
||
[Required] | ||
[Range(0, int.MaxValue)] | ||
public double? Price { get; set; } | ||
public Category? Category { get; set; } | ||
|
||
|
||
} | ||
} | ||
|
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,15 @@ | ||
namespace CoreBusiness | ||
{ | ||
public class Transaction | ||
{ | ||
public int TransactionId { get; set; } | ||
public DateTime TimeStamp { get; set; } | ||
public int ProductId { get; set; } | ||
public string ProductName { get; set; } = ""; | ||
public double Price { get; set; } | ||
public int BeforeQty { get; set; } | ||
public int SoldQty { get; set; } | ||
public string CashierName { get; set; } = ""; | ||
} | ||
} | ||
|
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,55 @@ | ||
using System; | ||
using CoreBusiness; | ||
using UseCases.DataStorePluginInterfaces; | ||
|
||
namespace Plugins.DataStore.SQL | ||
{ | ||
public class CategorySQLRepository : ICategoryRepository | ||
{ | ||
|
||
private readonly MarketContext db; | ||
|
||
public CategorySQLRepository(MarketContext db) | ||
{ | ||
this.db = db; | ||
} | ||
|
||
public void AddCategory(Category category) | ||
{ | ||
db.Categories.Add(category); | ||
db.SaveChanges(); | ||
} | ||
|
||
public void DeleteCategory(int categoryId) | ||
{ | ||
var category = db.Categories.Find(categoryId); | ||
if (category == null) return; | ||
|
||
db.Categories.Remove(category); | ||
db.SaveChanges(); | ||
} | ||
|
||
public IEnumerable<Category> GetCategories() | ||
{ | ||
return db.Categories.ToList(); | ||
} | ||
|
||
public Category? GetCategoryById(int categoryId) | ||
{ | ||
return db.Categories.Find(categoryId); | ||
} | ||
|
||
public void UpdateCategory(int categoryId, Category category) | ||
{ | ||
if (categoryId != category.CategoryId) return; | ||
|
||
var cat = db.Categories.Find(categoryId); | ||
if (cat == null) return; | ||
|
||
cat.Name = category.Name; | ||
cat.Description = category.Description; | ||
db.SaveChanges(); | ||
} | ||
} | ||
|
||
} |
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,51 @@ | ||
using System; | ||
using CoreBusiness; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Plugins.DataStore.SQL | ||
{ | ||
public class MarketContext : DbContext | ||
{ | ||
public MarketContext(DbContextOptions<MarketContext> options):base(options) | ||
{ | ||
//options.UseSqlServer("Server=localhost,1433;Database=MarketManagement;User Id=sa;Password=ragh2404;TrustServerCertificate=True;"); | ||
} | ||
|
||
public DbSet<Category> Categories { get; set; } | ||
|
||
public DbSet<Product> Products { get; set; } | ||
|
||
public DbSet<Transaction> Transactions { get; set; } | ||
|
||
|
||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
|
||
base.OnModelCreating(modelBuilder); | ||
|
||
// modelBuilder.HasDefaultSchema("InventoryManagement"); | ||
// define relationships - 1:N | ||
modelBuilder.Entity<Category>().HasMany(x => x.Products).WithOne(x => x.Category).HasForeignKey(x => x.CategoryId); | ||
|
||
|
||
//seeding data | ||
modelBuilder.Entity<Category>().HasData( | ||
new Category { CategoryId = 1, Name = "Beverage", Description = "Beverage" }, | ||
new Category { CategoryId = 2, Name = "Bakery", Description = "Bakery" }, | ||
new Category { CategoryId = 3, Name = "Meat", Description = "Meat" } | ||
); | ||
|
||
modelBuilder.Entity<Product>().HasData( | ||
new Product { ProductId = 1, CategoryId = 1, Name = "Iced Tea", Quantity = 100, Price = 1.99 }, | ||
new Product { ProductId = 2, CategoryId = 1, Name = "Canada Dry", Quantity = 200, Price = 1.99 }, | ||
new Product { ProductId = 3, CategoryId = 2, Name = "Whole Wheat Bread", Quantity = 300, Price = 1.50 }, | ||
new Product { ProductId = 4, CategoryId = 2, Name = "White Bread", Quantity = 300, Price = 1.50 } | ||
); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
184 changes: 184 additions & 0 deletions
184
Plugins.DataStore.SQL/Migrations/20241205210653_INIT.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.