commit change all folder
This commit is contained in:
@@ -0,0 +1,371 @@
|
||||
//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 string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionValidationRepository(
|
||||
DataContext context,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
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;
|
||||
dto.StaffFirstName = model.StaffFirstName;
|
||||
dto.StaffLastName = model.StaffLastName;
|
||||
dto.StaffEmail = model.StaffEmail;
|
||||
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.StaffFirstName = model.StaffFirstName;
|
||||
dto.StaffLastName = model.StaffLastName;
|
||||
dto.StaffEmail = model.StaffEmail;
|
||||
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.Trim();
|
||||
model.ConcessionExpiry = dto.ConcessionExpiry;
|
||||
model.ConcessionHolder = dto.ConcessionHolder.Trim();
|
||||
model.ConcessionTypeID = dto.ConcessionTypeId;
|
||||
model.ValidationID = dto.Id;
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.StaffFirstName = dto.StaffFirstName.Trim();
|
||||
model.StaffLastName = dto.StaffLastName.Trim();
|
||||
model.StaffEmail = dto.StaffEmail.Trim();
|
||||
model.ValidateDate = dto.ValidateDate.ToLocalTime();
|
||||
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 fromDate, DateTime toDate)
|
||||
{
|
||||
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, fromDate, toDate);
|
||||
/*
|
||||
//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;
|
||||
result.Sort((x, y) => x.ValidateDate.CompareTo(y.ValidateDate));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionValidationExtDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<int>> CheckConcessionValidationStaffLinkNoAsync(string staffLinkNo, string concessionCard, DateTime currentDate, int id)
|
||||
{
|
||||
int statuscode = 1;
|
||||
int result = 1;
|
||||
int number = id < 1 ? 0 : 1; // if insert check > 0 . if modify > 1
|
||||
string message = "warning you already add concession card on this date!";
|
||||
try
|
||||
{
|
||||
var anyRecord = await _context.SelectCheckConcessionValidationAsync(currentDate.ToLocalTime().Date, concessionCard.Trim(), staffLinkNo.Trim());
|
||||
|
||||
if (anyRecord.Count > number)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 1; //test
|
||||
message = "test OK just one time";
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = "Error " + ex.ToString();
|
||||
statuscode = 0;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<ResultModel<int>> CheckConcessionValidationStaffLinkNoAsync_old(string staffLinkNo, string concessionCard, DateTime currentDate)
|
||||
{
|
||||
int statuscode = 1;
|
||||
int result = 1;
|
||||
string concard = concessionCard.Trim();
|
||||
string message = "warning you already add concession card on this date!";
|
||||
try
|
||||
{
|
||||
var anyRecord = await _context.ConcessionValidations.Where(x =>
|
||||
x.StafflinkNo == staffLinkNo
|
||||
&& x.ConcessionCard == concard
|
||||
&& x.Active == true
|
||||
&& x.ValidateDate.Date == currentDate.ToLocalTime().Date
|
||||
).ToListAsync();
|
||||
if (anyRecord.Count > 0)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 1; //test
|
||||
message = "test OK just one time";
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = "Error " + ex.ToString();
|
||||
statuscode = 0;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
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 = "";
|
||||
//_currentUser = item.StafflinkNo;
|
||||
try
|
||||
{
|
||||
ConcessionValidation model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.ConcessionValidations.FindAsync(item.Id);
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ConcessionValidation();
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
model.CreatedDate = DateTime.Now;
|
||||
model.CreatedId = _currentUser;
|
||||
_context.ConcessionValidations.Add(model);
|
||||
result = await _context.SaveChangesAsync();
|
||||
result = model.ValidationID;
|
||||
}
|
||||
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;
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
//_context.ConcessionValidations.Remove(model);
|
||||
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";
|
||||
//await this._concessionValidationReport.GetConcessionValidationReport(DateTime.Today.AddDays(-30), DateTime.Today.AddDays(30));
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user