273 lines
7.0 KiB
C#
273 lines
7.0 KiB
C#
//using BCryptNet = BCrypt.Net.BCrypt;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Options;
|
|
using CarParkValidationAPI.Authorization;
|
|
using CarParkValidationAPI.Entities;
|
|
using CarParkValidationAPI.Helpers;
|
|
using CarParkValidationAPI.Models.Users;
|
|
using CarParkValidationAPI.Models;
|
|
using CarParkValidationAPI.Datas;
|
|
using CarParkValidationAPI.Interface;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
|
|
namespace CarParkValidationAPI.Repository
|
|
{
|
|
public class ConcessionValidationRepository : IConcessionValidation
|
|
{
|
|
private DataContext _context;
|
|
|
|
private readonly AppSettings _appSettings;
|
|
|
|
public ConcessionValidationRepository(
|
|
DataContext context,
|
|
|
|
IOptions<AppSettings> appSettings)
|
|
{
|
|
_context = context;
|
|
_appSettings = appSettings.Value;
|
|
}
|
|
|
|
private ConcessionValidationDto FillConcessionValidationDto(ConcessionValidation model)
|
|
{
|
|
ConcessionValidationDto dto = new ConcessionValidationDto();
|
|
dto.Active = model.Active;
|
|
dto.ConcessionCard = model.ConcessionCard;
|
|
dto.ConcessionExpiry = model.ConcessionExpiry;
|
|
dto.ConcessionHolder = model.ConcessionHolder;
|
|
dto.ConcessionTypeId = model.ConcessionTypeID;
|
|
dto.Id = model.ValidationID;
|
|
dto.StafflinkNo = model.StafflinkNo;
|
|
dto.ValidateDate = model.ValidateDate;
|
|
dto.ValidationPointId = model.ValidationPointID;
|
|
return dto;
|
|
}
|
|
|
|
private ConcessionValidationExtDto FillConcessionValidationExtDto(ConcessionValidation model)
|
|
{
|
|
ConcessionValidationExtDto dto = new ConcessionValidationExtDto();
|
|
dto.Active = model.Active;
|
|
dto.ConcessionCard = model.ConcessionCard;
|
|
dto.ConcessionExpiry = model.ConcessionExpiry;
|
|
dto.ConcessionHolder = model.ConcessionHolder;
|
|
dto.ConcessionTypeId = model.ConcessionTypeID;
|
|
dto.Id = model.ValidationID;
|
|
dto.StafflinkNo = model.StafflinkNo;
|
|
dto.ValidateDate = model.ValidateDate;
|
|
dto.ValidationPointId = model.ValidationPointID;
|
|
return dto;
|
|
}
|
|
|
|
private ConcessionValidation FillConcessionValidation(ConcessionValidationDto dto, ConcessionValidation model)
|
|
{
|
|
|
|
model.Active = dto.Active;
|
|
model.ConcessionCard = dto.ConcessionCard;
|
|
model.ConcessionExpiry = dto.ConcessionExpiry;
|
|
model.ConcessionHolder = dto.ConcessionHolder;
|
|
model.ConcessionTypeID = dto.ConcessionTypeId;
|
|
model.ValidationID = dto.Id;
|
|
model.StafflinkNo = dto.StafflinkNo;
|
|
model.ValidateDate = dto.ValidateDate;
|
|
model.ValidationPointID = dto.ValidationPointId;
|
|
return model;
|
|
}
|
|
public async Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationAsync(bool onlyActive)
|
|
{
|
|
int statuscode = 0;
|
|
string error = "";
|
|
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
|
|
|
ConcessionValidationExtDto dto;
|
|
ConcessionValidation model;
|
|
try
|
|
{
|
|
List<ConcessionValidation> clist = await _context.ConcessionValidations.Where(x => x.Active == true).ToListAsync();
|
|
for (int i = 0; i < clist.Count; i++)
|
|
{
|
|
model = clist[i];
|
|
dto = FillConcessionValidationExtDto(model);
|
|
result.Add(dto);
|
|
}
|
|
statuscode = 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statuscode = 0;
|
|
error = ex.ToString();
|
|
throw;
|
|
}
|
|
|
|
return new ResultModel<List<ConcessionValidationExtDto>>()
|
|
{
|
|
Data = result,
|
|
StatusCode = statuscode,
|
|
Message = error
|
|
};
|
|
}
|
|
|
|
public async Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationStaffLinkNoAsync(string staffLinkNo, DateTime currentDate)
|
|
{
|
|
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
|
// ConcessionValidationExtDto dto;
|
|
// ConcessionValidation model;
|
|
int statuscode = 0;
|
|
string error = "";
|
|
try
|
|
{
|
|
|
|
//List<ConcessionValidation> clist = await _context.ConcessionValidations.Where(x =>
|
|
// x.Active == true
|
|
// && x.StafflinkNo == staffLinkNo
|
|
// && x.ValidateDate.Date == currentDate.Date
|
|
//).ToListAsync();
|
|
result = await _context.SelectConcessionValidationByStaffId(true, staffLinkNo, currentDate, currentDate);
|
|
/*
|
|
//var clist = await _context.SPSelectValidation(true, staffLinkNo, currentDate);
|
|
for (int i = 0; i < clist.Count; i++)
|
|
{
|
|
model = clist[i];
|
|
dto = FillConcessionValidationExtDto(model);
|
|
result.Add(dto);
|
|
|
|
}
|
|
*/
|
|
statuscode = 1;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statuscode = 0;
|
|
error = ex.ToString();
|
|
throw;
|
|
}
|
|
|
|
return new ResultModel<List<ConcessionValidationExtDto>>()
|
|
{
|
|
Data = result,
|
|
StatusCode = statuscode,
|
|
Message = error
|
|
};
|
|
}
|
|
public async Task<ResultModel<ConcessionValidationDto>> LoadConcessionValidationByIdAsync(int id)
|
|
{
|
|
ConcessionValidationDto result = null;
|
|
int statuscode = 0;
|
|
string error = "";
|
|
try
|
|
{
|
|
if (id > 0)
|
|
{
|
|
ConcessionValidation model = await _context.ConcessionValidations.FindAsync(id);
|
|
result = FillConcessionValidationDto(model);
|
|
statuscode = 1;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statuscode = 0;
|
|
error = ex.ToString();
|
|
throw;
|
|
}
|
|
|
|
return new ResultModel<ConcessionValidationDto>()
|
|
{
|
|
Data = result,
|
|
StatusCode = statuscode,
|
|
Message = error
|
|
};
|
|
}
|
|
public async Task<ResultModel<int>> SaveConcessionValidationAsync(ConcessionValidationDto item)
|
|
{
|
|
int result = default(int);
|
|
int statuscode = 0;
|
|
string error = "";
|
|
try
|
|
{
|
|
ConcessionValidation model;
|
|
if (item.Id > 0)
|
|
{
|
|
model = await _context.ConcessionValidations.FindAsync(item.Id);
|
|
model = FillConcessionValidation(item, model);
|
|
result = await _context.SaveChangesAsync();
|
|
}
|
|
else
|
|
{
|
|
model = new ConcessionValidation();
|
|
model = FillConcessionValidation(item, model);
|
|
_context.ConcessionValidations.Add(model);
|
|
result = await _context.SaveChangesAsync();
|
|
}
|
|
statuscode = 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statuscode = 0;
|
|
error = ex.ToString();
|
|
throw;
|
|
}
|
|
|
|
|
|
return new ResultModel<int>()
|
|
{
|
|
Data = result,
|
|
StatusCode = statuscode,
|
|
Message = error
|
|
};
|
|
|
|
}
|
|
|
|
public async Task<ResultModel<bool>> DeleteConcessionValidationAsync(int id)
|
|
{
|
|
bool result = true;
|
|
int statuscode = 0;
|
|
string error = "";
|
|
try
|
|
{
|
|
if (id > 0)
|
|
{
|
|
ConcessionValidation model = await _context.ConcessionValidations.FindAsync(id);
|
|
model.Active = false;
|
|
await _context.SaveChangesAsync();
|
|
statuscode = 1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = false;
|
|
statuscode = 0;
|
|
error = ex.ToString();
|
|
throw;
|
|
}
|
|
|
|
|
|
return new ResultModel<bool>()
|
|
{
|
|
Data = result,
|
|
StatusCode = statuscode,
|
|
Message = error
|
|
};
|
|
}
|
|
public async Task<ResultModel<FileContent>> GetReport(DateTime fromDate, DateTime toDate)
|
|
{
|
|
int statusCode = 1;
|
|
string fileContext = "filecontain as string this is file contain in string format";
|
|
var result = new FileContent
|
|
{
|
|
Content = Convert.FromBase64String(fileContext),
|
|
FileName = "excel extension"
|
|
};
|
|
var task = await Task.Run(() => 1);
|
|
return new ResultModel<FileContent>
|
|
{
|
|
Data = result,
|
|
StatusCode = statusCode
|
|
};
|
|
}
|
|
|
|
|
|
}
|
|
} |