Views, Add Time in Deal & Stock
This commit is contained in:
Binary file not shown.
@@ -9,8 +9,8 @@ namespace Business.Business.Sales
|
||||
ICollection<T> GetAll();
|
||||
T Get(int id);
|
||||
ICollection<T> GetByTime(DateTime startTime, DateTime endTime);
|
||||
void Add(int productId, double Amount);
|
||||
void Add(string productName, double Amount);
|
||||
void Add(int productId, double Amount, DateTime time);
|
||||
void Add(string productName, double Amount, DateTime time);
|
||||
void Delete(int id);
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,11 @@ namespace Business.Business.Sales
|
||||
{
|
||||
this.currentUser = currentUser;
|
||||
}
|
||||
public void Add(int productId, double Amount)
|
||||
public void Add(int productId, double Amount, DateTime time)
|
||||
{
|
||||
if (Amount > 0)
|
||||
{
|
||||
var deal = new Deal(currentUser.Id, productId, Amount);
|
||||
var deal = new Deal(currentUser.Id, productId, Amount, time);
|
||||
context.Deal.Add(deal);
|
||||
context.SaveChanges();
|
||||
}
|
||||
@@ -30,17 +30,16 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(string productName, double Amount)
|
||||
public void Add(string productName, double Amount, DateTime time)
|
||||
{
|
||||
if (Amount > 0)
|
||||
{
|
||||
productCtrl = new ProductController(currentUser);
|
||||
var productId = productCtrl.Get(productName).Id;
|
||||
var deal = new Deal(currentUser.Id, productId, Amount);
|
||||
var deal = new Deal(currentUser.Id, productId, Amount, time);
|
||||
context.Deal.Add(deal);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Amount cannot be negative");
|
||||
|
@@ -56,13 +56,15 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(int productId, double Amount)
|
||||
public void Add(int productId, double Amount, DateTime time)
|
||||
{
|
||||
if (currentUser.RoleId > 1)
|
||||
{
|
||||
if (Amount > 0)
|
||||
{
|
||||
var stock = new Stock(currentUser.Id, productId, Amount);
|
||||
var stock = new Stock(currentUser.Id, productId, Amount, time);
|
||||
productCtrl = new ProductController(currentUser);
|
||||
productCtrl.Get(productId).AmountInStock += Amount;
|
||||
context.Stock.Add(stock);
|
||||
context.SaveChanges();
|
||||
}
|
||||
@@ -78,7 +80,7 @@ namespace Business.Business.Sales
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(string productName, double Amount)
|
||||
public void Add(string productName, double Amount, DateTime time)
|
||||
{
|
||||
if (currentUser.RoleId > 1)
|
||||
{
|
||||
@@ -86,7 +88,8 @@ namespace Business.Business.Sales
|
||||
{
|
||||
productCtrl = new ProductController(currentUser);
|
||||
var productId = productCtrl.Get(productName).Id;
|
||||
var stock = new Stock(currentUser.Id, productId, Amount);
|
||||
var stock = new Stock(currentUser.Id, productId, Amount, time);
|
||||
productCtrl.Get(productId).AmountInStock += Amount;
|
||||
context.Stock.Add(stock);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@@ -17,9 +17,4 @@
|
||||
<ProjectReference Include="..\Models\Data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Sales\" />
|
||||
<Folder Include="UserManagment\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -1,9 +1,10 @@
|
||||
using Business.Business.UserManagment;
|
||||
using Business.Business.UserManagment.Controllers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Display.InitialSetup
|
||||
namespace Display
|
||||
{
|
||||
public class InitialSetup
|
||||
{
|
||||
@@ -11,9 +12,8 @@ namespace Display.InitialSetup
|
||||
{
|
||||
|
||||
}
|
||||
public string[] InitialUserInput()
|
||||
public static void InitialUserInput(out string userName, out string password)
|
||||
{
|
||||
string userName = "", password = "";
|
||||
try
|
||||
{
|
||||
Console.Write("Enter username: ");
|
||||
@@ -23,13 +23,13 @@ namespace Display.InitialSetup
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
userName = string.Empty;
|
||||
password = string.Empty;
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
return new string[] { userName, password };
|
||||
}
|
||||
public void InitialRegistration()
|
||||
public static void InitialRegistration(UserController uc)
|
||||
{
|
||||
var uc = new UserController();
|
||||
try
|
||||
{
|
||||
if (uc.CheckIfUserEverCreated())
|
||||
@@ -38,7 +38,11 @@ namespace Display.InitialSetup
|
||||
}
|
||||
else
|
||||
{
|
||||
uc.RegisterItem(InitialUserInput()[0], InitialUserInput()[1]);
|
||||
RoleController rc = new RoleController();
|
||||
rc.CreateInitialRoles();
|
||||
string userName, password;
|
||||
InitialUserInput(out userName, out password);
|
||||
uc.RegisterItem(userName, password);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
@@ -15,6 +15,7 @@ namespace Display
|
||||
try
|
||||
{
|
||||
var uc = new UserController();
|
||||
InitialSetup.InitialRegistration(uc);
|
||||
Console.Write("Enter password: ");
|
||||
User currentUser = uc.ValidatePassword(Console.ReadLine());
|
||||
uc = new UserController(currentUser);
|
||||
@@ -33,6 +34,7 @@ namespace Display
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Console.WriteLine("Luminous Sales v0.1");
|
||||
view.ActionHandle();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -17,14 +17,16 @@ namespace Display.Views
|
||||
public override void ShowAvaliableCommands()
|
||||
{
|
||||
base.ShowAvaliableCommands();
|
||||
Console.WriteLine("4. User Managment");
|
||||
Console.WriteLine("3. Administration");
|
||||
}
|
||||
public override void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
{
|
||||
@@ -44,6 +46,7 @@ namespace Display.Views
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
@@ -54,16 +57,22 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("User Managment");
|
||||
Console.WriteLine("1. GetAll");
|
||||
Console.WriteLine("2. Get");
|
||||
Console.WriteLine("3. GetByApproximateName");
|
||||
Console.WriteLine("4. RegisterItem");
|
||||
Console.WriteLine("4. Register user");
|
||||
Console.WriteLine("5. Update Role");
|
||||
Console.WriteLine("6. UpdateName");
|
||||
Console.WriteLine("6. Update username");
|
||||
Console.WriteLine("7. UpdatePassword");
|
||||
Console.WriteLine("8. Delete");
|
||||
Console.WriteLine("9. Exit");
|
||||
Console.Write("Your choice: ");
|
||||
Console.WriteLine("8. Delete User");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Product Managment");
|
||||
Console.WriteLine("9. AddItem");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("10. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -94,6 +103,9 @@ namespace Display.Views
|
||||
Delete();
|
||||
break;
|
||||
case 9:
|
||||
AddItem();
|
||||
break;
|
||||
case 10:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
@@ -286,5 +298,21 @@ namespace Display.Views
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
public void AddItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Adding item to database...");
|
||||
Console.Write("Enter product name: ");
|
||||
string product = Console.ReadLine();
|
||||
Console.Write("Enter price: ");
|
||||
double price = double.Parse(Console.ReadLine());
|
||||
productctrl.AddItem(product, price);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ namespace Display.Views
|
||||
{
|
||||
public class BaseView
|
||||
{
|
||||
ProductController productctrl;
|
||||
internal ProductController productctrl;
|
||||
DealController dealctrl;
|
||||
public BaseView(User currentUser)
|
||||
{
|
||||
@@ -18,15 +18,19 @@ namespace Display.Views
|
||||
}
|
||||
public virtual void ShowAvaliableCommands()
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=== MAIN MENU ===");
|
||||
Console.WriteLine("0. Exit");
|
||||
Console.WriteLine("1. Sales");
|
||||
}
|
||||
public virtual void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
{
|
||||
@@ -38,6 +42,7 @@ namespace Display.Views
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
@@ -48,10 +53,12 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Deal Managment");
|
||||
Console.WriteLine("1. Search");
|
||||
Console.WriteLine("2. Sale");
|
||||
Console.WriteLine("3. Exit");
|
||||
Console.Write("Your choice: ");
|
||||
Console.WriteLine("3. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -103,19 +110,19 @@ namespace Display.Views
|
||||
Console.Write("Type in item id or name: ");
|
||||
string itemInput = Console.ReadLine();
|
||||
int itemId;
|
||||
if (Int32.TryParse(itemInput, out itemId))
|
||||
if (int.TryParse(itemInput, out itemId))
|
||||
{
|
||||
var productToAdd = productctrl.Get(itemId);
|
||||
Console.Write("Amount: ");
|
||||
double amount = double.Parse(Console.ReadLine());
|
||||
dealctrl.Add(itemId, amount);
|
||||
dealctrl.Add(itemId, amount, DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
var productToAdd = productctrl.Get(itemInput);
|
||||
Console.Write("Amount: ");
|
||||
double amount = double.Parse(Console.ReadLine());
|
||||
dealctrl.Add(itemInput, amount);
|
||||
dealctrl.Add(itemInput, amount, DateTime.Now);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -22,10 +22,12 @@ namespace Display.Views
|
||||
}
|
||||
public override void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
{
|
||||
@@ -41,6 +43,7 @@ namespace Display.Views
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
@@ -51,13 +54,15 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stock Managment");
|
||||
Console.WriteLine("1. GetAll");
|
||||
Console.WriteLine("2. Get");
|
||||
Console.WriteLine("3. GetByTime");
|
||||
Console.WriteLine("4. Add");
|
||||
Console.WriteLine("5. Delete");
|
||||
Console.WriteLine("6. Exit");
|
||||
Console.Write("Your choice: ");
|
||||
Console.WriteLine("6. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -97,11 +102,11 @@ namespace Display.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Getting all stock...");
|
||||
|
||||
Console.WriteLine("Getting all stock...");
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
foreach (var item in stockctrl.GetAll())
|
||||
{
|
||||
Console.WriteLine($"{item.Id} {item.ProductId} {item.Amount} ");
|
||||
Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -119,7 +124,9 @@ namespace Display.Views
|
||||
{
|
||||
Console.Write("Enter stock id: ");
|
||||
int id = int.Parse(Console.ReadLine());
|
||||
stockctrl.Get(id);
|
||||
var result = stockctrl.Get(id);
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
Console.WriteLine($"{result.Id} - {result.ProductId} - {result.Amount} - {result.Time}");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -135,11 +142,16 @@ namespace Display.Views
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Getting stock by time...");
|
||||
Console.WriteLine("Enter start time: ");
|
||||
Console.Write("Enter start time: ");
|
||||
DateTime startTime = DateTime.Parse(Console.ReadLine());
|
||||
Console.WriteLine("Enter end time: ");
|
||||
Console.Write("Enter end time: ");
|
||||
DateTime endTime = DateTime.Parse(Console.ReadLine());
|
||||
stockctrl.GetByTime(startTime, endTime);
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
foreach (var item in stockctrl.GetByTime(startTime, endTime))
|
||||
{
|
||||
Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -151,7 +163,7 @@ namespace Display.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Adding stock by product id...");
|
||||
Console.WriteLine("Adding stock by product id or name...");
|
||||
Console.Write("Enter product ID or name: ");
|
||||
string product = Console.ReadLine();
|
||||
Console.Write("Enter stock amount: ");
|
||||
@@ -159,11 +171,11 @@ namespace Display.Views
|
||||
bool result = int.TryParse(product, out int productId);
|
||||
if (result)
|
||||
{
|
||||
stockctrl.Add(productId, amount);
|
||||
stockctrl.Add(productId, amount, DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
stockctrl.Add(product, amount);
|
||||
stockctrl.Add(product, amount, DateTime.Now);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -178,9 +190,9 @@ namespace Display.Views
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Deleting stock...");
|
||||
Console.Write("Enter deal id: ");
|
||||
Console.Write("Enter stock id: ");
|
||||
int id = int.Parse(Console.ReadLine());
|
||||
dealctrl.Delete(id);
|
||||
stockctrl.Delete(id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -13,11 +13,12 @@ namespace Data.Base
|
||||
{
|
||||
|
||||
}
|
||||
protected BaseSales(int UserId, int ProductId, double Amount)
|
||||
protected BaseSales(int UserId, int ProductId, double Amount, DateTime Time)
|
||||
{
|
||||
this.UserId = UserId;
|
||||
this.ProductId = ProductId;
|
||||
this.Amount = Amount;
|
||||
this.Time = Time;
|
||||
}
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Data.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Models.Models
|
||||
@@ -6,6 +7,6 @@ namespace Models.Models
|
||||
public class Deal : BaseSales
|
||||
{
|
||||
public Deal() : base(){}
|
||||
public Deal(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount) { }
|
||||
public Deal(int UserId, int ProductId, double Amount, DateTime Time) : base(UserId, ProductId, Amount, Time) { }
|
||||
}
|
||||
}
|
@@ -9,6 +9,6 @@ namespace Models.Models
|
||||
public class Stock : BaseSales
|
||||
{
|
||||
public Stock() : base(){}
|
||||
public Stock(int UserId, int ProductId, double Amount) : base(UserId, ProductId, Amount){}
|
||||
public Stock(int UserId, int ProductId, double Amount, DateTime Time) : base(UserId, ProductId, Amount, Time){}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user