1
0
mirror of https://github.com/chyzy/RSystem-MVC synced 2024-11-22 15:20:27 +01:00
RSystem-MVC-Fork/RSystem/Managers/RecrutationManager.cs
2018-04-17 11:20:49 +02:00

47 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
using Microsoft.Ajax.Utilities;
using RSystem.DAL;
using RSystem.Models;
using WebGrease.Css.Extensions;
namespace RSystem.Managers
{
public class RecrutationManager
{
public static void RecruitBySpecializations(IEnumerable<int>specializationsId)
{
var db = new ApplicationDbContext();
//get all recruits, that contains at
//least one of selected specialization
var recruits = db.Recruits
.Include(p=>p.RecruitPreferences)
.Include(m=>m.MaturaResults)
.Where(r => r.RecruitPreferences
.Any(s => specializationsId.Contains(s.SpecializationId)));
//new list with Recruits and specialization left
var recrutationList=new List<KeyValuePair<Recruit,int>>();
foreach (var recruit in recruits)
{
var filteredPreferences = recruit.RecruitPreferences
.Where(r => specializationsId.Contains(r.SpecializationId))
.OrderBy(p=>p.Priority);
recrutationList.Add(new KeyValuePair<Recruit, int>(recruit,filteredPreferences.Count()));
}
//Final list
var finalList=new List<Specialization>(
db.Specializations
.Where(id=>specializationsId.Contains(id.SpecializationId)));
}
}
}