Skip to content

Commit

Permalink
Small fixes to decrease unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Guldborg committed Nov 27, 2023
1 parent 04b4419 commit 071d3fa
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions coffeecard/CoffeeCard.Library/Services/v2/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ public async Task<ChangedProductResponse> AddProduct(AddProductRequest newProduc
Name = newProduct.Name,
NumberOfTickets = newProduct.NumberOfTickets,
ExperienceWorth = 0,
Visible = newProduct.Visible
Visible = newProduct.Visible,
ProductUserGroup = newProduct.AllowedUserGroups.Select(userGroup => new ProductUserGroup
{
UserGroup = userGroup
}).ToList()
};

product.ProductUserGroup = newProduct.AllowedUserGroups.Select(userGroup => new ProductUserGroup
{
ProductId = product.Id,
UserGroup = userGroup
}).ToList();

_context.Products.Add(product);
await _context.SaveChangesAsync();

Expand All @@ -105,19 +103,17 @@ public async Task<ChangedProductResponse> AddProduct(AddProductRequest newProduc

public async Task<ChangedProductResponse> UpdateProduct(UpdateProductRequest changedProduct)
{
var newProductUserGroups = changedProduct.AllowedUserGroups.Select(userGroup => new ProductUserGroup
{
ProductId = changedProduct.Id,
UserGroup = userGroup
}).ToList();

var product = await GetProductAsync(changedProduct.Id);
product.Price = changedProduct.Price;
product.Description = changedProduct.Description;
product.NumberOfTickets = changedProduct.NumberOfTickets;
product.Name = changedProduct.Name;
product.Visible = changedProduct.Visible;
product.ProductUserGroup = newProductUserGroups;
product.ProductUserGroup = changedProduct.AllowedUserGroups.Select(userGroup => new ProductUserGroup
{
ProductId = changedProduct.Id,
UserGroup = userGroup
}).ToList();

await _context.SaveChangesAsync();

Expand Down

0 comments on commit 071d3fa

Please sign in to comment.