Compare commits
No commits in common. "182ca1655cd87630b6e12c3b3869640dc0ef6743" and "6743e9c7aa096bf2857a8158f5596bf1a08c592a" have entirely different histories.
182ca1655c
...
6743e9c7aa
@ -6,11 +6,13 @@ namespace API.BusinessLogic
|
|||||||
{
|
{
|
||||||
public class RecipeLogic
|
public class RecipeLogic
|
||||||
{
|
{
|
||||||
private readonly RecipeDBAccess _dbAccess;
|
private readonly RecipeDBaccess _dbAccess;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public RecipeLogic(RecipeDBAccess dbAccess)
|
public RecipeLogic(IConfiguration configuration, RecipeDBaccess dbAccess)
|
||||||
{
|
{
|
||||||
_dbAccess = dbAccess;
|
_dbAccess = dbAccess;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> GetPrefereredRecipes(int userId)
|
public async Task<IActionResult> GetPrefereredRecipes(int userId)
|
||||||
@ -31,7 +33,7 @@ namespace API.BusinessLogic
|
|||||||
return new OkObjectResult(recipe);
|
return new OkObjectResult(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> CreateRecipe(RecipeDTO recipe, int prefereredRecipesId)
|
public async Task<IActionResult> CreateRecipe(Recipe recipe, int prefereredRecipesId)
|
||||||
{
|
{
|
||||||
var prefereredRecipes = await _dbAccess.ReadAllRecipe(prefereredRecipesId);
|
var prefereredRecipes = await _dbAccess.ReadAllRecipe(prefereredRecipesId);
|
||||||
|
|
||||||
@ -43,24 +45,10 @@ namespace API.BusinessLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe recipe1 = new Recipe();
|
return await _dbAccess.CreateRecipe(recipe, prefereredRecipesId);
|
||||||
recipe1.Name = recipe.Name;
|
|
||||||
recipe1.Directions = recipe.Directions;
|
|
||||||
recipe1.Description = recipe.Description;
|
|
||||||
recipe1.Ingredients = new List<Ingredient>();
|
|
||||||
foreach (var item in recipe.Ingredients)
|
|
||||||
{
|
|
||||||
Ingredient ingredient = new Ingredient();
|
|
||||||
ingredient.Unit = item.Unit;
|
|
||||||
ingredient.Element = item.Element;
|
|
||||||
ingredient.Amount = item.Amount;
|
|
||||||
recipe1.Ingredients.Add(ingredient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await _dbAccess.CreateRecipe(recipe1, prefereredRecipesId);
|
public async Task<IActionResult> EditRecipe(Recipe recipe, int recipeId, int userId)
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> EditRecipe(RecipeDTO recipe, int recipeId, int userId)
|
|
||||||
{
|
{
|
||||||
var prefereredRecipes = await _dbAccess.ReadPrefereredRecipes(userId);
|
var prefereredRecipes = await _dbAccess.ReadPrefereredRecipes(userId);
|
||||||
var dish = await _dbAccess.ReadRecipe(recipeId);
|
var dish = await _dbAccess.ReadRecipe(recipeId);
|
||||||
@ -76,14 +64,7 @@ namespace API.BusinessLogic
|
|||||||
dish.Name = recipe.Name;
|
dish.Name = recipe.Name;
|
||||||
dish.Description = recipe.Description;
|
dish.Description = recipe.Description;
|
||||||
dish.Directions = recipe.Directions;
|
dish.Directions = recipe.Directions;
|
||||||
foreach (var item in recipe.Ingredients)
|
dish.Ingredients = recipe.Ingredients;
|
||||||
{
|
|
||||||
Ingredient ingredient = new Ingredient();
|
|
||||||
ingredient.Unit = item.Unit;
|
|
||||||
ingredient.Element = item.Element;
|
|
||||||
ingredient.Amount = item.Amount;
|
|
||||||
dish.Ingredients.Add(ingredient);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await _dbAccess.UpdateRecipe(dish);
|
return await _dbAccess.UpdateRecipe(dish);
|
||||||
}
|
}
|
||||||
|
@ -1,209 +0,0 @@
|
|||||||
using API.DBAccess;
|
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace API.BusinessLogic
|
|
||||||
{
|
|
||||||
public class ShoppingListLogic
|
|
||||||
{
|
|
||||||
private readonly ShoppingListDBAccess _dbAccess;
|
|
||||||
private readonly RecipeDBAccess _recipeDBAccess;
|
|
||||||
|
|
||||||
public ShoppingListLogic(ShoppingListDBAccess dbAccess, RecipeDBAccess recipeDBAccess)
|
|
||||||
{
|
|
||||||
_dbAccess = dbAccess;
|
|
||||||
_recipeDBAccess = recipeDBAccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> ReadShoppingList(int userId)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
|
|
||||||
return new OkObjectResult(user.ShoppingList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> AddItemToShoppingList(ShoppingListItemDTO listItemDTO, int userId)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
|
|
||||||
List<ShoppingList> shoppingList = user.ShoppingList;
|
|
||||||
|
|
||||||
if (shoppingList.Any(s => s.Name == listItemDTO.Name))
|
|
||||||
{
|
|
||||||
ShoppingList item = shoppingList.Where(s => s.Name == listItemDTO.Name).FirstOrDefault();
|
|
||||||
shoppingList.Remove(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" && item.Unit == "l")
|
|
||||||
{
|
|
||||||
item.Amount = (item.Amount / 1000) + listItemDTO.Amount;
|
|
||||||
item.Unit = "l";
|
|
||||||
}
|
|
||||||
else if (item.Unit == "dl" && item.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
|
|
||||||
{
|
|
||||||
ShoppingList newItem = new ShoppingList();
|
|
||||||
newItem.Name = listItemDTO.Name;
|
|
||||||
newItem.Amount = listItemDTO.Amount;
|
|
||||||
newItem.Unit = listItemDTO.Unit;
|
|
||||||
newItem.Checked = false;
|
|
||||||
|
|
||||||
user.ShoppingList.Add(newItem);
|
|
||||||
}
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> CheckItemInShoppingList(int userId, int itemId)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
|
|
||||||
int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
|
|
||||||
|
|
||||||
user.ShoppingList[itemIndex].Checked = !user.ShoppingList[itemIndex].Checked;
|
|
||||||
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> UpdateItemInShoppingList(int userId, int itemId, ShoppingListItemDTO listItemDTO)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
|
|
||||||
int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
|
|
||||||
|
|
||||||
user.ShoppingList[itemIndex].Unit = listItemDTO.Unit;
|
|
||||||
user.ShoppingList[itemIndex].Name = listItemDTO.Name;
|
|
||||||
user.ShoppingList[itemIndex].Amount = listItemDTO.Amount;
|
|
||||||
|
|
||||||
if (user.ShoppingList[itemIndex].Unit == "g" && user.ShoppingList[itemIndex].Amount >= 1000)
|
|
||||||
{
|
|
||||||
user.ShoppingList[itemIndex].Unit = "kg";
|
|
||||||
user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 1000;
|
|
||||||
}
|
|
||||||
else if (user.ShoppingList[itemIndex].Unit == "ml" && user.ShoppingList[itemIndex].Amount >= 1000)
|
|
||||||
{
|
|
||||||
user.ShoppingList[itemIndex].Unit = "l";
|
|
||||||
user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 1000;
|
|
||||||
}
|
|
||||||
else if (user.ShoppingList[itemIndex].Unit == "dl" && user.ShoppingList[itemIndex].Amount >= 10)
|
|
||||||
{
|
|
||||||
user.ShoppingList[itemIndex].Unit = "l";
|
|
||||||
user.ShoppingList[itemIndex].Amount = user.ShoppingList[itemIndex].Amount / 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> DeleteItemInShoppingList(int userId, int itemId)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
|
|
||||||
int itemIndex = user.ShoppingList.FindIndex(x => x.Id == itemId);
|
|
||||||
|
|
||||||
user.ShoppingList.RemoveAt(itemIndex);
|
|
||||||
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> AddRecipeToShoppingList(int userId, int recipeId)
|
|
||||||
{
|
|
||||||
var user = await _dbAccess.ReadShoppingList(userId);
|
|
||||||
var recipe = await _recipeDBAccess.ReadRecipe(recipeId);
|
|
||||||
var ingredients = recipe.Ingredients;
|
|
||||||
|
|
||||||
foreach (var ingredient in ingredients)
|
|
||||||
{
|
|
||||||
List<ShoppingList> shoppingList = user.ShoppingList;
|
|
||||||
|
|
||||||
if (shoppingList.Any(s => s.Name == ingredient.Element))
|
|
||||||
{
|
|
||||||
ShoppingList item = shoppingList.Where(s => s.Name == ingredient.Element).FirstOrDefault();
|
|
||||||
shoppingList.Remove(item);
|
|
||||||
|
|
||||||
if (item.Unit == ingredient.Unit)
|
|
||||||
{
|
|
||||||
item.Amount += ingredient.Amount;
|
|
||||||
}
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
ShoppingList newItem = new ShoppingList();
|
|
||||||
newItem.Name = ingredient.Element;
|
|
||||||
newItem.Amount = ingredient.Amount;
|
|
||||||
newItem.Unit = ingredient.Unit;
|
|
||||||
newItem.Checked = false;
|
|
||||||
|
|
||||||
user.ShoppingList.Add(newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return await _dbAccess.UpdateShoppingList(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,6 @@ using System.Security.Claims;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
|
|
||||||
namespace API.BusinessLogic
|
namespace API.BusinessLogic
|
||||||
{
|
{
|
||||||
@ -71,7 +70,6 @@ namespace API.BusinessLogic
|
|||||||
Password = hashedPassword,
|
Password = hashedPassword,
|
||||||
Salt = salt,
|
Salt = salt,
|
||||||
PrefereredRecipes = recipes,
|
PrefereredRecipes = recipes,
|
||||||
ShoppingList = new List<ShoppingList>(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return await _dbAccess.CreateUser(user);
|
return await _dbAccess.CreateUser(user);
|
||||||
|
@ -36,14 +36,14 @@ namespace API.Controllers
|
|||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("create/{prefereredRecipesId}")]
|
[HttpPost("create/{prefereredRecipesId}")]
|
||||||
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe, int prefereredRecipesId)
|
public async Task<IActionResult> CreateRecipe([FromBody] Recipe recipe, int prefereredRecipesId)
|
||||||
{
|
{
|
||||||
return await _recipeLogic.CreateRecipe(recipe, prefereredRecipesId);
|
return await _recipeLogic.CreateRecipe(recipe, prefereredRecipesId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPut("edit/{recipeId}")]
|
[HttpPut("edit/{recipeId}")]
|
||||||
public async Task<IActionResult> EditRecipe([FromBody] RecipeDTO recipe, int recipeId)
|
public async Task<IActionResult> EditRecipe([FromBody] Recipe recipe, int recipeId)
|
||||||
{
|
{
|
||||||
var claims = HttpContext.User.Claims;
|
var claims = HttpContext.User.Claims;
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
|
|
||||||
using API.BusinessLogic;
|
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Security.Claims;
|
|
||||||
|
|
||||||
namespace API.Controllers
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class ShoppingListController : Controller
|
|
||||||
{
|
|
||||||
private readonly ShoppingListLogic _shoppingListLogic;
|
|
||||||
|
|
||||||
public ShoppingListController(ShoppingListLogic shoppingListLogic)
|
|
||||||
{
|
|
||||||
_shoppingListLogic = shoppingListLogic;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("get")]
|
|
||||||
public async Task<IActionResult> ReadShoppingList()
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.ReadShoppingList(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("add")]
|
|
||||||
public async Task<IActionResult> AddItem([FromBody] ShoppingListItemDTO listItemDTO)
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.AddItemToShoppingList(listItemDTO, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("check")]
|
|
||||||
public async Task<IActionResult> CheckItem(int itemId)
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.CheckItemInShoppingList(userId, itemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("update")]
|
|
||||||
public async Task<IActionResult> UpdateItem([FromBody] ShoppingListItemDTO listItemDTO, int itemId)
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.UpdateItemInShoppingList(userId, itemId, listItemDTO);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpDelete("delete")]
|
|
||||||
public async Task<IActionResult> DeleteItem(int itemId)
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.DeleteItemInShoppingList(userId, itemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("recipeadd")]
|
|
||||||
public async Task<IActionResult> AddARecipesItems(int recipeId)
|
|
||||||
{
|
|
||||||
var claims = HttpContext.User.Claims;
|
|
||||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
|
||||||
int userId = Convert.ToInt32(userIdString);
|
|
||||||
return await _shoppingListLogic.AddRecipeToShoppingList(userId, recipeId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using API.Models.RecipeModels;
|
using API.Models.RecipeModels;
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
using API.Models.UserModels;
|
using API.Models.UserModels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -13,8 +12,6 @@ namespace API.DBAccess
|
|||||||
|
|
||||||
public DbSet<Recipe> Recipes { get; set; }
|
public DbSet<Recipe> Recipes { get; set; }
|
||||||
|
|
||||||
public DbSet<ShoppingList> ShoppingList { get; set; }
|
|
||||||
|
|
||||||
public DBContext(DbContextOptions<DBContext> options) : base(options) { }
|
public DBContext(DbContextOptions<DBContext> options) : base(options) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace API.DBAccess
|
namespace API.DBAccess
|
||||||
{
|
{
|
||||||
public class RecipeDBAccess
|
public class RecipeDBaccess
|
||||||
{
|
{
|
||||||
private readonly DBContext _context;
|
private readonly DBContext _context;
|
||||||
|
|
||||||
public RecipeDBAccess(DBContext context)
|
public RecipeDBaccess(DBContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
using API.Models.RecipeModels;
|
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
using API.Models.UserModels;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.DBAccess
|
|
||||||
{
|
|
||||||
public class ShoppingListDBAccess
|
|
||||||
{
|
|
||||||
private readonly DBContext _context;
|
|
||||||
|
|
||||||
public ShoppingListDBAccess(DBContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
public async Task<User> ReadShoppingList(int userId)
|
|
||||||
{
|
|
||||||
var user = await _context.Users.Include(u => u.ShoppingList).FirstOrDefaultAsync(u => u.Id == userId);
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> UpdateShoppingList(User user)
|
|
||||||
{
|
|
||||||
_context.Entry(user).State = EntityState.Modified;
|
|
||||||
|
|
||||||
bool saved = await _context.SaveChangesAsync() >= 1;
|
|
||||||
|
|
||||||
if (saved) { return new OkObjectResult(user); }
|
|
||||||
|
|
||||||
return new ConflictObjectResult(new { message = "Could not save to database" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -49,7 +49,7 @@ namespace API.DBAccess
|
|||||||
{
|
{
|
||||||
_context.Users.Add(user);
|
_context.Users.Add(user);
|
||||||
|
|
||||||
bool saved = await _context.SaveChangesAsync() >= 1;
|
bool saved = await _context.SaveChangesAsync() == 1;
|
||||||
|
|
||||||
if (saved) { return new OkObjectResult(true); }
|
if (saved) { return new OkObjectResult(true); }
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
namespace API.Models.RecipeModels
|
|
||||||
{
|
|
||||||
public class IngredientDTO
|
|
||||||
{
|
|
||||||
public int Amount { get; set; }
|
|
||||||
|
|
||||||
public string Unit { get; set; }
|
|
||||||
|
|
||||||
public string Element { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace API.Models.RecipeModels
|
|
||||||
{
|
|
||||||
public class PrefereredRecipesDTO
|
|
||||||
{
|
|
||||||
public List<RecipeDTO> Recipes { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
namespace API.Models.RecipeModels
|
|
||||||
{
|
|
||||||
public class RecipeDTO
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
public string Directions { get; set; }
|
|
||||||
|
|
||||||
public List<IngredientDTO> Ingredients { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
namespace API.Models.ShoppingListModels
|
|
||||||
{
|
|
||||||
public class ShoppingList
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public double Amount { get; set; }
|
|
||||||
|
|
||||||
public string Unit { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public bool Checked { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
namespace API.Models.ShoppingListModels
|
|
||||||
{
|
|
||||||
public class ShoppingListItemDTO
|
|
||||||
{
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public double Amount { get; set; }
|
|
||||||
|
|
||||||
public string Unit { get; set; }
|
|
||||||
|
|
||||||
public bool Checked { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using API.Models.RecipeModels;
|
using API.Models.RecipeModels;
|
||||||
using API.Models.ShoppingListModels;
|
|
||||||
|
|
||||||
namespace API.Models.UserModels
|
namespace API.Models.UserModels
|
||||||
{
|
{
|
||||||
@ -20,7 +19,5 @@ namespace API.Models.UserModels
|
|||||||
public DateTime RefreshTokenExpireAt { get; set; }
|
public DateTime RefreshTokenExpireAt { get; set; }
|
||||||
|
|
||||||
public PrefereredRecipes PrefereredRecipes { get; set; }
|
public PrefereredRecipes PrefereredRecipes { get; set; }
|
||||||
|
|
||||||
public List<ShoppingList> ShoppingList { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace API
|
|||||||
|
|
||||||
services.AddScoped<UserDBAccess>();
|
services.AddScoped<UserDBAccess>();
|
||||||
services.AddScoped<UserLogic>();
|
services.AddScoped<UserLogic>();
|
||||||
services.AddScoped<RecipeDBAccess>();
|
services.AddScoped<RecipeDBaccess>();
|
||||||
services.AddScoped<RecipeLogic>();
|
services.AddScoped<RecipeLogic>();
|
||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
Loading…
Reference in New Issue
Block a user