Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions CRUDRecipeEF.BL/Services/RecipeCategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<string> AddRecipeToCategory(RecipeDTO recipeAddDTO, string cat
{
var category = await GetCategoryByNameIfExists(categoryName);
var recipe = await _context.Recipes
.FirstOrDefaultAsync(x => x.Name.ToLower() == recipeAddDTO.Name.ToLower().Trim());
.FirstOrDefaultAsync(x => x.Name == recipeAddDTO.Name.ToLower().Trim());

if (recipe == null)
{
Expand All @@ -75,7 +75,7 @@ private async Task Save()

private async Task<RecipeCategory> GetCategoryByNameIfExists(string name)
{
var category = await _context.RecipeCategories.FirstOrDefaultAsync(c => c.Name.ToLower() == name.ToLower().Trim());
var category = await _context.RecipeCategories.FirstOrDefaultAsync(c => c.Name == name.ToLower().Trim());
if (category == null)
{
throw new KeyNotFoundException("Category doesn't exist");
Expand All @@ -86,10 +86,8 @@ private async Task<RecipeCategory> GetCategoryByNameIfExists(string name)

private async Task<bool> CategoryExists(string categoryName)
{
bool exists = await _context.RecipeCategories.AnyAsync(c => c.Name.ToLower() == categoryName.ToLower().Trim());
bool exists = await _context.RecipeCategories.AnyAsync(c => c.Name == categoryName.ToLower().Trim());
return exists;
// Not using => makes this easier to debug. For some reason .ToLowerInvariant() does not work in the predicate.
// Possibly not compatiable with async? May look into this later.
}
}
}
2 changes: 1 addition & 1 deletion CRUDRecipeEF.DAL/Entities/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Recipe
public int Id { get; set; }

[Required]
public string Name { get => _name; set => _name = value.Trim(); }
public string Name { get => _name; set => _name = value.Trim().ToLower(); }

public List<Ingredient> Ingredients { get; set; } = new List<Ingredient>();

Expand Down
2 changes: 1 addition & 1 deletion CRUDRecipeEF.DAL/Entities/RecipeCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RecipeCategory
public int Id { get; set; }

[Required]
public string Name { get => _name; set => _name = value.Trim(); }
public string Name { get => _name; set => _name = value.Trim().ToLower(); }
public List<Recipe> Recipes { get; set; } = new List<Recipe>();
}
}
2 changes: 1 addition & 1 deletion CRUDRecipeEF.DAL/Entities/Restaurant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Restaurant

public int Id { get; set; }
[Required]
public string Name { get => _name; set => _name = value.Trim(); }
public string Name { get => _name; set => _name = value.Trim().ToLower(); }
public List<Menu> Menus { get; set; } = new List<Menu>();
}
}
4 changes: 2 additions & 2 deletions CRUDRecipeEF.DAL/Repositories/IngredientRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<IEnumerable<IngredientDTO>> GetAllIngredientsDTOsAsync()
}

public Task<Ingredient> GetIngredientByNameAsync(string name) =>
_context.Ingredients.SingleOrDefaultAsync(i => i.Name.ToLower() == name.ToLower().Trim());
_context.Ingredients.SingleOrDefaultAsync(i => i.Name == name.ToLower().Trim());

public Task<IngredientDTO> GetIngredientDTOByNameAsync(string name)
{
Expand All @@ -45,7 +45,7 @@ public Task<IngredientDTO> GetIngredientDTOByNameAsync(string name)
}

public Task<bool> IngredientExistsAsync(string name) =>
_context.Ingredients.AnyAsync(i => i.Name.ToLower() == name.ToLower().Trim());
_context.Ingredients.AnyAsync(i => i.Name == name.ToLower().Trim());

}
}
2 changes: 1 addition & 1 deletion CRUDRecipeEF.DAL/Repositories/RestaurantRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task<Restaurant> GetRestaurantByNameAsync(string name)
{
return _context.Restaurants
.Include(m => m.Menus)
.FirstOrDefaultAsync(r => r.Name.ToLower() == name.ToLower().Trim());
.FirstOrDefaultAsync(r => r.Name == name.ToLower().Trim());
}

public Task<bool> RestaurantExists(string name)
Expand Down