Recipe.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. namespace Recepie.Models
  4. {
  5. public class Recipe
  6. {
  7. [Key]
  8. public int Id { get; set; }
  9. [Required]
  10. [StringLength(200)]
  11. public string Title { get; set; } = string.Empty;
  12. [StringLength(1000)]
  13. public string? Description { get; set; }
  14. [StringLength(50)]
  15. public string? Difficulty { get; set; }
  16. // Properties that exist in your database - made nullable to handle NULL values
  17. public string? Url { get; set; }
  18. public string? Time { get; set; }
  19. // Navigation properties for ingredients, steps, and images
  20. public virtual ICollection<RecipeIngredientLink> RecipeIngredients { get; set; } = new List<RecipeIngredientLink>();
  21. public virtual ICollection<RecipeStep> RecipeSteps { get; set; } = new List<RecipeStep>();
  22. // public virtual RecipeImage? RecipeImage { get; set; } // Temporarily disabled for main page performance
  23. // Computed property to get ingredient names
  24. [NotMapped]
  25. public List<string> IngredientNames => RecipeIngredients?.Select(ri => ri.Ingredient?.Name ?? "").Where(name => !string.IsNullOrEmpty(name)).ToList() ?? new List<string>();
  26. }
  27. }