3900-MyRecipes-backup / Server / Controllers / MealTypeController.cs
MealTypeController.cs
Raw
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using MyRecipes2.Server.Data;
using MyRecipes2.Server.Models;
using MyRecipes2.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MyRecipes2.Server.Controllers
{
    [ApiController]
    public class MealTypeController
    {
        private readonly ApplicationDbContext dbContext;

        public MealTypeController(ApplicationDbContext dbContext)
        {
            this.dbContext = dbContext;
        }

        [HttpGet]
        [Route("[controller]/AllMealTypes")]
        public List<MealTypeDto> GetAllMealTypes()
        {
            return dbContext.MealTypes.ToList().Select(x =>
            {
                MealTypeDto res = new();
                res.Id = x.Id;
                res.Name = x.Name;
                return res;
            }).ToList();
        }
    }
}