-
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.
implemented transactions display on sale of products and print them:
:wq
- Loading branch information
1 parent
9f42a68
commit a5c2d04
Showing
42 changed files
with
1,236 additions
and
48 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,45 @@ | ||
|
||
# Please enter the commit message for your changes. Lines starting | ||
# with '#' will be ignored, and an empty message aborts the commit. | ||
# | ||
# On branch main | ||
# Your branch is up to date with 'origin/main'. | ||
# | ||
# Changes to be committed: | ||
# modified: .DS_Store | ||
# modified: Controllers/CategoriesController.cs | ||
# deleted: Models/CategoryRepositoruy.cs | ||
# modified: Program.cs | ||
# modified: Views/Categories/Index.cshtml | ||
# modified: Views/Shared/_Layout.cshtml | ||
# modified: bin/Debug/net8.0/demoMvcCore.dll | ||
# modified: bin/Debug/net8.0/demoMvcCore.pdb | ||
# modified: demoMvcCore.csproj | ||
# modified: obj/Debug/net8.0/demoMvcCore.AssemblyInfo.cs | ||
# modified: obj/Debug/net8.0/demoMvcCore.AssemblyInfoInputs.cache | ||
# modified: obj/Debug/net8.0/demoMvcCore.GeneratedMSBuildEditorConfig.editorconfig | ||
# modified: obj/Debug/net8.0/demoMvcCore.csproj.CoreCompileInputs.cache | ||
# modified: obj/Debug/net8.0/demoMvcCore.csproj.FileListAbsolute.txt | ||
# modified: obj/Debug/net8.0/demoMvcCore.dll | ||
# modified: obj/Debug/net8.0/demoMvcCore.pdb | ||
# modified: obj/Debug/net8.0/ref/demoMvcCore.dll | ||
# modified: obj/Debug/net8.0/refint/demoMvcCore.dll | ||
# modified: wwwroot/css/site.css | ||
# | ||
# Untracked files: | ||
# Controllers/ProductsController.cs | ||
# Controllers/SalesController.cs | ||
# Controllers/TransactionsController.cs | ||
# Models/CategoryRepository.cs | ||
# Models/Product.cs | ||
# Models/ProductRepository.cs | ||
# Models/Transaction.cs | ||
# Models/TransactionsRepository.cs | ||
# ViewComponents/ | ||
# ViewModels/ | ||
# Views/Products/ | ||
# Views/Sales/ | ||
# Views/Shared/Components/ | ||
# Views/Transactions/ | ||
# obj/Debug/net8.0/demoMvcCore.sourcelink.json | ||
# |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
using demoMvcCore.Models; | ||
using demoMvcCore.ViewModels; | ||
using Microsoft.AspNetCore.Cors; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 | ||
|
||
namespace demoMvcCore.Controllers | ||
{ | ||
public class ProductsController : Controller | ||
{ | ||
// GET: /<controller>/ | ||
public IActionResult Index() | ||
{ | ||
var products = ProductsRepository.GetProducts(loadCategory:true); | ||
return View(products); | ||
|
||
} | ||
|
||
public IActionResult Add() | ||
{ | ||
ViewBag.Action = "add"; | ||
var productViewModels = new ProductsViewModel | ||
{ | ||
Categories = CategoryRepository.GetCategories(), | ||
//Product | ||
}; | ||
return View(productViewModels); | ||
|
||
|
||
} | ||
|
||
[HttpPost] | ||
public IActionResult Add(ProductsViewModel productsViewModel) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
ProductsRepository.AddProduct(productsViewModel.Product); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
ViewBag.Action = "edit"; | ||
productsViewModel.Categories = CategoryRepository.GetCategories(); | ||
return View(productsViewModel); | ||
} | ||
|
||
|
||
|
||
|
||
public IActionResult Edit(int id) | ||
{ | ||
ViewBag.Action = "edit"; | ||
var productView = new ProductsViewModel | ||
{ | ||
Product = ProductsRepository.GetProductById(id) ?? new Product(), | ||
Categories = CategoryRepository.GetCategories() | ||
}; | ||
return View(productView); | ||
} | ||
|
||
[HttpPost] | ||
|
||
public IActionResult Edit(ProductsViewModel productsViewModel) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
ProductsRepository.UpdateProduct(productsViewModel.Product.ProductId, productsViewModel.Product); | ||
|
||
return RedirectToAction(nameof(Index)); | ||
} | ||
ViewBag.Action = "edit"; | ||
productsViewModel.Categories = CategoryRepository.GetCategories(); | ||
return View(productsViewModel); | ||
} | ||
|
||
|
||
public IActionResult Delete(int id) | ||
{ | ||
ProductsRepository.DeleteProduct(id); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
|
||
public IActionResult ProductsByCategoryPartial(int categoryId) | ||
{ | ||
var products = ProductsRepository.GetProductsByCategoryId(categoryId); | ||
return PartialView("_Product",products); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} | ||
|
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,58 @@ | ||
using demoMvcCore.Models; | ||
using demoMvcCore.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 | ||
|
||
namespace demoMvcCore.Controllers | ||
{ | ||
public class SalesController : Controller | ||
{ | ||
// GET: /<controller>/ | ||
public IActionResult Index() | ||
{ | ||
var salesVm = new SalesViewModel | ||
{ | ||
Categories = CategoryRepository.GetCategories() | ||
}; | ||
return View(salesVm); | ||
} | ||
|
||
|
||
public IActionResult SellProductPartial(int productId) | ||
{ | ||
var product = ProductsRepository.GetProductById(productId); | ||
|
||
return PartialView("_SellProduct", product); | ||
|
||
|
||
} | ||
|
||
public IActionResult Sell(SalesViewModel salesViewModel) | ||
{ | ||
if(ModelState.IsValid) | ||
{ | ||
var prod = ProductsRepository.GetProductById(salesViewModel.SelectedProductId); | ||
if(prod !=null) | ||
{ | ||
TransactionsRepository.Add("Cashier1" | ||
, salesViewModel.SelectedProductId, | ||
prod.Name, | ||
prod.Price.HasValue ? prod.Price.Value : 0, | ||
prod.Quantity.HasValue ? prod.Quantity.Value : 0, | ||
salesViewModel.QuantityToSell); | ||
|
||
prod.Quantity -= salesViewModel.QuantityToSell; | ||
ProductsRepository.UpdateProduct(salesViewModel.SelectedProductId, prod); | ||
|
||
|
||
} | ||
} | ||
var product = ProductsRepository.GetProductById(salesViewModel.SelectedProductId); | ||
salesViewModel.SelectedCategoryId = (product?.CategoryId is null) ? 0 : product.CategoryId.Value; | ||
salesViewModel.Categories = CategoryRepository.GetCategories(); | ||
return View("Index", salesViewModel); | ||
} | ||
} | ||
} | ||
|
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,36 @@ | ||
using demoMvcCore.Models; | ||
using demoMvcCore.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 | ||
|
||
namespace demoMvcCore.Controllers | ||
{ | ||
public class TransactionsController : Controller | ||
{ | ||
// GET: /<controller>/ | ||
public IActionResult Index() | ||
{ | ||
TransactionsViewModel transactionsVM = new(); | ||
|
||
return View(transactionsVM); | ||
} | ||
|
||
|
||
|
||
public IActionResult Search(TransactionsViewModel transactionsViewModel) | ||
{ | ||
|
||
//search | ||
|
||
var transactions = TransactionsRepository.Search(transactionsViewModel.CashierName ?? string.Empty, transactionsViewModel.StartDate, transactionsViewModel.EndDate); | ||
transactionsViewModel.Transactions = transactions; | ||
|
||
return View("Index", transactionsViewModel); | ||
|
||
|
||
} | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace demoMvcCore.Models | ||
{ | ||
|
||
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; } | ||
|
||
|
||
} | ||
} | ||
|
Oops, something went wrong.