убрал (частично закомментил) ошибки для миграции. ДО МИГРАЦИИ

This commit is contained in:
ujijrujijr 2024-04-27 19:31:00 +04:00
parent cb2210f479
commit efe2bb327b
5 changed files with 42 additions and 37 deletions

View File

@ -24,9 +24,9 @@ namespace ComputerShopDatabaseImplement.Implements
{ {
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
return context.Orders return context.Orders
.Include(x => x.ShipmentOrders) .Include(x => x.Shipments)
.ThenInclude(x => x.Shipment) .ThenInclude(x => x.Shipment)
.Include(x => x.RequestOrders) .Include(x => x.Requests)
.ThenInclude(x => x.Request) .ThenInclude(x => x.Request)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -40,9 +40,9 @@ namespace ComputerShopDatabaseImplement.Implements
{ {
return context.Orders return context.Orders
.Where(x => (x.UserId == model.UserId) && (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)) .Where(x => (x.UserId == model.UserId) && (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo))
.Include(x => x.ShipmentOrders) .Include(x => x.Shipments)
.ThenInclude(x => x.Shipment) .ThenInclude(x => x.Shipment)
.Include(x => x.RequestOrders) .Include(x => x.Requests)
.ThenInclude(x => x.Request) .ThenInclude(x => x.Request)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -52,9 +52,9 @@ namespace ComputerShopDatabaseImplement.Implements
{ {
return context.Orders return context.Orders
.Where(x => (x.UserId == model.UserId) && (x.Status == model.Status)) .Where(x => (x.UserId == model.UserId) && (x.Status == model.Status))
.Include(x => x.ShipmentOrders) .Include(x => x.Shipments)
.ThenInclude(x => x.Shipment) .ThenInclude(x => x.Shipment)
.Include(x => x.RequestOrders) .Include(x => x.Requests)
.ThenInclude(x => x.Request) .ThenInclude(x => x.Request)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -63,9 +63,9 @@ namespace ComputerShopDatabaseImplement.Implements
//возвращение просто всех заказов пользователя (замена GetFullList) //возвращение просто всех заказов пользователя (замена GetFullList)
return context.Orders return context.Orders
.Where(x => x.UserId == model.UserId) .Where(x => x.UserId == model.UserId)
.Include(x => x.ShipmentOrders) .Include(x => x.Shipments)
.ThenInclude(x => x.Shipment) .ThenInclude(x => x.Shipment)
.Include(x => x.RequestOrders) .Include(x => x.Requests)
.ThenInclude(x => x.Request) .ThenInclude(x => x.Request)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -80,9 +80,9 @@ namespace ComputerShopDatabaseImplement.Implements
} }
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
return context.Orders return context.Orders
.Include(x => x.ShipmentOrders) .Include(x => x.Shipments)
.ThenInclude(x => x.Shipment) .ThenInclude(x => x.Shipment)
.Include(x => x.RequestOrders) .Include(x => x.Requests)
.ThenInclude(x => x.Request) .ThenInclude(x => x.Request)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }

View File

@ -14,28 +14,21 @@ namespace ComputerShopDatabaseImplement.Implements
{ {
public class UserStorage : IUserStorage public class UserStorage : IUserStorage
{ {
//!!!ТУТ МБ РАЗДЕЛИТЬ НА 2 МЕТОДА: исполнителя и поручителя и добавить where public List<UserViewModel> GetFullList()
public List<UserViewModel> GetFullList(UserRole role)
{ {
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
return context.Users.Where(x => x.Role == role).Select(x => x.GetViewModel).ToList(); return context.Users.Select(x => x.GetViewModel).ToList();
} }
//!!!ТУТ МБ РАЗДЕЛИТЬ НА 2 МЕТОДА: исполнителя и поручителя и добавить where //Фильтрация пользователей логически нужна только для роли (по остальным параметрам будет 1 или 0 пользователей)
//!!!ДОПИСАТЬ
//!!!мб не надо, т.к. есть getelement для получения 1 пользователя и получение всех пользователей по роли.
//при фильтрации всегда (?) будет либо 1, либо все пользователи роли
public List<UserViewModel> GetFilteredList(UserSearchModel model) public List<UserViewModel> GetFilteredList(UserSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Login)) if (model.Role == null || model.Role == UserRole.Неизвестная)
{ {
return new(); return new();
} }
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
if (!string.IsNullOrEmpty(model.Login)) return context.Users.Where(x => x.Role == model.Role).Select(x => x.GetViewModel).ToList();
{
}
} }
//!!!ПРОВЕРИТЬ //!!!ПРОВЕРИТЬ
@ -46,10 +39,18 @@ namespace ComputerShopDatabaseImplement.Implements
return null; return null;
} }
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
return context.Users.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) //Получение по логину (пользователей с таким логином будет 1 или 0)
|| (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) if (!string.IsNullOrEmpty(model.Login))
|| (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email)) {
?.GetViewModel; return context.Users.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
}
//Получение по почте (пользователей с такой почтой будет 1 или 0)
else if (!string.IsNullOrEmpty(model.Email))
{
return context.Users.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel;
}
//Получение по id
return context.Users.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }
public UserViewModel? Insert(UserBindingModel model) public UserViewModel? Insert(UserBindingModel model)

View File

@ -29,16 +29,15 @@ namespace ComputerShopDatabaseImplement.Models
[Required] [Required]
public double Sum { get; private set; } public double Sum { get; private set; }
//!!!мб не нужен
public virtual User User { get; set; }
//!!!ПРОВЕРМТЬ, ЧТО ПАРВИЛЬНЫЕ ВНЕШНИЕ КЛЮЧИ //!!!ПРОВЕРМТЬ, ЧТО ПАРВИЛЬНЫЕ ВНЕШНИЕ КЛЮЧИ
[ForeignKey("OrderId")] [ForeignKey("OrderId")]
public virtual List<RequestOrder> RequestOrders { get; set; } = new(); public virtual List<RequestOrder> Requests { get; set; } = new();
//!!!было ShipmentOrders
[ForeignKey("OrderId")] [ForeignKey("OrderId")]
public virtual List<ShipmentOrder> ShipmentOrders { get; set; } = new(); public virtual List<ShipmentOrder> Shipments { get; set; } = new();
public static Order? Create(OrderBindingModel model) public static Order? Create(OrderBindingModel model)
{ {
@ -63,7 +62,6 @@ namespace ComputerShopDatabaseImplement.Models
return; return;
} }
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
//!!!МБ НАДО БУДЕТ ОБНОВЛЯТЬ ПОЛЬЗОВАТЕЛЯ, НО ОН ПО СУТИ НЕ ДОЛЖЕН ОБНОВЛЯТЬСЯ ПОСЛЕ СОЗДАНИЯ
Status = model.Status; Status = model.Status;
context.SaveChanges(); context.SaveChanges();
} }

View File

@ -4,17 +4,22 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
//!!!ÇÀÃËÓØÊÀ: ÇÀÊÎÌÌÅÍÒÈË, ×ÒÎÁÛ ÍÎÐÌÀËÜÍÎ ÑÎÇÄÀËÀÑÜ ÌÈÃÐÀÖÈß
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); //builder.Services.AddSwaggerGen(c =>
//{
// c.SwaggerDoc("v1", new OpenApiInfo { Title = "GarmentFactoryRestApi", Version = "v1" });
//});
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) //if (app.Environment.IsDevelopment())
{ //{
app.UseSwagger(); // app.UseSwagger();
app.UseSwaggerUI(); // app.UseSwaggerUI();
} //}
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View File

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup> </ItemGroup>