-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from davewalker5/FR-31-Sightings-Export
FR-31 Sightings Export
- Loading branch information
Showing
24 changed files
with
1,240 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/FlightRecorder.BusinessLogic/Logic/JobStatusManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using FlightRecorder.BusinessLogic.Extensions; | ||
using FlightRecorder.Data; | ||
using FlightRecorder.Entities.Db; | ||
using FlightRecorder.Entities.Interfaces; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace FlightRecorder.BusinessLogic.Logic | ||
{ | ||
internal class JobStatusManager : IJobStatusManager | ||
{ | ||
private readonly FlightRecorderDbContext _context; | ||
|
||
internal JobStatusManager(FlightRecorderDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Get the first job status matching the specified criteria | ||
/// </summary> | ||
/// <param name="predicate"></param> | ||
/// <returns></returns> | ||
public async Task<JobStatus> GetAsync(Expression<Func<JobStatus, bool>> predicate) | ||
{ | ||
List<JobStatus> statuses = await ListAsync(predicate, 1, 1).ToListAsync(); | ||
return statuses.FirstOrDefault(); | ||
} | ||
|
||
/// <summary> | ||
/// Return all entities matching the specified criteria | ||
/// </summary> | ||
/// <param name="predicate"></param> | ||
/// <param name="pageNumber"></param> | ||
/// <param name="pageSize"></param> | ||
/// <returns></returns> | ||
public IAsyncEnumerable<JobStatus> ListAsync(Expression<Func<JobStatus, bool>> predicate, int pageNumber, int pageSize) | ||
{ | ||
IAsyncEnumerable<JobStatus> results; | ||
if (predicate == null) | ||
{ | ||
results = _context.JobStatuses | ||
.Skip((pageNumber - 1) * pageSize) | ||
.Take(pageSize) | ||
.AsAsyncEnumerable(); | ||
} | ||
else | ||
{ | ||
results = _context.JobStatuses.Where(predicate).AsAsyncEnumerable(); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
/// <summary> | ||
/// Create a new job status | ||
/// </summary> | ||
/// <param name="name"></param> | ||
/// <returns></returns> | ||
public async Task<JobStatus> AddAsync(string name, string parameters) | ||
{ | ||
JobStatus status = new JobStatus | ||
{ | ||
Name = name.CleanString(), | ||
Parameters = parameters.CleanString(), | ||
Start = DateTime.Now | ||
}; | ||
|
||
await _context.JobStatuses.AddAsync(status); | ||
await _context.SaveChangesAsync(); | ||
|
||
return status; | ||
} | ||
|
||
/// <summary> | ||
/// Update a job status, setting the end timestamp and error result | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <param name="error"></param> | ||
/// <returns></returns> | ||
public async Task<JobStatus> UpdateAsync(long id, string error) | ||
{ | ||
JobStatus status = await GetAsync(x => x.Id == id); | ||
if (status != null) | ||
{ | ||
status.End = DateTime.Now; | ||
status.Error = error.CleanString(); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
return status; | ||
} | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
src/FlightRecorder.BusinessLogic/Sql/ManufacturerStatistis.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.