Rework so employee dont use repos but servies
This commit is contained in:
@@ -69,10 +69,30 @@ namespace Database.Repository
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public void SetOrder(IReadOnlyList<int> orderedIds)
|
||||
{
|
||||
using PosDbContext context = new PosDbContext();
|
||||
List<ProductGroupEntity> productGroups = context.ProductGroups
|
||||
.Where(productGroup => orderedIds.Contains(productGroup.Id))
|
||||
.ToList();
|
||||
|
||||
if (productGroups.Count != orderedIds.Count)
|
||||
throw new InvalidOperationException(
|
||||
"En eller flere produktgrupper findes ikke.");
|
||||
|
||||
Dictionary<int, ProductGroupEntity> productGroupsById =
|
||||
productGroups.ToDictionary(productGroup => productGroup.Id);
|
||||
|
||||
for (int index = 0; index < orderedIds.Count; index++)
|
||||
productGroupsById[orderedIds[index]].Index = index;
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
using PosDbContext context = new PosDbContext();
|
||||
bool any = context.ProductGroups.Any();
|
||||
bool any = context.ProductGroups.Any(c => !c.IsArchived);
|
||||
return any;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Database.Models;
|
||||
|
||||
@@ -38,6 +39,33 @@ namespace Database.Repository
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public void SetOrder(
|
||||
int productGroupId,
|
||||
IReadOnlyList<int> orderedIds)
|
||||
{
|
||||
using PosDbContext context = new PosDbContext();
|
||||
List<ProductEntity> products = context.Products
|
||||
.Where(product => product.ProductGroupId == productGroupId)
|
||||
.Where(product => orderedIds.Contains(product.Id))
|
||||
.ToList();
|
||||
|
||||
if (products.Count != orderedIds.Count)
|
||||
throw new InvalidOperationException(
|
||||
"Et eller flere produkter findes ikke i produktgruppen.");
|
||||
|
||||
Dictionary<int, ProductEntity> productsById =
|
||||
products.ToDictionary(product => product.Id);
|
||||
|
||||
for (int index = 0; index < orderedIds.Count; index++)
|
||||
{
|
||||
ProductEntity product = productsById[orderedIds[index]];
|
||||
product.Index = index;
|
||||
product.IsModified = true;
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public ProductEntity GetById(int id)
|
||||
{
|
||||
using PosDbContext context = new PosDbContext();
|
||||
@@ -72,7 +100,11 @@ namespace Database.Repository
|
||||
product.ProductGroupId = productGroupId;
|
||||
using PosDbContext context = new PosDbContext();
|
||||
//Get the highest index
|
||||
ProductEntity highest = context.Products.OrderByDescending(c => c.Index).Take(1).FirstOrDefault();
|
||||
ProductEntity highest = context.Products
|
||||
.Where(c => c.ProductGroupId == productGroupId)
|
||||
.OrderByDescending(c => c.Index)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
if (highest == null)
|
||||
{
|
||||
highest = new ProductEntity();
|
||||
|
||||
Reference in New Issue
Block a user