Extrated unit adjustment
This commit is contained in:
parent
7e1583f485
commit
fd11c89cea
@ -34,45 +34,8 @@ 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);
|
||||||
|
|
||||||
if (item.Unit == listItemDTO.Unit)
|
user.ShoppingList.Add(await UnitAdjustmentSameName(listItemDTO, item));
|
||||||
{
|
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -82,7 +45,7 @@ namespace API.BusinessLogic
|
|||||||
newItem.Unit = listItemDTO.Unit;
|
newItem.Unit = listItemDTO.Unit;
|
||||||
newItem.Checked = false;
|
newItem.Checked = false;
|
||||||
|
|
||||||
user.ShoppingList.Add(newItem);
|
user.ShoppingList.Add(await UnitAdjustment(newItem));
|
||||||
}
|
}
|
||||||
bool succes = await _dbAccess.AddItemToShoppingList(user);
|
bool succes = await _dbAccess.AddItemToShoppingList(user);
|
||||||
|
|
||||||
@ -163,45 +126,13 @@ 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);
|
||||||
|
|
||||||
if (item.Unit == ingredient.Unit)
|
ShoppingListItemDTO listItemDTO = new ShoppingListItemDTO();
|
||||||
{
|
listItemDTO.Name = ingredient.Name;
|
||||||
item.Amount += ingredient.Amount;
|
listItemDTO.Amount = ingredient.Amount;
|
||||||
}
|
listItemDTO.Unit = ingredient.Unit;
|
||||||
else if (item.Unit == "g" && ingredient.Unit == "kg")
|
listItemDTO.Checked = false;
|
||||||
{
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
item.Checked = false;
|
user.ShoppingList.Add(await UnitAdjustmentSameName(listItemDTO, item));
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -211,11 +142,58 @@ namespace API.BusinessLogic
|
|||||||
newItem.Unit = ingredient.Unit;
|
newItem.Unit = ingredient.Unit;
|
||||||
newItem.Checked = false;
|
newItem.Checked = false;
|
||||||
|
|
||||||
user.ShoppingList.Add(newItem);
|
user.ShoppingList.Add(await UnitAdjustment(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