2019-03-06 19:17:36 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using api.Models;
|
|
|
|
using api.Data;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using System.Collections.Generic;
|
2019-04-05 22:57:50 +01:00
|
|
|
using System.Linq;
|
2019-03-06 19:17:36 +00:00
|
|
|
|
|
|
|
namespace api.Data
|
|
|
|
{
|
|
|
|
public class EventLocsVisitedRepository : IEventLocsVisitedRepository
|
|
|
|
{
|
|
|
|
public EventLocsVisitedRepository(DataContext context)
|
|
|
|
{
|
|
|
|
_context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataContext _context { get; }
|
|
|
|
|
|
|
|
public async Task<IEnumerable<EventLocVisited>> GetEventLocsVisited()
|
|
|
|
{
|
2019-03-18 18:49:03 +00:00
|
|
|
var rEventLocsVisitedList = await _context.EventLocsVisited.Include(e => e.Team).Include(e => e.Location).ToListAsync();
|
|
|
|
|
2019-03-06 19:17:36 +00:00
|
|
|
return rEventLocsVisitedList;
|
|
|
|
}
|
|
|
|
|
2019-03-09 18:10:26 +00:00
|
|
|
public async Task<List<EventLocVisited>> GetEventLocsVisitedTeam(int id)
|
2019-03-06 19:17:36 +00:00
|
|
|
{
|
2019-04-05 22:57:50 +01:00
|
|
|
Team t= await _context.Teams.FirstOrDefaultAsync(team=>team.Id== id);
|
2019-03-18 18:49:03 +00:00
|
|
|
|
2019-04-05 22:57:50 +01:00
|
|
|
List<EventLoc> allPlaces = await _context.EventLocs.Where(a=>a.EventId== t.EventId ).ToListAsync();
|
|
|
|
|
2019-04-12 15:34:25 +01:00
|
|
|
List<EventLocVisited> allLocs = await _context.EventLocsVisited.Where(T=>T.Team.Id== id).Include(e => e.Team).Include(e => e.Location).ToListAsync();
|
2019-03-18 17:55:02 +00:00
|
|
|
|
2019-03-06 19:17:36 +00:00
|
|
|
List<EventLocVisited> rList = new List<EventLocVisited>();
|
2019-03-18 18:49:03 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < allPlaces.Count; j++)
|
|
|
|
{
|
|
|
|
|
2019-04-11 18:54:39 +01:00
|
|
|
|
2019-03-18 18:49:03 +00:00
|
|
|
EventLocVisited novo=new EventLocVisited();
|
|
|
|
|
|
|
|
novo.Location= allPlaces[j];
|
|
|
|
|
|
|
|
novo.complete=false;
|
|
|
|
|
|
|
|
for (var i = 0; i < allLocs.Count; i++)
|
|
|
|
{
|
2019-04-11 18:54:39 +01:00
|
|
|
if(allPlaces[j].Id == allLocs[i].Location.Id){
|
2019-03-18 18:49:03 +00:00
|
|
|
novo.complete=true;
|
|
|
|
}
|
2019-03-06 19:17:36 +00:00
|
|
|
}
|
2019-03-18 17:55:02 +00:00
|
|
|
|
2019-03-18 18:49:03 +00:00
|
|
|
|
|
|
|
rList.Add(novo);
|
2019-03-06 19:17:36 +00:00
|
|
|
}
|
2019-03-18 18:49:03 +00:00
|
|
|
|
2019-03-09 18:10:26 +00:00
|
|
|
return rList;
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:49:03 +00:00
|
|
|
public async Task<List<EventLocVisited>> GetEventLocsVisitedEvent(int id)
|
2019-03-09 18:10:26 +00:00
|
|
|
{
|
2019-03-18 18:49:03 +00:00
|
|
|
List<EventLocVisited> allLocs = await _context.EventLocsVisited.Include(e => e.Team).Include(e => e.Location).ToListAsync();
|
2019-03-09 18:10:26 +00:00
|
|
|
List<EventLocVisited> rList = new List<EventLocVisited>();
|
2019-03-18 18:49:03 +00:00
|
|
|
for (var i = 0; i < allLocs.Count; i++)
|
|
|
|
{
|
|
|
|
if (allLocs[i].Location.EventId == id)
|
|
|
|
{
|
2019-03-09 18:10:26 +00:00
|
|
|
rList.Add(allLocs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rList;
|
2019-03-06 19:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|