Emelyanov A.S. LabWork_5 #6
@ -110,7 +110,7 @@ namespace FishFactoryClientApp.Controllers
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void Create(int product, int count)
|
||||
public void Create(int canned, int count)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
@ -123,16 +123,16 @@ namespace FishFactoryClientApp.Controllers
|
||||
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
CannedId = product,
|
||||
CannedId = canned,
|
||||
Count = count,
|
||||
Sum = Calc(count, product)
|
||||
Sum = Calc(count, canned)
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpPost]
|
||||
public double Calc(int count, int product)
|
||||
public double Calc(int count, int canned)
|
||||
{
|
||||
var prod = APIClient.GetRequest<CannedViewModel>($"api/main/getcanned?cannedId={product}");
|
||||
var prod = APIClient.GetRequest<CannedViewModel>($"api/main/getcanned?cannedId={canned}");
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
@section scripts{
|
||||
<script>
|
||||
$('#canned').on('change', function () {
|
||||
check();
|
||||
});
|
||||
@ -47,4 +48,5 @@
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
}
|
@ -942,13 +942,13 @@ $.validator.addMethod( "postcodeUK", function( value, element ) {
|
||||
*
|
||||
* The end result is that neither of these inputs:
|
||||
*
|
||||
* <input class="productinfo" name="partnumber">
|
||||
* <input class="productinfo" name="description">
|
||||
* <input class="cannedinfo" name="partnumber">
|
||||
* <input class="cannedinfo" name="description">
|
||||
*
|
||||
* ...will validate unless at least one of them is filled.
|
||||
*
|
||||
* partnumber: {require_from_group: [1,".productinfo"]},
|
||||
* description: {require_from_group: [1,".productinfo"]}
|
||||
* partnumber: {require_from_group: [1,".cannedinfo"]},
|
||||
* description: {require_from_group: [1,".cannedinfo"]}
|
||||
*
|
||||
* options[0]: number of fields that must be filled in the group
|
||||
* options[1]: CSS selector that defines the group of conditionally required fields
|
||||
@ -981,16 +981,16 @@ $.validator.addMethod( "require_from_group", function( value, element, options )
|
||||
*
|
||||
* The end result, is that none of these inputs:
|
||||
*
|
||||
* <input class="productinfo" name="partnumber">
|
||||
* <input class="productinfo" name="description">
|
||||
* <input class="productinfo" name="color">
|
||||
* <input class="cannedinfo" name="partnumber">
|
||||
* <input class="cannedinfo" name="description">
|
||||
* <input class="cannedinfo" name="color">
|
||||
*
|
||||
* ...will validate unless either at least two of them are filled,
|
||||
* OR none of them are.
|
||||
*
|
||||
* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
|
||||
* description: {skip_or_fill_minimum: [2,".productinfo"]},
|
||||
* color: {skip_or_fill_minimum: [2,".productinfo"]}
|
||||
* partnumber: {skip_or_fill_minimum: [2,".cannedinfo"]},
|
||||
* description: {skip_or_fill_minimum: [2,".cannedinfo"]},
|
||||
* color: {skip_or_fill_minimum: [2,".cannedinfo"]}
|
||||
*
|
||||
* options[0]: number of fields that must be filled in the group
|
||||
* options[1]: CSS selector that defines the group of conditionally required fields
|
||||
|
@ -12,12 +12,11 @@ namespace FishFactoryContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int CannedId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace FishFactoryContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int CannedId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
[DisplayName("Консерва")]
|
||||
public string CannedName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
@ -11,11 +11,11 @@ namespace FishFactoryDataModels.Models
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int CannedId { get; }
|
||||
int ClientId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
int ClientId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace FishFactoryDatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=FishFactoryLab5;Username=postgres;Password=postgres");
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=FishFactoryLab51;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -100,9 +100,7 @@ namespace FishFactoryDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FishFactoryDatabase();
|
||||
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders
|
||||
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace FishFactoryDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FishFactoryDatabase))]
|
||||
[Migration("20230327162742_Init")]
|
||||
[Migration("20230410133743_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -127,7 +127,7 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
b.Property<int>("CannedId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
@ -175,15 +175,21 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", null)
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CannedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Client", null)
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId");
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Canned");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
|
@ -62,12 +62,12 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CannedId = table.Column<int>(type: "integer", nullable: false),
|
||||
ClientId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
ClientId = table.Column<int>(type: "integer", nullable: true)
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -82,7 +82,8 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
name: "FK_Orders_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id");
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
@ -124,7 +124,7 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
b.Property<int>("CannedId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
@ -172,15 +172,21 @@ namespace FishFactoryDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", null)
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("CannedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Client", null)
|
||||
b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId");
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Canned");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
|
||||
|
@ -13,6 +13,7 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
@ -22,8 +23,6 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
|
@ -7,6 +7,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -14,30 +15,23 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int CannedId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
[Required]
|
||||
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
|
||||
public OrderStatus Status { get; set; }
|
||||
[Required]
|
||||
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public Canned Canned { get; private set; }
|
||||
|
||||
|
||||
public Client Client { get; private set; }
|
||||
public virtual Canned Canned { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
@ -47,30 +41,16 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
CannedId = model.CannedId,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
public static Order Create(OrderViewModel model)
|
||||
{
|
||||
return new Order
|
||||
{
|
||||
CannedId = model.CannedId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -82,6 +62,7 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
|
||||
Id = Id,
|
||||
CannedId = CannedId,
|
||||
ClientId = ClientId,
|
||||
@ -92,6 +73,6 @@ namespace FishFactoryDatabaseImplement.Models
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
CannedName = Canned.CannedName
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
@ -13,19 +12,19 @@ namespace FishFactoryRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly ICannedLogic _product;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, ICannedLogic product)
|
||||
private readonly ICannedLogic _canned;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, ICannedLogic canned)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_product = product;
|
||||
_canned = canned;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<CannedViewModel>? GetCannedList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _product.ReadList(null);
|
||||
return _canned.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -34,18 +33,18 @@ namespace FishFactoryRestApi.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public CannedViewModel? GetCanned(int productId)
|
||||
public CannedViewModel? GetCanned(int cannedId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _product.ReadElement(new CannedSearchModel
|
||||
return _canned.ReadElement(new CannedSearchModel
|
||||
{
|
||||
Id = productId
|
||||
Id = cannedId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения продукта по id={Id}",productId);
|
||||
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", cannedId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -62,7 +61,7 @@ namespace FishFactoryRestApi.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка заказов клиента id ={Id}", clientId);
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
|
Loading…
Reference in New Issue
Block a user