Update the repository and model to have the join between the models

This commit is contained in:
Sébastien André
2019-11-20 17:43:30 +01:00
parent 51f7fc2b7d
commit 29740709c6
7 changed files with 46 additions and 15 deletions

View File

@@ -19,7 +19,7 @@ namespace skydiveLogs_api.Business
{ {
var allJumps = _jumpRepository.GetAll(); var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.AircraftId, return allJumps.GroupBy(j => j.Aircraft.Id,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
@@ -33,7 +33,7 @@ namespace skydiveLogs_api.Business
{ {
var allJumps = _jumpRepository.GetAll(); var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.DropZoneId, return allJumps.GroupBy(j => j.DropZone.Id,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
@@ -47,7 +47,7 @@ namespace skydiveLogs_api.Business
{ {
var allJumps = _jumpRepository.GetAll(); var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.JumpTypeId, return allJumps.GroupBy(j => j.JumpType.Id,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {
@@ -61,7 +61,7 @@ namespace skydiveLogs_api.Business
{ {
var allJumps = _jumpRepository.GetAll(); var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.GearId, return allJumps.GroupBy(j => j.Gear.Id,
j => j, j => j,
(groupby, jumps) => new Statistic (groupby, jumps) => new Statistic
{ {

View File

@@ -10,6 +10,10 @@ namespace skydiveLogs_api.Data
public LiteDbProvider(string connectionString) public LiteDbProvider(string connectionString)
{ {
_db = new LiteDatabase(connectionString); _db = new LiteDatabase(connectionString);
BsonMapper.Global.Entity<Jump>().DbRef(x => x.JumpType, "JumpType");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Gear, "Gear");
} }
public LiteCollection<T> GetCollection<T>() public LiteCollection<T> GetCollection<T>()

View File

@@ -6,13 +6,21 @@ namespace skydiveLogs_api.Model
{ {
public int Id { get; set; } public int Id { get; set; }
public int JumpTypeId { get; set; } //public int JumpTypeId { get; set; }
public int AircraftId { get; set; } //public int AircraftId { get; set; }
public int DropZoneId { get; set; } //public int DropZoneId { get; set; }
public int GearId { get; set; } //public int GearId { get; set; }
public JumpType JumpType { get; set; }
public Aircraft Aircraft { get; set; }
public DropZone DropZone { get; set; }
public Gear Gear { get; set; }
public int ExitAltitude { get; set; } public int ExitAltitude { get; set; }

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace skydiveLogs_api.DataContract
{
public class GearReq
{
}
}

View File

@@ -0,0 +1,9 @@
namespace skydiveLogs_api.DataContract
{
public class GearResp
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -6,13 +6,13 @@ namespace skydiveLogs_api.DataContract
{ {
public int Id { get; set; } public int Id { get; set; }
public int JumpTypeId { get; set; } public JumpTypeResp JumpType { get; set; }
public int AircraftId { get; set; } public AircraftResp Aircraft { get; set; }
public int DropZoneId { get; set; } public DropZoneResp DropZone { get; set; }
public int GearId { get; set; } public GearResp Gear { get; set; }
public int ExitAltitude { get; set; } public int ExitAltitude { get; set; }

View File

@@ -1,7 +1,4 @@
using AutoMapper; using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
namespace skydiveLogs_api.Mapper namespace skydiveLogs_api.Mapper
{ {
@@ -13,7 +10,9 @@ namespace skydiveLogs_api.Mapper
CreateMap<DataContract.JumpTypeReq, Model.JumpType>(); CreateMap<DataContract.JumpTypeReq, Model.JumpType>();
CreateMap<DataContract.AircraftReq, Model.Aircraft>(); CreateMap<DataContract.AircraftReq, Model.Aircraft>();
CreateMap<DataContract.DropZoneReq, Model.DropZone>(); CreateMap<DataContract.DropZoneReq, Model.DropZone>();
CreateMap<DataContract.GearReq, Model.Gear>();
CreateMap<Model.Gear, DataContract.GearResp>();
CreateMap<Model.Jump, DataContract.JumpResp>(); CreateMap<Model.Jump, DataContract.JumpResp>();
CreateMap<Model.JumpType ,DataContract.JumpTypeResp>(); CreateMap<Model.JumpType ,DataContract.JumpTypeResp>();
CreateMap<Model.Aircraft ,DataContract.AircraftResp>(); CreateMap<Model.Aircraft ,DataContract.AircraftResp>();