омега починка в 3 ночи
This commit is contained in:
parent
ac6fe67c5c
commit
3b0e3e475a
@ -11,6 +11,8 @@ namespace CarCenterContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
public long? VINnumber { get; set; }
|
||||
public int? StorekeeperId { get; set; }
|
||||
public int? FeatureId { get; set; }
|
||||
public int? OrderId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,7 +18,9 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
return context.Bundlings
|
||||
.Select(x => x.GetViewModel)
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<BundlingViewModel> GetFilteredList(BundlingSearchModel model)
|
||||
@ -28,9 +31,15 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new CarCenterDatabase();
|
||||
if (model.DateFrom.HasValue)
|
||||
return context.Bundlings.Where(x => x.StorekeeperId == model.StorekeeperId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
|
||||
return context.Bundlings
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.Where(x => x.StorekeeperId == model.StorekeeperId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList();
|
||||
else
|
||||
return context.Bundlings.Where(x => x.StorekeeperId == model.StorekeeperId).Select(x => x.GetViewModel).ToList();
|
||||
return context.Bundlings
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.Where(x => x.StorekeeperId == model.StorekeeperId).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public BundlingViewModel? GetElement(BundlingSearchModel model)
|
||||
{
|
||||
@ -40,13 +49,15 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
return context.Bundlings
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public BundlingViewModel? Insert(BundlingBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var newBundling = Bundling.Create(model);
|
||||
var newBundling = Bundling.Create(context, model);
|
||||
if (newBundling == null)
|
||||
{
|
||||
return null;
|
||||
@ -54,7 +65,9 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
context.Bundlings.Add(newBundling);
|
||||
context.SaveChanges();
|
||||
return context.Bundlings
|
||||
.FirstOrDefault(x => x.Id == newBundling.Id)
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == newBundling.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public BundlingViewModel? Update(BundlingBindingModel model)
|
||||
@ -66,8 +79,11 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
order.UpdatePresales(context, model);
|
||||
context.SaveChanges();
|
||||
return context.Bundlings
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
@ -75,11 +91,15 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var element = context.Bundlings
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Bundlings
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
.Include(x => x.PresaleBundling)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Bundlings.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
@ -50,6 +50,19 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.FeatureId.HasValue)
|
||||
{
|
||||
return context.Cars
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Feature)
|
||||
.Where(x => x.FeatureID == model.FeatureId && x.OrderId == model.OrderId)
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Storekeeper)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
return new();
|
||||
}
|
||||
public CarViewModel? GetElement(CarSearchModel model)
|
||||
@ -96,6 +109,7 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
car.Update(model);
|
||||
car.UpdateBundlings(context, model);
|
||||
context.SaveChanges();
|
||||
return context.Cars
|
||||
.Include(x => x.Bundlings)
|
||||
|
@ -3,6 +3,7 @@ using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using CarCenterDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -57,21 +58,36 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue) //для списка Сагиров
|
||||
{
|
||||
//будет применятся в ReportLogic
|
||||
return context.Orders
|
||||
.Where(x => x.WorkerId == model.WorkerId)
|
||||
.Include(x => x.Worker)
|
||||
.Include(x => x.Cars)
|
||||
.Include(x => x.Presales)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.ThenInclude(x => x.Requests)
|
||||
.Include(x => x.Presales)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.ThenInclude(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Where(x => x.PaymentDate >= model.DateFrom && x.PaymentDate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if(model.WorkerId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Worker)
|
||||
.Where(x => x.WorkerId == model.WorkerId)
|
||||
.Include(x => x.Cars)
|
||||
.Include(x => x.Presales)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.ThenInclude(x => x.Requests)
|
||||
.Include(x => x.Presales)
|
||||
//.Where(x => x.PaymentDate >= model.DateFrom && x.PaymentDate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Worker)
|
||||
//.Where(x => x.WorkerId == model.WorkerId)
|
||||
.Include(x => x.Cars)
|
||||
.ThenInclude(y => y.Bundlings.Where(b => b.BundlingId == model.BundlingId))
|
||||
.Include(x => x.Presales)
|
||||
.ThenInclude(x => x.Presale)
|
||||
.ThenInclude(x => x.Requests)
|
||||
.Include(x => x.Presales)
|
||||
//.Where(x => x.PaymentDate >= model.DateFrom && x.PaymentDate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
else if (model.Presales.Count > 0) //для отчета Сагиров
|
||||
{
|
||||
@ -152,6 +168,8 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
order.UpdateCars(context, model);
|
||||
order.UpdatePresales(context, model);
|
||||
context.SaveChanges();
|
||||
return context.Orders
|
||||
.Include(x => x.Worker)
|
||||
|
@ -23,7 +23,6 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
var deletedElement = context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -43,7 +42,6 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
}
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -56,7 +54,6 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.Where(x => x.WorkerId == model.WorkerId)
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -70,7 +67,6 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
using var context = new CarCenterDatabase();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -88,7 +84,6 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.FirstOrDefault(x => x.Id == newPresale.Id)
|
||||
?.GetViewModel;
|
||||
@ -104,11 +99,10 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
order.UpdateBundlings(context, model);
|
||||
order.UpdateBundlings(context, model);
|
||||
order.UpdateRequests(context, model);
|
||||
context.SaveChanges();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Include(x => x.Requests)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace CarCenterDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarCenterDatabase))]
|
||||
[Migration("20240529170508_predFin2")]
|
||||
partial class predFin2
|
||||
[Migration("20240529194318_pochti")]
|
||||
partial class pochti
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
@ -6,7 +6,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
namespace CarCenterDatabaseImplement.Migrations
|
||||
{
|
||||
public partial class predFin2 : Migration
|
||||
public partial class pochti : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
@ -31,7 +31,21 @@ namespace CarCenterDatabaseImplement.Models
|
||||
public virtual List<CarBundling> CarBundling { get; set; } = new();
|
||||
[ForeignKey("BundlingId")]
|
||||
public virtual List<PresaleBundling> PresaleBundling { get; set; } = new();
|
||||
public static Bundling? Create(BundlingBindingModel model)
|
||||
private Dictionary<int, IPresaleModel>? _bundlingPresales = null;
|
||||
public Dictionary<int, IPresaleModel> BundlingPresales
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bundlingPresales == null)
|
||||
{
|
||||
_bundlingPresales = PresaleBundling
|
||||
.GroupBy(recPc => recPc.PresaleId)
|
||||
.ToDictionary(g => g.Key, g => g.First().Presale as IPresaleModel);
|
||||
}
|
||||
return _bundlingPresales;
|
||||
}
|
||||
}
|
||||
public static Bundling? Create(CarCenterDatabase context, BundlingBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -46,20 +60,11 @@ namespace CarCenterDatabaseImplement.Models
|
||||
ToolKit = model.ToolKit,
|
||||
Price = model.Price,
|
||||
DateCreate = model.DateCreate,
|
||||
};
|
||||
}
|
||||
public static Bundling Create(BundlingViewModel model)
|
||||
{
|
||||
return new Bundling
|
||||
{
|
||||
Id = model.Id,
|
||||
StorekeeperId=model.StorekeeperId,
|
||||
EquipmentPackage = model.EquipmentPackage,
|
||||
TirePackage = model.TirePackage,
|
||||
ToolKit = model.ToolKit,
|
||||
Price = model.Price,
|
||||
DateCreate = model.DateCreate,
|
||||
};
|
||||
PresaleBundling = model.BundlingsPresale.Select(x => new PresaleBundling
|
||||
{
|
||||
Presale = context.Presales.First(y => y.Id == x.Value.Id)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(BundlingBindingModel model)
|
||||
{
|
||||
@ -74,7 +79,29 @@ namespace CarCenterDatabaseImplement.Models
|
||||
ToolKit = model.ToolKit;
|
||||
Price = model.Price;
|
||||
}
|
||||
public BundlingViewModel GetViewModel => new()
|
||||
public void UpdatePresales(CarCenterDatabase context, BundlingBindingModel model)
|
||||
{
|
||||
var bundling = context.Bundlings.First(x => x.Id == Id);
|
||||
var existingPresaleBundlings = context.PresaleBundlings.Where(pb => pb.BundlingId == bundling.Id).ToList();
|
||||
context.PresaleBundlings.RemoveRange(existingPresaleBundlings);
|
||||
context.SaveChanges();
|
||||
foreach (var pc in model.BundlingsPresale)
|
||||
{
|
||||
var tmp = new PresaleBundling
|
||||
{
|
||||
Bundling = bundling,
|
||||
Presale = context.Presales.First(x => x.Id == pc.Value.Id),
|
||||
};
|
||||
if (context.PresaleBundlings.Contains(tmp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
context.PresaleBundlings.Add(tmp);
|
||||
context.SaveChanges();
|
||||
}
|
||||
_bundlingPresales = null;
|
||||
}
|
||||
public BundlingViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StorekeeperId = StorekeeperId,
|
||||
@ -83,6 +110,7 @@ namespace CarCenterDatabaseImplement.Models
|
||||
ToolKit = ToolKit,
|
||||
Price = Price,
|
||||
DateCreate = DateCreate,
|
||||
BundlingsPresale = BundlingPresales,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,10 @@ namespace CarCenterDatabaseImplement.Models
|
||||
public void UpdateBundlings(CarCenterDatabase context, CarBindingModel model)
|
||||
{
|
||||
var car = context.Cars.First(x => x.Id == Id);
|
||||
foreach (var pc in model.CarBundlings)
|
||||
var existingBundling = context.CarBundlings.Where(pb => pb.CarId == car.Id).ToList();
|
||||
context.CarBundlings.RemoveRange(existingBundling);
|
||||
context.SaveChanges();
|
||||
foreach (var pc in model.CarBundlings)
|
||||
{
|
||||
context.CarBundlings.Add(new CarBundling
|
||||
{
|
||||
|
@ -38,7 +38,9 @@ namespace CarCenterDatabaseImplement.Models
|
||||
{
|
||||
if(_orderPresales == null)
|
||||
{
|
||||
_orderPresales = Presales.ToDictionary(recPc => recPc.PresaleId, recPc => recPc.Presale as IPresaleModel);
|
||||
_orderPresales = Presales
|
||||
.GroupBy(recPc => recPc.PresaleId)
|
||||
.ToDictionary(g => g.Key, g => g.First().Presale as IPresaleModel);
|
||||
}
|
||||
return _orderPresales;
|
||||
}
|
||||
@ -91,18 +93,44 @@ namespace CarCenterDatabaseImplement.Models
|
||||
public void UpdatePresales(CarCenterDatabase context, OrderBindingModel model)
|
||||
{
|
||||
var order = context.Orders.First(x => x.Id == Id);
|
||||
foreach (var pc in model.OrderPresales)
|
||||
var existingPresale = context.OrderPresales.Where(pb => pb.OrderId == order.Id).ToList();
|
||||
context.OrderPresales.RemoveRange(existingPresale);
|
||||
context.SaveChanges();
|
||||
foreach (var pc in model.OrderPresales)
|
||||
{
|
||||
context.OrderPresales.Add(new OrderPresale
|
||||
var tmp = new OrderPresale
|
||||
{
|
||||
Order = order,
|
||||
Presale = context.Presales.First(x => x.Id == pc.Key),
|
||||
});
|
||||
Presale = context.Presales.First(x => x.Id == pc.Value.Id),
|
||||
};
|
||||
if (context.OrderPresales.Contains(tmp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
context.OrderPresales.Add(tmp);
|
||||
context.SaveChanges();
|
||||
}
|
||||
_orderPresales = null;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
public void UpdateCars(CarCenterDatabase context, OrderBindingModel model)
|
||||
{
|
||||
var order = context.Orders.First(x => x.Id == Id);
|
||||
order.Cars.Clear();
|
||||
foreach (var car in model.Cars)
|
||||
{
|
||||
var cartmp = context.Cars.FirstOrDefault(x => x.Id == car.Value.Id);
|
||||
if (cartmp != null)
|
||||
{
|
||||
if (order.Cars.Contains(cartmp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
order.Cars.Add(cartmp);
|
||||
}
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WorkerId = WorkerId,
|
||||
|
@ -31,15 +31,18 @@ namespace CarCenterDatabaseImplement.Models
|
||||
|
||||
private Dictionary<int, IBundlingModel>? _presaleBundlings = null;
|
||||
[ForeignKey("PresaleId")]
|
||||
public virtual List<PresaleBundling> Bundlings { get; set; } = new();
|
||||
public Dictionary<int, IBundlingModel> PresaleBundlings
|
||||
public virtual List<PresaleBundling>? Bundlings { get; set; } = new();
|
||||
[NotMapped]
|
||||
public Dictionary<int, IBundlingModel> PresaleBundlings
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_presaleBundlings == null)
|
||||
{
|
||||
_presaleBundlings = Bundlings.ToDictionary(recPc => recPc.BundlingId, recPc => recPc.Bundling as IBundlingModel);
|
||||
}
|
||||
_presaleBundlings = Bundlings
|
||||
.GroupBy(recPc => recPc.BundlingId)
|
||||
.ToDictionary(g => g.Key, g => g.First().Bundling as IBundlingModel);
|
||||
}
|
||||
return _presaleBundlings;
|
||||
}
|
||||
}
|
||||
@ -59,13 +62,13 @@ namespace CarCenterDatabaseImplement.Models
|
||||
WorkerId = model.WorkerId,
|
||||
Bundlings = model.PresaleBundlings.Select(x => new PresaleBundling
|
||||
{
|
||||
Bundling = context.Bundlings.First(y => y.Id == x.Value.Id)
|
||||
Bundling = context.Bundlings.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
foreach (var request in model.Requests)
|
||||
{
|
||||
var requesttmp = context.Requests.FirstOrDefault(x => x.Id == request.Value.Id);
|
||||
var requesttmp = context.Requests.FirstOrDefault(x => x.Id == request.Key);
|
||||
if (requesttmp != null)
|
||||
{
|
||||
presale.Requests.Add(requesttmp);
|
||||
@ -75,29 +78,41 @@ namespace CarCenterDatabaseImplement.Models
|
||||
return presale;
|
||||
}
|
||||
|
||||
public void UpdateBundlings(CarCenterDatabase context, PresaleBindingModel model)
|
||||
public void UpdateRequests(CarCenterDatabase context, PresaleBindingModel model)
|
||||
{
|
||||
var presale = context.Presales.First(x => x.Id == Id);
|
||||
foreach (var request in model.Requests)
|
||||
{
|
||||
var requesttmp = context.Requests.FirstOrDefault(x => x.Id == request.Value.Id);
|
||||
var requesttmp = context.Requests.FirstOrDefault(x => x.Id == request.Key);
|
||||
if (requesttmp != null)
|
||||
{
|
||||
if (presale.Requests.Contains(requesttmp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
presale.Requests.Add(requesttmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRequests(CarCenterDatabase context, PresaleBindingModel model)
|
||||
public void UpdateBundlings(CarCenterDatabase context, PresaleBindingModel model)
|
||||
{
|
||||
var presale = context.Presales.First(x => x.Id == Id);
|
||||
var existingBundling = context.PresaleBundlings.Where(pb => pb.PresaleId == presale.Id).ToList();
|
||||
context.PresaleBundlings.RemoveRange(existingBundling);
|
||||
context.SaveChanges();
|
||||
foreach (var pc in model.PresaleBundlings)
|
||||
{
|
||||
context.PresaleBundlings.Add(new PresaleBundling
|
||||
var tmp = new PresaleBundling
|
||||
{
|
||||
Presale = presale,
|
||||
Bundling = context.Bundlings.First(x => x.Id == pc.Value.Id),
|
||||
});
|
||||
Bundling = context.Bundlings.First(x => x.Id == pc.Key),
|
||||
};
|
||||
if (context.PresaleBundlings.Contains(tmp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
context.PresaleBundlings.Add(tmp);
|
||||
context.SaveChanges();
|
||||
}
|
||||
_presaleBundlings = null;
|
||||
|
@ -5,6 +5,8 @@ using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterBusinessLogic.MailWorker;
|
||||
using CarCenterBusinessLogic.OfficePackage;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
|
||||
namespace StorekeeperApp
|
||||
{
|
||||
@ -120,24 +122,56 @@ namespace StorekeeperApp
|
||||
{
|
||||
return _carLogic.Delete(new() { Id = carId });
|
||||
}
|
||||
public List<ReportBundlingViewModel> GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
|
||||
public List<ReportBundlingViewModel> GetTimeReport(DateTime? startDate, DateTime? endDate, int userId)
|
||||
{
|
||||
var bundlings = _bundlingLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, StorekeeperId = UserId });
|
||||
var bundlings = _bundlingLogic.ReadList(new BundlingSearchModel { StorekeeperId = userId });
|
||||
if (bundlings == null)
|
||||
return new();
|
||||
return new List<ReportBundlingViewModel>();
|
||||
|
||||
List<ReportBundlingViewModel> bundlingTimeReports = new List<ReportBundlingViewModel>();
|
||||
|
||||
foreach (var bundling in bundlings)
|
||||
{
|
||||
var report = new ReportBundlingViewModel();
|
||||
report.BundlingId = bundling.Id;
|
||||
var features = _featureLogic.ReadList(new() { BundlingId = bundling.Id, StorekeeperId = UserId });
|
||||
if (features != null)
|
||||
report.Features = features.Select(p => p.Id.ToString()).ToList();
|
||||
var orders = _orderLogic.ReadList(new() { BundlingId = bundling.Id, WorkerId = UserId });
|
||||
if (orders != null)
|
||||
report.Orders = orders.Select(p => p.Id.ToString()).ToList();
|
||||
var report = new ReportBundlingViewModel
|
||||
{
|
||||
BundlingId = bundling.Id,
|
||||
Features = new List<string>(),
|
||||
Orders = new List<string>()
|
||||
};
|
||||
|
||||
// Получение Orders
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel { BundlingId = bundling.Id, DateFrom = startDate, DateTo = endDate });
|
||||
if (orders?.Count != 0 && orders != null)
|
||||
{
|
||||
// Получение Features из машин в заказах
|
||||
var features = new List<string>();
|
||||
foreach (var order in orders)
|
||||
{
|
||||
bool fnd = false;
|
||||
var cars = order.Cars;
|
||||
foreach (var car in cars) {
|
||||
if(car.Value.CarBundlings.Count <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var carFeatures = _carLogic.ReadList(new CarSearchModel { FeatureId = car.Value.FeatureID, OrderId = order.Id });
|
||||
if (carFeatures?.Count != 0 && carFeatures != null)
|
||||
{
|
||||
fnd = true;
|
||||
features.AddRange(carFeatures.Select(f => f.FeatureID.ToString()));
|
||||
}
|
||||
}
|
||||
if (fnd)
|
||||
{
|
||||
report.Orders.Add(order.Id.ToString());
|
||||
}
|
||||
}
|
||||
report.Features = features.Distinct().ToList(); // Удаление дубликатов
|
||||
}
|
||||
|
||||
bundlingTimeReports.Add(report);
|
||||
}
|
||||
|
||||
return bundlingTimeReports;
|
||||
}
|
||||
public List<PresaleViewModel>? GetPresales()
|
||||
@ -149,18 +183,25 @@ namespace StorekeeperApp
|
||||
return _orderLogic.ReadList(null);
|
||||
}
|
||||
|
||||
public List<ReportCarViewModel>? GetPresaleReports(List<int> bundlings)
|
||||
public List<ReportCarViewModel>? GetPresaleReports(List<int> cars)
|
||||
{
|
||||
List<ReportCarViewModel> reports = new();
|
||||
foreach (int i in bundlings)
|
||||
|
||||
var orders = _orderLogic.ReadList(null);
|
||||
foreach (var order in orders)
|
||||
{
|
||||
ReportCarViewModel report = new();
|
||||
var bundling = _carLogic.ReadElement(new() { Id = i });
|
||||
report.VINnumber = (int)bundling!.VINnumber;
|
||||
var presales = _presaleLogic.ReadList(new() { CarId = i });
|
||||
if (presales != null)
|
||||
report.Presales = presales.Select(w => w.Id.ToString()).ToList();
|
||||
reports.Add(report);
|
||||
var Cars = order.Cars;
|
||||
foreach (var car in Cars)
|
||||
{
|
||||
ReportCarViewModel report = new();
|
||||
report.VINnumber = (int)car.Value.VINnumber;
|
||||
if (cars.Contains(car.Value.Id))
|
||||
{
|
||||
report.Presales = order.OrderPresales.Select(p => p.Value.Id.ToString()).ToList();
|
||||
}
|
||||
reports.Add(report);
|
||||
}
|
||||
|
||||
}
|
||||
return reports;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<select name="EquipmentPackage" id="EquipmentPackage" value="@Model.EquipmentPackage">
|
||||
@foreach (var value in Enum.GetValues(typeof(EquipmentPackage)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.EquipmentPackage) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="EquipmentPackageError" class="text-danger"></span>
|
||||
@ -28,7 +28,7 @@
|
||||
<select name="TirePackage" id="TirePackage" value="@Model.TirePackage">
|
||||
@foreach (var value in Enum.GetValues(typeof(TirePackage)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.TirePackage) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="TirePackageError" class="text-danger"></span>
|
||||
@ -40,7 +40,7 @@
|
||||
<select name="ToolKit" id="ToolKit" value="@Model.ToolKit">
|
||||
@foreach (var value in Enum.GetValues(typeof(ToolKit)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.ToolKit) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="ToolKiteError" class="text-danger"></span>
|
||||
@ -99,6 +99,11 @@
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$(document).on('click', '.deletePresale', function () {
|
||||
var row = $(this).closest('tr');
|
||||
row.remove();
|
||||
updateSum();
|
||||
});
|
||||
$('#addPresale').click(function () {
|
||||
var selectedPresale = $('#presaleSelect option:selected');
|
||||
if (selectedPresale.val()) {
|
||||
@ -111,20 +116,23 @@
|
||||
}
|
||||
});
|
||||
if (exists) {
|
||||
alert('Эта комплектация уже добавлена.');
|
||||
alert('Эта работа уже добавлена.');
|
||||
return;
|
||||
}
|
||||
|
||||
var presaleName = selectedPresale.text();
|
||||
var presalePrice = selectedPresale.data('price');
|
||||
|
||||
var newRow = `
|
||||
<tr data-presale-id="${presaleId}">
|
||||
<tr data-presale-id="${presaleId}">
|
||||
<td>
|
||||
<input type="hidden" name="presaleIds" value="${presaleId}" />
|
||||
${presaleId}
|
||||
<input type="hidden" name="presaleIds" value="${presaleId}" />
|
||||
${presaleId}
|
||||
</td>
|
||||
<th> </th>
|
||||
<td><button type="button" class="deletePresale" data-presale-id="${presaleId}">Удалить</button></td>
|
||||
<td class="presale-price" data-price="${presalePrice}">${presalePrice}</td>
|
||||
<th> </th>
|
||||
<td><button type="button" class="deletePresale" data-presale-id="${presaleId}">Удалить</button></td>
|
||||
</tr>
|
||||
`;
|
||||
$('#presalesTable tbody').append(newRow);
|
||||
@ -139,7 +147,7 @@
|
||||
|
||||
updateSum();
|
||||
} else {
|
||||
alert('Выберите комплектацию для добавления');
|
||||
alert('Выберите работу для добавления');
|
||||
}
|
||||
});
|
||||
$('#bundlinglForm').submit(function (event) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
<select name="CarBrand" id="CarBrand" value="@Model.CarBrand">
|
||||
@foreach (var value in Enum.GetValues(typeof(CarBrand)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.CarBrand) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="CarBrandError" class="text-danger"></span>
|
||||
@ -36,7 +36,7 @@
|
||||
<select name="CarClass" id="CarClass" value="@Model.CarClass">
|
||||
@foreach (var value in Enum.GetValues(typeof(CarClass)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.CarClass) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="CarClassError" class="text-danger"></span>
|
||||
@ -62,7 +62,7 @@
|
||||
<select name="FeatureId" id="FeatureId">
|
||||
@foreach (var feature in ViewBag.Features)
|
||||
{
|
||||
<option value="@feature.Id">Особенность @feature.Id</option>
|
||||
<option value="@feature.Id" selected="@(feature.Id.Equals(Model.FeatureID) ? "selected" : null)">Особенность @feature.Id</option>
|
||||
}
|
||||
</select>
|
||||
<span id="FeatureIdError" class="text-danger"></span>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<select name="HelpDevice" id="HelpDevice" value="@Model.HelpDevice">
|
||||
@foreach (var value in Enum.GetValues(typeof(HelpDevices)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.HelpDevice) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="HelpDeviceError" class="text-danger"></span>
|
||||
@ -29,7 +29,7 @@
|
||||
<select name="DriveType" id="DriveType" value="@Model.DriveType">
|
||||
@foreach (var value in Enum.GetValues(typeof(DriveTypes)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.DriveType) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="DriveTypeeError" class="text-danger"></span>
|
||||
|
@ -164,13 +164,13 @@ namespace CarCenterWorkerApp.Controllers
|
||||
for (int i = 0; i < bundlingIds.Length; i++)
|
||||
{
|
||||
var bundling = bundlings!.FirstOrDefault(x => x.Id == bundlingIds[i])!;
|
||||
model.PresaleBundlings.Add(i, bundling);
|
||||
model.PresaleBundlings.TryAdd(bundling.Id, bundling);
|
||||
}
|
||||
var requests = _data.GetRequests(UserWorker.user!.Id);
|
||||
for (int i = 0; i < requestIds.Length; i++)
|
||||
{
|
||||
var request = requests!.FirstOrDefault(x => x.Id == requestIds[i])!;
|
||||
model.Requests.Add(i, request);
|
||||
model.Requests.TryAdd(request.Id, request);
|
||||
}
|
||||
model.WorkerId = UserWorker.user!.Id;
|
||||
bool changed = false;
|
||||
@ -240,7 +240,7 @@ namespace CarCenterWorkerApp.Controllers
|
||||
model.OrderPresales.Add(i, presale);
|
||||
}
|
||||
model.WorkerId = UserWorker.user!.Id;
|
||||
if(double.TryParse(Sum, out double val))
|
||||
if(double.TryParse(Sum, System.Globalization.CultureInfo.InvariantCulture, out double val))
|
||||
{
|
||||
model.Sum = val;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<select name="PaymentType" id="PaymentType" value="@Model.PaymentType">
|
||||
@foreach (var value in Enum.GetValues(typeof(PaymentType)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.PaymentType) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="PaymentTypeError" class="text-danger"></span>
|
||||
@ -32,7 +32,7 @@
|
||||
<select name="PaymentStatus" id="PaymentStatus" value="@Model.PaymentStatus">
|
||||
@foreach (var value in Enum.GetValues(typeof(PaymentStatus)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.PaymentStatus) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="PaymentStatusError" class="text-danger"></span>
|
||||
|
@ -19,7 +19,7 @@
|
||||
<select name="PresaleStatus" id="PresaleStatus" value="@Model.PresaleStatus">
|
||||
@foreach (var value in Enum.GetValues(typeof(PresaleStatus)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.PresaleStatus) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="PresaleStatusError" class="text-danger"></span>
|
||||
|
@ -24,7 +24,7 @@
|
||||
<select name="RequestType" id="RequestType" value="@Model.RequestType">
|
||||
@foreach (var value in Enum.GetValues(typeof(RequestTypes)))
|
||||
{
|
||||
<option value="@value">@value</option>
|
||||
<option value="@value" selected="@(value.Equals(Model.RequestType) ? "selected" : null)">@value</option>
|
||||
}
|
||||
</select>
|
||||
<span id="RequestTypeError" class="text-danger"></span>
|
||||
|
Loading…
Reference in New Issue
Block a user