Display update

This commit is contained in:
thermalthrottle
2021-03-19 10:58:04 +02:00
parent 701be834cf
commit d516d33a38
5 changed files with 127 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ using System.Text;
namespace Business.Business.Sales namespace Business.Business.Sales
{ {
class ProductController : IController<Product> public class ProductController : IController<Product>
{ {
private LuminousContext context; private LuminousContext context;
private User currentUser; private User currentUser;
@@ -23,15 +23,39 @@ namespace Business.Business.Sales
} }
public Product Get(int id) public Product Get(int id)
{ {
return context.Product.Find(id); var item = context.Product.Find(id);
if (item != null)
{
return item;
}
else
{
throw new ArgumentException("Product Id not found!");
}
} }
public Product Get(string name) public Product Get(string name)
{ {
return context.Product.FirstOrDefault(p => p.Name == name); var item = context.Product.FirstOrDefault(p => p.Name == name);
if (item != null)
{
return item;
}
else
{
throw new ArgumentException("Product name not found!");
}
} }
public ICollection<Product> GetByApproximateName(string name) public ICollection<Product> GetByApproximateName(string name)
{ {
return context.Product.Where(u => u.Name.Contains(name)).ToList(); var items = context.Product.Where(u => u.Name.Contains(name)).ToList();
if (items.Any())
{
return items;
}
else
{
throw new ArgumentException("No products added in the database!");
}
} }
public void AddItem(string name, double price) public void AddItem(string name, double price)
{ {

View File

@@ -1,5 +1,7 @@
using Business.Business.UserManagment; using Business.Business.UserManagment;
using Display.Views;
using Models; using Models;
using Models.Models;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@@ -10,10 +12,18 @@ namespace Display
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var a = new InitialSetup.InitialSetup(); try
a.InitialRegistration(); {
var ih = new InputHandler(); var uc = new UserController();
ih.CommandLineInterface(); User currentUser = uc.ValidatePassword("admin123");
uc = new UserController(currentUser);
var cv = new CashierView(currentUser);
cv.SaleHandle();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} }
} }
} }

View File

@@ -6,6 +6,6 @@ namespace Display.Sales
{ {
class Stock class Stock
{ {
public void //public void
} }
} }

View File

@@ -1,12 +1,21 @@
using Models.Models; using Business.Business.Sales;
using Models.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace Display.Views namespace Display.Views
{ {
class BaseView class BaseView
{ {
ProductController productctrl;
DealController dealctrl;
public BaseView(User currentUser)
{
this.productctrl = new ProductController(currentUser);
this.dealctrl = new DealController(currentUser);
}
public virtual void ShowAvaliableCommands() public virtual void ShowAvaliableCommands()
{ {
Console.WriteLine("1. Sales"); Console.WriteLine("1. Sales");
@@ -17,17 +26,81 @@ namespace Display.Views
Product product = new Product(); Product product = new Product();
while (true) while (true)
{ {
SearchItem(); Console.WriteLine("1. Search");
SaleItem(); Console.WriteLine("2. Sale");
Console.WriteLine("3. Exit");
Console.Write("Your Choice: ");
try
{
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
SearchItem();
break;
case 2:
SaleItem();
break;
case 3:
Environment.Exit(0);
break;
default:
Console.WriteLine("Invalid Option!");
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} }
} }
private void SearchItem() private void SearchItem()
{ {
try
{
Console.Write("Search item: ");
string search = Console.ReadLine();
ICollection<Product> productsFound = productctrl.GetByApproximateName(search).ToArray();
foreach (var item in productsFound)
{
Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} }
private void SaleItem() private void SaleItem()
{ {
try
{
Console.Write("Type in item id or name: ");
string itemInput = Console.ReadLine();
int itemId;
if (Int32.TryParse(itemInput, out itemId))
{
var productToAdd = productctrl.Get(itemId);
Console.Write("Amount: ");
double amount = double.Parse(Console.ReadLine());
dealctrl.Add(itemId, amount);
}
else
{
var productToAdd = productctrl.Get(itemInput);
Console.Write("Amount: ");
double amount = double.Parse(Console.ReadLine());
dealctrl.Add(itemInput, amount);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} }
} }
} }

View File

@@ -1,10 +1,16 @@
using System; using Models.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace Display.Views namespace Display.Views
{ {
class CashierView class CashierView : BaseView
{ {
public CashierView(User currentUser) : base(currentUser)
{
}
} }
} }