Add Gear controller/service/repo and relations in db between Jumps and others objects
This commit is contained in:
45
Back/skydiveLogs-api.Business/GearService.cs
Normal file
45
Back/skydiveLogs-api.Business/GearService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class GearService : IGearService
|
||||
{
|
||||
public GearService(IGearRepository gearRepository)
|
||||
{
|
||||
_gearRepository = gearRepository;
|
||||
}
|
||||
|
||||
public void AddNewGear(Gear Gear)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteGearById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
{
|
||||
return _gearRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
{
|
||||
return _gearRepository.GetAll();
|
||||
}
|
||||
|
||||
public void UpdateGear(int id, Gear Gear)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IGearRepository _gearRepository;
|
||||
}
|
||||
}
|
||||
18
Back/skydiveLogs-api.Business/Interface/IGearService.cs
Normal file
18
Back/skydiveLogs-api.Business/Interface/IGearService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IGearService
|
||||
{
|
||||
IEnumerable<Gear> GetAllGears();
|
||||
|
||||
Gear GetGearById(int id);
|
||||
|
||||
void DeleteGearById(int id);
|
||||
|
||||
void UpdateGear(int id, Gear Gear);
|
||||
|
||||
void AddNewGear(Gear Gear);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,11 @@ namespace skydiveLogs_api.Business.Interface
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
void AddNewJump(Jump jump);
|
||||
void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump);
|
||||
|
||||
void UpdateJump(int id, Jump jump);
|
||||
|
||||
|
||||
@@ -10,13 +10,35 @@ namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class JumpService : IJumpService
|
||||
{
|
||||
public JumpService(IJumpRepository jumpRepository)
|
||||
public JumpService(IJumpTypeService jumpTypeService,
|
||||
IAircraftService aircraftService,
|
||||
IDropZoneService dropZoneService,
|
||||
IGearService gearService,
|
||||
IJumpRepository jumpRepository)
|
||||
{
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_aircraftService = aircraftService;
|
||||
_dropZoneService = dropZoneService;
|
||||
_gearService = gearService;
|
||||
_jumpRepository = jumpRepository;
|
||||
}
|
||||
|
||||
public void AddNewJump(Jump jump)
|
||||
public void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump)
|
||||
{
|
||||
var selectedGear = _gearService.GetGearById(gearId);
|
||||
var selectedJumpType = _jumpTypeService.GetJumpTypeById(jumpTypeId);
|
||||
var selectedAircraft = _aircraftService.GetAircraftById(aircraftId);
|
||||
var selectedDropZone = _dropZoneService.GetDzById(dzId);
|
||||
|
||||
jump.Aircraft = selectedAircraft;
|
||||
jump.JumpType = selectedJumpType;
|
||||
jump.DropZone = selectedDropZone;
|
||||
jump.Gear = selectedGear;
|
||||
|
||||
_jumpRepository.AddJump(jump);
|
||||
}
|
||||
|
||||
@@ -41,5 +63,13 @@ namespace skydiveLogs_api.Business
|
||||
}
|
||||
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user