4using Microsoft.EntityFrameworkCore;
29 .Include(pl => pl.PriceElements)
30 .Include(pl => pl.Currency)
57 throw new InvalidOperationException($
"Prisliste med navn {priceList.PriceListName} finnes allerede.");
61 throw new InvalidOperationException(
"Sluttdato må være etter startdato.");
67 await
_db.SaveChangesAsync();
68 var savedPriceList = res.Entity;
70 var copy = await
_db.
PriceLists.Include(pl => pl.PriceElements).Where(pl => pl.PriceListSeq == priceListToCopy).ToListAsync();
73 throw new InvalidOperationException(
"Prisliste for utgangspunkt finnes ikke i databasen.");
76 var copiedPriceElements =
new List<PriceElement>();
77 copy.First().PriceElements.ForEach(pe =>
82 Price = pe.Price * priceAdjustmentFactor,
83 IsActive = pe.IsActive,
84 PriceListSeq = savedPriceList.PriceListSeq
86 copiedPriceElements.Add(priceElementCopy);
89 savedPriceList.PriceElements = copiedPriceElements;
90 await
_db.SaveChangesAsync();
106 throw new InvalidOperationException($
"Prisliste med navn {priceList.PriceListName} finnes allerede.");
110 throw new InvalidOperationException(
"Sluttdato må være etter startdato.");
116 await
_db.SaveChangesAsync();
130 throw new InvalidOperationException($
"Prisliste med navn {priceList.PriceListName} finnes allerede.");
134 throw new InvalidOperationException(
"Sluttdato må være etter startdato.");
139 _db.Entry(priceList).State = EntityState.Modified;
140 await
_db.SaveChangesAsync();
141 _db.ChangeTracker.Clear();
DbSet< Currency > Currencies
DbSet< PriceList > PriceLists
virtual Currency Currency
PriceListService class inserts and updates PriceList in the Database
async Task< PriceList > AddPriceList(PriceList priceList)
Adds a PriceList to the database
async Task< PriceList > GetPriceListById(int id)
Read one PriceList with id from database
PriceListService(DataContext db)
async Task< List< PriceList > > GetAllPriceLists()
Read all PriceLists from database
async Task< PriceList > UpdatePriceList(PriceList priceList)
Updates changes on a PriceList in the database
async Task< PriceList > AddPriceListFromCopy(PriceList priceList, int priceListToCopy, decimal priceAdjustmentFactor)
Adds a PriceList to the database. Copies the PriceElements from priceListToCopy and multiply prices w...
static bool DateFromIsBeforeDateTo(DateTime dateFrom, DateTime dateTo)
Compares dateFrom and dateTo