using CD67.FicheCollege.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace CD67.FicheCollege.Factory
{
    public partial class RestaurationFormulairesRepaFactory : Internal.BaseFactory<Entity.RestaurationFormulairesRepa>
    {
        public override IQueryable<Entity.RestaurationFormulairesRepa> getAll()
        {
            return base.getAll();
        }

        public List<Entity.RestaurationFormulairesRepa> getByForm(Guid form_Id)
        {
            return dbContext.RestaurationFormulairesRepas.Where(x => x.RestaurationFormulaires_Id == form_Id).OrderBy(x => x.RestaurationTypesRepas_Id).ToList();
        }

        public int getSumTotal(Guid form_Id)
        {
            return dbContext.RestaurationFormulairesRepas.Where(x => x.RestaurationFormulaires_Id == form_Id).Sum(x => x.NbRepas).Value;
        }

        public int getMoyTotal(Guid form_Id)
        {
            ICollection<RestaurationFormulairesRepa> listeFormRepas = dbContext.RestaurationFormulairesRepas.Where(x => x.RestaurationFormulaires_Id == form_Id).ToList();
            int sum = 0;
            int count = listeFormRepas.Count();

            foreach (RestaurationFormulairesRepa repas in listeFormRepas)
            {
                sum = sum + (repas.NbRepas.Value / repas.NbJours.Value);
            }

            return sum;
        }

        public override void add(ref Entity.RestaurationFormulairesRepa form)
        {
            base.add(ref form);
        }

        public override void update(ref Entity.RestaurationFormulairesRepa form)
        {
            base.update(ref form);
        }
        public override void delete(ref Entity.RestaurationFormulairesRepa form)
        {
            base.delete(ref form);
        }
    }
}