Skip to content

Instantly share code, notes, and snippets.

@kleberksms
Created February 6, 2019 01:26
Show Gist options
  • Save kleberksms/9f07f0ddd6adbe20c4b3c668687aed57 to your computer and use it in GitHub Desktop.
Save kleberksms/9f07f0ddd6adbe20c4b3c668687aed57 to your computer and use it in GitHub Desktop.
using System.Linq;
using AvaliacoesEmpresas.Domain.Interfaces;
using AvaliacoesEmpresas.Domain.Models;
using AvaliacoesEmpresas.Infra.Data.Context;
using Microsoft.EntityFrameworkCore;
namespace AvaliacoesEmpresas.Infra.Data.Repository
{
public class EvaluationRepository : Repository<Evaluation>, IEvaluationRepository
{
public EvaluationRepository(DeafultContext context)
: base(context)
{
}
public Evaluation GetEvaluationByCompany(string client, string company)
{
return DbSet.AsNoTracking().FirstOrDefault(c => c.Fk_Company == company && c.Client == client);
}
//EvaluationListViewModel
public EvaluationListViewModel GetEvaluationListByCompany(string client, string company)
{
var result = DbSet.AsQueryable()
.Where(c => c.Fk_Company == company && c.Client == client)
.GroupBy(i => i.Fk_Company)
.Select(g => new EvaluationListViewModel
{
AVG_General_ev = g.Average(i => i.General_ev),
AVG_Culture = g.Average(i => i.General_ev),
AVG_Management = g.Average(i => i.General_ev),
AVG_Opportunity = g.Average(i => i.General_ev),
AVG_Life_Quality = g.Average(i => i.General_ev),
AVG_Remuneration = g.Average(i => i.General_ev)
});
return new EvaluationListViewModel();
}
public Evaluation GetEvaluationByUser(string client, int user)
{
return DbSet.AsNoTracking().FirstOrDefault(c => c.Client == client && c.User == user);
}
public void SetEvaluation(Evaluation evaluation)
{
DbSet.Add(evaluation);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment