-
Notifications
You must be signed in to change notification settings - Fork 1
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
d916a76
commit 8fcd219
Showing
73 changed files
with
2,420 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
09.Auto Mapping Objects/NonStopMarket.App/Core/CommandInterpreter.cs
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,48 @@ | ||
namespace NonStopMarket.App.Core | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using NonStopMarket.App.Core.Contracts; | ||
|
||
public class CommandInterpreter : ICommandInterpreter | ||
{ | ||
private const string Suffix = "command"; | ||
|
||
private readonly IServiceProvider serviceProvider; | ||
|
||
public CommandInterpreter(IServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider; | ||
} | ||
|
||
public IExecutable InterpretCommand(string[] data) | ||
{ | ||
var inputCommand = data[0]; | ||
|
||
var type = Assembly | ||
.GetCallingAssembly() | ||
.GetTypes() | ||
.Where(x => x.Name.ToLower() == inputCommand.ToLower() + Suffix) | ||
.SingleOrDefault(); | ||
|
||
var commandConstructor = type | ||
.GetConstructors() | ||
.First(); | ||
|
||
var constructorParams = commandConstructor | ||
.GetParameters() | ||
.Select(x => x.ParameterType) | ||
.ToArray(); | ||
|
||
var injectedParams = constructorParams | ||
.Select(serviceProvider.GetService) | ||
.ToArray(); | ||
|
||
var command = (IExecutable)commandConstructor.Invoke(injectedParams); | ||
|
||
return command; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...to Mapping Objects/NonStopMarket.App/Core/Commands/EmployeeCommands/AddEmployeeCommand.cs
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,30 @@ | ||
namespace NonStopMarket.App.Core.Commands.EmployeeCommands | ||
{ | ||
using Contracts; | ||
using Dtos.EmployeeDtos; | ||
|
||
public class AddEmployeeCommand : IExecutable | ||
{ | ||
public AddEmployeeCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
EmployeeDto employee = new EmployeeDto() | ||
{ | ||
FirstName = data[0], | ||
LastName = data[1], | ||
Salary = decimal.Parse(data[2]) | ||
}; | ||
|
||
this.UnitOfWork.Employees.AddEmployee(employee); | ||
this.UnitOfWork.Complete(); | ||
|
||
return $"User with name {data[0]} {data[1]} has been added!"; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...o Mapping Objects/NonStopMarket.App/Core/Commands/EmployeeCommands/EmployeeInfoCommand.cs
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,23 @@ | ||
namespace NonStopMarket.App.Core.Commands.EmployeeCommands | ||
{ | ||
using NonStopMarket.App.Core.Contracts; | ||
|
||
public class EmployeeInfoCommand : IExecutable | ||
{ | ||
public EmployeeInfoCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var id = int.Parse(data[0]); | ||
|
||
var employee = this.UnitOfWork.Employees.EmployeeInfo(id); | ||
|
||
return employee.ToString(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...g Objects/NonStopMarket.App/Core/Commands/EmployeeCommands/EmployeePersonalInfoCommand.cs
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,23 @@ | ||
namespace NonStopMarket.App.Core.Commands.EmployeeCommands | ||
{ | ||
using Contracts; | ||
|
||
public class EmployeePersonalInfoCommand : IExecutable | ||
{ | ||
public EmployeePersonalInfoCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var id = int.Parse(data[0]); | ||
|
||
var employee = this.UnitOfWork.Employees.EmployeePersonalInfo(id); | ||
|
||
return employee.ToString(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...uto Mapping Objects/NonStopMarket.App/Core/Commands/EmployeeCommands/SetAddressCommand.cs
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,26 @@ | ||
namespace NonStopMarket.App.Core.Commands.EmployeeCommands | ||
{ | ||
using NonStopMarket.App.Core.Contracts; | ||
using System.Linq; | ||
|
||
public class SetAddressCommand : IExecutable | ||
{ | ||
public SetAddressCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var id = int.Parse(data[0]); | ||
var address = string.Join(" ", data.Skip(1)); | ||
|
||
this.UnitOfWork.Employees.SetAddress(id, address); | ||
this.UnitOfWork.Complete(); | ||
|
||
return $"Address for user with id {id} has been changed!"; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...to Mapping Objects/NonStopMarket.App/Core/Commands/EmployeeCommands/SetBirthdayCommand.cs
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,29 @@ | ||
namespace NonStopMarket.App.Core.Commands.EmployeeCommands | ||
{ | ||
using System; | ||
|
||
using Contracts; | ||
|
||
public class SetBirthdayCommand : IExecutable | ||
{ | ||
public SetBirthdayCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public int MyProperty { get; set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var id = int.Parse(data[0]); | ||
var birthday = DateTime.Parse(data[1]); | ||
|
||
this.UnitOfWork.Employees.SetBirthday(id, birthday); | ||
this.UnitOfWork.Complete(); | ||
|
||
return $"Birthdate for user with id {id} has been changed!"; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...uto Mapping Objects/NonStopMarket.App/Core/Commands/ManagerCommands/ManagerInfoCommand.cs
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,23 @@ | ||
namespace NonStopMarket.App.Core.Commands.ManagerCommands | ||
{ | ||
using Contracts; | ||
|
||
class ManagerInfoCommand : IExecutable | ||
{ | ||
public ManagerInfoCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var id = int.Parse(data[0]); | ||
|
||
var manager = this.UnitOfWork.Employees.ManagerInfo(id); | ||
|
||
return manager.ToString(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
09.Auto Mapping Objects/NonStopMarket.App/Core/Commands/ManagerCommands/SetManagerCommand.cs
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,25 @@ | ||
namespace NonStopMarket.App.Core.Commands.ManagerCommands | ||
{ | ||
using Contracts; | ||
|
||
public class SetManagerCommand : IExecutable | ||
{ | ||
public SetManagerCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var employeeId = int.Parse(data[0]); | ||
var managerId = int.Parse(data[1]); | ||
|
||
this.UnitOfWork.Employees.SetManager(employeeId, managerId); | ||
this.UnitOfWork.Complete(); | ||
|
||
return $"Employee with id {employeeId} has manager with id {managerId}!"; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
09.Auto Mapping Objects/NonStopMarket.App/Core/Commands/OrderCommands/AddOrderCommand.cs
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 @@ | ||
namespace NonStopMarket.App.Core.Commands.OrderCommands | ||
{ | ||
using System; | ||
|
||
using Contracts; | ||
using NonStopMarket.Models; | ||
using NonStopMarket.Models.Enums; | ||
|
||
public class AddOrderCommand : IExecutable | ||
{ | ||
public AddOrderCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var empId = int.Parse(data[0]); | ||
var commandToEnum = (PaymentMethod)Enum.Parse(typeof(PaymentMethod), data[1], true); | ||
|
||
var order = new Order() | ||
{ | ||
PaymentMethod = commandToEnum, | ||
Date = DateTime.Now, | ||
EmployeeId = empId | ||
}; | ||
|
||
this.UnitOfWork.Orders.Add(order); | ||
this.UnitOfWork.Complete(); | ||
|
||
return "Order was added!"; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...Mapping Objects/NonStopMarket.App/Core/Commands/OrderCommands/GetOrdersByIncomeCommand.cs
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,35 @@ | ||
namespace NonStopMarket.App.Core.Commands.OrderCommands | ||
{ | ||
using System.Text; | ||
|
||
using NonStopMarket.App.Core.Contracts; | ||
|
||
public class GetOrdersByIncomeCommand : IExecutable | ||
{ | ||
public GetOrdersByIncomeCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var orders = this.UnitOfWork.Orders.GetOrdersByIncome(); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
foreach (var order in orders) | ||
{ | ||
sb.AppendLine($"ID: {order.OrderId}, Income: ${order.Income}"); | ||
|
||
foreach (var product in order.Products) | ||
{ | ||
sb.AppendLine($"--- ProductName: {product.Name} Price: ${product.Price}"); | ||
} | ||
} | ||
|
||
return sb.ToString().TrimEnd(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
09.Auto Mapping Objects/NonStopMarket.App/Core/Commands/ProductCommands/AddProductCommand.cs
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 @@ | ||
namespace NonStopMarket.App.Core.Commands.ProductCommands | ||
{ | ||
using Contracts; | ||
using NonStopMarket.Models; | ||
|
||
public class AddProductCommand : IExecutable | ||
{ | ||
public AddProductCommand(IUnitOfWork unitOfwork) | ||
{ | ||
this.UnitOfWork = unitOfwork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var name = data[0]; | ||
var totalQ = int.Parse(data[1]); | ||
var qInStock = int.Parse(data[2]); | ||
var price = decimal.Parse(data[3]); | ||
|
||
var product = new Product() | ||
{ | ||
Name = name, | ||
TotalQuantity = totalQ, | ||
QuantityInstock = qInStock, | ||
Price = price | ||
}; | ||
|
||
this.UnitOfWork.Products.Add(product); | ||
this.UnitOfWork.Complete(); | ||
|
||
return $"Product {name} was delivered in the market!"; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
... Mapping Objects/NonStopMarket.App/Core/Commands/ProductCommands/FindBestSellerCommand.cs
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,21 @@ | ||
namespace NonStopMarket.App.Core.Commands.ProductCommands | ||
{ | ||
using NonStopMarket.App.Core.Contracts; | ||
|
||
public class FindBestSellerCommand : IExecutable | ||
{ | ||
public FindBestSellerCommand(IUnitOfWork unitOfWork) | ||
{ | ||
this.UnitOfWork = unitOfWork; | ||
} | ||
|
||
public IUnitOfWork UnitOfWork { get; private set; } | ||
|
||
public string Execute(string[] data) | ||
{ | ||
var bestSeller = this.UnitOfWork.Products.FindBestSeller(); | ||
|
||
return $"ID: {bestSeller.ProductId}, Name: {bestSeller.Name}, SoldAmount: {bestSeller.SoldAmount}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.