Skip to content

Instantly share code, notes, and snippets.

@TheFo2sh
Created June 9, 2020 22:26
Show Gist options
  • Save TheFo2sh/bcfc070481f62110afc06a763e37f7b0 to your computer and use it in GitHub Desktop.
Save TheFo2sh/bcfc070481f62110afc06a763e37f7b0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TimeTable.Core.Models;
using TimeTableServer.Context;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace TimeTableServer.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TimeTableController : ControllerBase
{
public TimeTableController()
{
}
// GET: api/<TimeTableController>
[HttpGet]
public IEnumerable<TimeSlotDTO> Get()
{
using (var context=new DataContext())
{
var timeslots = context.TimeSlots
.Include(slot => slot.Course)
.ThenInclude(course=>course.Teacher)
.Include(slot => slot.Course)
.ThenInclude(course => course.Students)
.Include(slot => slot.Place).ToList();
return timeslots.Select(slot => new TimeSlotDTO()
{
Course = slot.Course.Title,
Place = slot.Place.Name,
Start = slot.Start.TotalMilliseconds,
End = slot.End.TotalMilliseconds,
Students=slot.Course.Students.Count,
Day = slot.Day
}).ToList();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment