Compare commits

..

No commits in common. "050ff896e16e927a27984ef7c93044b06e9cd7c0" and "e30110bcff0d6f4db86b2fada9bba13ac796c476" have entirely different histories.

3 changed files with 1 additions and 20 deletions

View File

@ -14,7 +14,6 @@ namespace API.DBAccess
_context = context;
}
// Reads the users recipes
public async Task<List<Recipe>> ReadRecipes(int userId)
{
var recipes = await _context.Users.Include(p => p.Recipes).FirstOrDefaultAsync(u => u.Id == userId);
@ -22,13 +21,11 @@ namespace API.DBAccess
return recipes.Recipes;
}
// Returns a specifik recipe
public async Task<Recipe> ReadRecipe(int recipeId)
{
return await _context.Recipes.Include(r => r.Ingredients).Include(r => r.Directions).FirstOrDefaultAsync(r => r.Id == recipeId);
}
// Adds a new recipe to the database
public async Task<IActionResult> CreateRecipe(Recipe recipe, int userId)
{
var recipes = await _context.Users.Include(p => p.Recipes).FirstOrDefaultAsync(u => u.Id == userId);
@ -42,7 +39,6 @@ namespace API.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Updates the recipe in the database
public async Task<IActionResult> UpdateRecipe(Recipe recipe)
{
_context.Entry(recipe).State = EntityState.Modified;
@ -54,7 +50,6 @@ namespace API.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Deletes the recipe from the database
public async Task<IActionResult> DeleteRecipe(Recipe recipe)
{
_context.Recipes.Remove(recipe);

View File

@ -14,8 +14,6 @@ namespace API.DBAccess
{
_context = context;
}
// Read the shoppinglist connected to the user
public async Task<User> ReadShoppingList(int userId)
{
var user = await _context.Users.Include(u => u.ShoppingList).FirstOrDefaultAsync(u => u.Id == userId);
@ -23,7 +21,6 @@ namespace API.DBAccess
return user;
}
// Updates the shoppinglist
public async Task<IActionResult> UpdateShoppingList(User user)
{
_context.Entry(user).State = EntityState.Modified;

View File

@ -13,19 +13,16 @@ namespace API.DBAccess
_context = context;
}
// Reads the user from the database
public async Task<User> ReadUser(int userId)
{
return await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
}
// Reads all the users from the database
public async Task<List<User>> ReadAllUsers()
{
return await _context.Users.ToListAsync();
}
// Searches for a user with the username
public async Task<bool> UserNameInUse(string username)
{
var user = await _context.Users.FirstOrDefaultAsync(u => u.UserName == username);
@ -33,7 +30,6 @@ namespace API.DBAccess
return true;
}
// Searches for a user with the email
public async Task<bool> EmailInUse(string email)
{
var user = await _context.Users.FirstOrDefaultAsync(u => u.UserName == email);
@ -41,19 +37,16 @@ namespace API.DBAccess
return true;
}
// Searches for a user with refreshtoken and returns that user
public async Task<User> ReadUserByRefreshToken(string refreshToken)
{
return await _context.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken);
}
// Gets all the data for a user
public async Task<User> ReadUserForDelete(int userId)
{
return await _context.Users.Include(u => u.Recipes).ThenInclude(r => r.Ingredients).Include(u => u.Recipes).ThenInclude(r => r.Directions).Include(u => u.ShoppingList).FirstOrDefaultAsync(u => u.Id == userId);
return await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
}
// Gets a user according to either the email or username
public async Task<User> ReadUserForLogin(string emailOrUsername)
{
if (emailOrUsername.Contains("@"))
@ -66,7 +59,6 @@ namespace API.DBAccess
}
}
// Adds a new user to the database
public async Task<IActionResult> CreateUser(User user)
{
_context.Users.Add(user);
@ -79,7 +71,6 @@ namespace API.DBAccess
}
// Updates the user in the database
public async Task<IActionResult> UpdateUser(User user)
{
_context.Entry(user).State = EntityState.Modified;
@ -91,7 +82,6 @@ namespace API.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Updates the password in the database
public async Task<IActionResult> UpdatePassword(User user)
{
_context.Entry(user).State = EntityState.Modified;
@ -103,7 +93,6 @@ namespace API.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Deletes the user from the database
public async Task<IActionResult> DeleteUser(User user)
{
_context.Users.Remove(user);