public IHttpActionResult GetDietByNeeds(DietFind model)
 {
     if (model is null)
     {
         return(BadRequest("Your request body cannot be empty. "));
     }
     if (ModelState.IsValid)
     {
         return(Ok(dietService.GetDietByUserNeeds(model)));
     }
     return(BadRequest(ModelState));
 }
Ejemplo n.º 2
0
 public List <DietListItem> GetDietByUserNeeds(DietFind needs)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var query =
             ctx
             .Diets
             .Where(
                 e => e.IsVegetarian == needs.IsVegetarian &&
                 e.IsKeto == needs.IsKeto &&
                 e.IsLactoseFree == needs.IsLactoseFree &&
                 e.IsGlutenFree == needs.IsGlutenFree
                 )
             .Select(e =>
                     new DietListItem
         {
             DietId      = e.DietId,
             Name        = e.Name,
             Description = e.Description
         }
                     );
         return(query.ToList());
     }
 }