99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
using skydiveLogs_api.Domain;
|
|
using skydiveLogs_api.DomainBusiness.Interfaces;
|
|
using skydiveLogs_api.DomainService.Repositories;
|
|
using System.Collections.Generic;
|
|
|
|
namespace skydiveLogs_api.DomainBusiness
|
|
{
|
|
public class JumpService : IJumpService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public JumpService(IJumpTypeService jumpTypeService,
|
|
IAircraftService aircraftService,
|
|
IDropZoneService dropZoneService,
|
|
IGearService gearService,
|
|
IJumpRepository jumpRepository,
|
|
IIdentityService identityService)
|
|
{
|
|
_jumpTypeService = jumpTypeService;
|
|
_aircraftService = aircraftService;
|
|
_dropZoneService = dropZoneService;
|
|
_gearService = gearService;
|
|
_jumpRepository = jumpRepository;
|
|
_identityService = identityService;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
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;
|
|
jump.User = _identityService.ConnectedUser;
|
|
|
|
_jumpRepository.Add(jump);
|
|
}
|
|
|
|
public void DeleteJumpById(int id)
|
|
{
|
|
_jumpRepository.DeleteById(id);
|
|
}
|
|
|
|
public IEnumerable<Jump> GetAllJumps()
|
|
{
|
|
return _jumpRepository.GetAll(_identityService.ConnectedUser);
|
|
}
|
|
|
|
public Jump GetJumpById(int id)
|
|
{
|
|
return _jumpRepository.GetById(id);
|
|
}
|
|
|
|
public int GetJumpCount()
|
|
{
|
|
return _jumpRepository.GetCount(_identityService.ConnectedUser);
|
|
}
|
|
|
|
public IEnumerable<Jump> GetJumpsByIndexes(int beginIndex, int endIndex)
|
|
{
|
|
return _jumpRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
|
|
}
|
|
|
|
public void UpdateJump(int id, Jump updatedJump)
|
|
{
|
|
var myJump = GetJumpById(id);
|
|
myJump.IsSpecial = updatedJump.IsSpecial;
|
|
myJump.WithCutaway = updatedJump.WithCutaway;
|
|
myJump.Notes = updatedJump.Notes;
|
|
|
|
_jumpRepository.Update(myJump);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IAircraftService _aircraftService;
|
|
private readonly IDropZoneService _dropZoneService;
|
|
private readonly IGearService _gearService;
|
|
private readonly IIdentityService _identityService;
|
|
private readonly IJumpRepository _jumpRepository;
|
|
private readonly IJumpTypeService _jumpTypeService;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |