Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
raghav2404 committed Dec 14, 2024
1 parent 475857d commit 1674843
Show file tree
Hide file tree
Showing 148 changed files with 7,713 additions and 105 deletions.
22 changes: 22 additions & 0 deletions CoreBusiness/Category.cs
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; }

}
}

9 changes: 9 additions & 0 deletions CoreBusiness/CoreBusiness.csproj
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>
28 changes: 28 additions & 0 deletions CoreBusiness/Product.cs
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; }


}
}

15 changes: 15 additions & 0 deletions CoreBusiness/Transaction.cs
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; } = "";
}
}

55 changes: 55 additions & 0 deletions Plugins.DataStore.SQL/CategorySQLRepository.cs
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();
}
}

}
51 changes: 51 additions & 0 deletions Plugins.DataStore.SQL/MarketContext.cs
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 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.

Loading

0 comments on commit 1674843

Please sign in to comment.