Compare commits
No commits in common. "2a4b0c671d81d4ecc69cb2e481f2852db63be91c" and "df0c9511000506a66385d5dbb4a57b9c0b7ffc1d" have entirely different histories.
2a4b0c671d
...
df0c951100
@ -35,7 +35,44 @@ namespace API.BusinessLogic
|
|||||||
ShoppingListItem item = shoppingList.Where(s => s.Name == listItemDTO.Name).FirstOrDefault();
|
ShoppingListItem item = shoppingList.Where(s => s.Name == listItemDTO.Name).FirstOrDefault();
|
||||||
shoppingList.Remove(item);
|
shoppingList.Remove(item);
|
||||||
|
|
||||||
user.ShoppingList.Add(await UnitAdjustmentSameName(listItemDTO, item));
|
if (item.Unit == listItemDTO.Unit)
|
||||||
|
{
|
||||||
|
item.Amount += listItemDTO.Amount;
|
||||||
|
}
|
||||||
|
else if (item.Unit == "g" && listItemDTO.Unit == "kg")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 1000) + listItemDTO.Amount;
|
||||||
|
item.Unit = "kg";
|
||||||
|
}
|
||||||
|
else if (item.Unit == "ml" && listItemDTO.Unit == "l")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 1000) + listItemDTO.Amount;
|
||||||
|
item.Unit = "l";
|
||||||
|
}
|
||||||
|
else if (item.Unit == "dl" && listItemDTO.Unit == "l")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 10) + listItemDTO.Amount;
|
||||||
|
item.Unit = "l";
|
||||||
|
}
|
||||||
|
|
||||||
|
item.Checked = false;
|
||||||
|
|
||||||
|
if (item.Unit == "g" && item.Amount >= 1000)
|
||||||
|
{
|
||||||
|
item.Unit = "kg";
|
||||||
|
item.Amount = item.Amount / 1000;
|
||||||
|
}
|
||||||
|
else if (item.Unit == "ml" && item.Amount >= 1000)
|
||||||
|
{
|
||||||
|
item.Unit = "l";
|
||||||
|
item.Amount = item.Amount / 1000;
|
||||||
|
}
|
||||||
|
else if (item.Unit == "dl" && item.Amount >= 10)
|
||||||
|
{
|
||||||
|
item.Unit = "l";
|
||||||
|
item.Amount = item.Amount / 10;
|
||||||
|
}
|
||||||
|
user.ShoppingList.Add(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -45,7 +82,7 @@ namespace API.BusinessLogic
|
|||||||
newItem.Unit = listItemDTO.Unit;
|
newItem.Unit = listItemDTO.Unit;
|
||||||
newItem.Checked = false;
|
newItem.Checked = false;
|
||||||
|
|
||||||
user.ShoppingList.Add(await UnitAdjustment(newItem));
|
user.ShoppingList.Add(newItem);
|
||||||
}
|
}
|
||||||
bool succes = await _dbAccess.AddItemToShoppingList(user);
|
bool succes = await _dbAccess.AddItemToShoppingList(user);
|
||||||
|
|
||||||
@ -126,13 +163,45 @@ namespace API.BusinessLogic
|
|||||||
ShoppingListItem item = shoppingList.Where(s => s.Name == ingredient.Name).FirstOrDefault();
|
ShoppingListItem item = shoppingList.Where(s => s.Name == ingredient.Name).FirstOrDefault();
|
||||||
shoppingList.Remove(item);
|
shoppingList.Remove(item);
|
||||||
|
|
||||||
ShoppingListItemDTO listItemDTO = new ShoppingListItemDTO();
|
if (item.Unit == ingredient.Unit)
|
||||||
listItemDTO.Name = ingredient.Name;
|
{
|
||||||
listItemDTO.Amount = ingredient.Amount;
|
item.Amount += ingredient.Amount;
|
||||||
listItemDTO.Unit = ingredient.Unit;
|
}
|
||||||
listItemDTO.Checked = false;
|
else if (item.Unit == "g" && ingredient.Unit == "kg")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 1000) + ingredient.Amount;
|
||||||
|
item.Unit = "kg";
|
||||||
|
}
|
||||||
|
else if (item.Unit == "ml" && item.Unit == "l")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 1000) + ingredient.Amount;
|
||||||
|
item.Unit = "l";
|
||||||
|
}
|
||||||
|
else if (item.Unit == "dl" && item.Unit == "l")
|
||||||
|
{
|
||||||
|
item.Amount = (item.Amount / 10) + ingredient.Amount;
|
||||||
|
item.Unit = "l";
|
||||||
|
}
|
||||||
|
|
||||||
user.ShoppingList.Add(await UnitAdjustmentSameName(listItemDTO, item));
|
item.Checked = false;
|
||||||
|
|
||||||
|
if (item.Unit == "g" && item.Amount >= 1000)
|
||||||
|
{
|
||||||
|
item.Unit = "kg";
|
||||||
|
item.Amount = item.Amount / 1000;
|
||||||
|
}
|
||||||
|
else if (item.Unit == "ml" && item.Amount >= 1000)
|
||||||
|
{
|
||||||
|
item.Unit = "l";
|
||||||
|
item.Amount = item.Amount / 1000;
|
||||||
|
}
|
||||||
|
else if (item.Unit == "dl" && item.Amount >= 10)
|
||||||
|
{
|
||||||
|
item.Unit = "l";
|
||||||
|
item.Amount = item.Amount / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.ShoppingList.Add(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -142,58 +211,11 @@ namespace API.BusinessLogic
|
|||||||
newItem.Unit = ingredient.Unit;
|
newItem.Unit = ingredient.Unit;
|
||||||
newItem.Checked = false;
|
newItem.Checked = false;
|
||||||
|
|
||||||
user.ShoppingList.Add(await UnitAdjustment(newItem));
|
user.ShoppingList.Add(newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
return await _dbAccess.UpdateShoppingList(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ShoppingListItem> UnitAdjustmentSameName(ShoppingListItemDTO listItemDTO, ShoppingListItem listItem)
|
|
||||||
{
|
|
||||||
if (listItem.Unit == listItemDTO.Unit)
|
|
||||||
{
|
|
||||||
listItem.Amount += listItemDTO.Amount;
|
|
||||||
}
|
|
||||||
else if (listItem.Unit == "g" && listItemDTO.Unit == "kg")
|
|
||||||
{
|
|
||||||
listItem.Amount = (listItem.Amount / 1000) + listItemDTO.Amount;
|
|
||||||
listItem.Unit = "kg";
|
|
||||||
}
|
|
||||||
else if (listItem.Unit == "ml" && listItemDTO.Unit == "l")
|
|
||||||
{
|
|
||||||
listItem.Amount = (listItem.Amount / 1000) + listItemDTO.Amount;
|
|
||||||
listItem.Unit = "l";
|
|
||||||
}
|
|
||||||
else if (listItem.Unit == "dl" && listItemDTO.Unit == "l")
|
|
||||||
{
|
|
||||||
listItem.Amount = (listItem.Amount / 10) + listItemDTO.Amount;
|
|
||||||
listItem.Unit = "l";
|
|
||||||
}
|
|
||||||
|
|
||||||
listItem.Checked = false;
|
|
||||||
|
|
||||||
return await UnitAdjustment(listItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<ShoppingListItem> UnitAdjustment(ShoppingListItem listItem)
|
|
||||||
{
|
|
||||||
if (listItem.Unit == "g" && listItem.Amount >= 1000)
|
|
||||||
{
|
|
||||||
listItem.Unit = "kg";
|
|
||||||
listItem.Amount = listItem.Amount / 1000;
|
|
||||||
}
|
|
||||||
else if (listItem.Unit == "ml" && listItem.Amount >= 1000)
|
|
||||||
{
|
|
||||||
listItem.Unit = "l";
|
|
||||||
listItem.Amount = listItem.Amount / 1000;
|
|
||||||
}
|
|
||||||
else if (listItem.Unit == "dl" && listItem.Amount >= 10)
|
|
||||||
{
|
|
||||||
listItem.Unit = "l";
|
|
||||||
listItem.Amount = listItem.Amount / 10;
|
|
||||||
}
|
|
||||||
return listItem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user