CostItem create
This commit is contained in:
parent
12851df7fc
commit
1a5a000ef4
@ -95,7 +95,11 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
if (string.IsNullOrEmpty(model.Name)) {
|
||||
throw new ArgumentNullException("Отсутствует название статьи затрат", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}");
|
||||
if (model.CostNum <= 0) {
|
||||
throw new ArgumentOutOfRangeException("Номер счета должен идти от 1");
|
||||
}
|
||||
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" +
|
||||
$"CostNum:{model.CostNum}");
|
||||
var element = _storage.GetElement(new CostItemSearchModel { ID = model.ID });
|
||||
if (element != null && element.ID != model.EmployeeID)
|
||||
{
|
||||
|
@ -14,5 +14,7 @@ namespace ElectronicsShopContracts.BindingModels {
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public int CostNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ namespace ElectronicsShopContracts.SearchModels {
|
||||
public class CostItemSearchModel {
|
||||
public int? ID { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? CostNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,8 @@ namespace ElectronicsShopContracts.ViewModels {
|
||||
|
||||
[DisplayName("Затраты")]
|
||||
public double Price { get; set; }
|
||||
|
||||
[DisplayName("Номер счета")]
|
||||
public int CostNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace ElectronicsShopDataBaseImplement
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false) {
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase11;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20240527144429_test")]
|
||||
partial class test
|
||||
[Migration("20240527175902_InitMigration")]
|
||||
partial class InitMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -58,6 +58,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostNum")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeeID")
|
||||
.HasColumnType("int");
|
||||
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class test : Migration
|
||||
public partial class InitMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@ -34,7 +34,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
EmployeeID = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
Price = table.Column<double>(type: "float", nullable: false),
|
||||
CostNum = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
@ -55,6 +55,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("CostNum")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeeID")
|
||||
.HasColumnType("int");
|
||||
|
||||
|
@ -24,7 +24,10 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
public static CostItem? Create(CostItemBindingModel? model)
|
||||
[Required]
|
||||
public int CostNum { get; set; }
|
||||
|
||||
public static CostItem? Create(CostItemBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -36,6 +39,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
EmployeeID = model.EmployeeID,
|
||||
Name = model.Name,
|
||||
Price = model.Price,
|
||||
CostNum = model.CostNum,
|
||||
};
|
||||
}
|
||||
public void Update(CostItemBindingModel? model)
|
||||
@ -47,6 +51,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
EmployeeID = model.EmployeeID;
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
CostNum = model.CostNum;
|
||||
}
|
||||
|
||||
public CostItemViewModel GetViewModel => new()
|
||||
@ -55,7 +60,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
EmployeeID = EmployeeID,
|
||||
Name = Name,
|
||||
Price = Price,
|
||||
CostNum = CostNum,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace ElectronicsShopDataModels.Models {
|
||||
int EmployeeID { get; }
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
int CostNum { get; }
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,27 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateCostItem() {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateCostItem(string name, double price, int costNum) {
|
||||
if (APIEmployee.Employee == null) {
|
||||
throw new Exception("Ňîëüęî äë˙ ŕâňîđčçîâŕíűő");
|
||||
}
|
||||
if (price <= 0) {
|
||||
throw new Exception("Ńóěěŕ çŕňđŕň äîëćíŕ áűňü áîëüřĺ 0");
|
||||
}
|
||||
APIEmployee.PostRequest("api/main/createcostitem", new CostItemBindingModel {
|
||||
EmployeeID = APIEmployee.Employee.ID,
|
||||
Name = name,
|
||||
Price = price,
|
||||
CostNum = costNum
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Create() {
|
||||
ViewBag.Orders = APIEmployee.GetRequset<List<ProductViewModel>>("api/main/getproductlist");
|
||||
@ -96,7 +117,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(int price, int costItem, string productName) {
|
||||
public void Create(int price, int costNum, string productName) {
|
||||
if (APIEmployee.Employee == null) {
|
||||
throw new Exception("Òîëüêî äëÿ àâòîðèçîâàííûõ");
|
||||
}
|
||||
@ -104,9 +125,9 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
throw new Exception("Ñòîèìîñòü òîâàðà äîëæíà áûòü áîëüøå 0");
|
||||
}
|
||||
APIEmployee.PostRequest("api/main/createproduct", new ProductBindingModel {
|
||||
CostItemID = costItem,
|
||||
CostItemID = costNum,
|
||||
ProductName = productName,
|
||||
Price = Calc(price, costItem)
|
||||
Price = Calc(price, costNum)
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
@{
|
||||
ViewData["Title"] = "CreateCostItem";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание статьи затрат</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Название статьи затрат:</div>
|
||||
<div class="col-8">
|
||||
<input id="name" type="text" name="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Номер счета:</div>
|
||||
<div class="col-8">
|
||||
<input id="costnum" type="text" name="costnum" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Затраты:</div>
|
||||
<div class="col-8">
|
||||
<input id="price" type="text" name="price" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8">
|
||||
<input type="submit" value="Создать" class="btn btn-outline-primary"/>
|
||||
</div>
|
||||
</div>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('#price').on('price', function () {
|
||||
check();
|
||||
}
|
||||
$('#costnum').on('costnum', function () {
|
||||
check();
|
||||
}
|
||||
function check() {
|
||||
var price = $('#price').val();
|
||||
var costnum = $('#costnum').val();
|
||||
}
|
||||
</script>
|
@ -14,11 +14,14 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductLogic _product;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly ICostItemLogic _costItem;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IProductLogic product, IOrderLogic orderLogic) {
|
||||
public MainController(ILogger<MainController> logger, IProductLogic product,
|
||||
IOrderLogic orderLogic, ICostItemLogic costItemLogic) {
|
||||
_logger = logger;
|
||||
_product = product;
|
||||
_order = orderLogic;
|
||||
_costItem = costItemLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -72,6 +75,17 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
return;
|
||||
}
|
||||
|
||||
//Мейби нужны будут удаления, обновления, выбор конкретного заказа или продукта. Короче потом....
|
||||
[HttpPost]
|
||||
public void CreateCostItem(CostItemBindingModel model) {
|
||||
try {
|
||||
_costItem.Create(model);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
//Мейби нужны будут удаления, обновления, выбор конкретного заказа или продукта. Короче потом...
|
||||
//А также для статей затрат.
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,13 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
|
||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<ICostItemStorage, CostItemStorage>();
|
||||
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<ICostItemLogic, CostItemLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
Loading…
Reference in New Issue
Block a user