Add project files.
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class ValidationPointFakeRepository : IValidationPoint
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
private List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointFakeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
dto.Active = item.Active;
|
||||
dto.Description = item.Description;
|
||||
dto.Display = item.DisplayName;
|
||||
dto.Id = item.ValidationPointID;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
|
||||
model.Active = item.Active;
|
||||
model.Description = item.Description;
|
||||
model.DisplayName = item.Display;
|
||||
model.ValidationPointID = item.Id;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<ValidationPointDto>>> LoadValidationPointAsync(bool onlyActive)
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
var it = await _context.Validations.AsQueryable().ToListAsync();
|
||||
*/
|
||||
|
||||
ValidationPointDto dto;
|
||||
ValidationPoint val;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
val = new ValidationPoint()
|
||||
{
|
||||
ValidationPointID = i,
|
||||
Description = $"Validation {i}",
|
||||
DisplayName = $"Display {i}",
|
||||
Active = true,
|
||||
|
||||
|
||||
};
|
||||
|
||||
dto = FillValidationDto(val);
|
||||
_list.Add(dto);
|
||||
}
|
||||
//var it = await Task.Run(() => _list);
|
||||
|
||||
return new ResultModel<List<ValidationPointDto>>()
|
||||
{
|
||||
Data = _list,
|
||||
StatusCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<ResultModel<ValidationPointDto>> LoadValidationPointByIdAsync(int id)
|
||||
{
|
||||
ValidationPoint result = null;
|
||||
try
|
||||
{
|
||||
ValidationPointDto dto;
|
||||
result = await _context.Validations.FindAsync(id);
|
||||
dto = FillValidationDto(result);
|
||||
//result = _list.Find(x => x.Id == id);
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<ValidationPointDto>()
|
||||
{
|
||||
Data = dto,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveValidationPointAsync(ValidationPointDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
try
|
||||
{
|
||||
ValidationPoint model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(item.Id);
|
||||
model = FillValidationModel(item, model);
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ValidationPoint();
|
||||
model = FillValidationModel(item, model);
|
||||
_context.Validations.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = id;
|
||||
item.Id = id;
|
||||
}
|
||||
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
/*
|
||||
ConcessionTypeDA dataAccess = new ConcessionTypeDA();
|
||||
try
|
||||
{
|
||||
result = await dataAccess.InsertConcessionTypeAsync(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteValidationPointAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
ValidationPoint model;
|
||||
if (id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(id);
|
||||
model.Active = false;
|
||||
//_context.Validations.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user