608 lines
29 KiB
C#
608 lines
29 KiB
C#
using AutoMapper;
|
|
using Azure.Core;
|
|
using CPRNIMS.Domain.Services.ICanvass;
|
|
using CPRNIMS.Infrastructure.Database;
|
|
using CPRNIMS.Infrastructure.Dto.Canvass;
|
|
using CPRNIMS.Infrastructure.Dto.Canvass.Request;
|
|
using CPRNIMS.Infrastructure.Dto.Canvass.Response;
|
|
using CPRNIMS.Infrastructure.Entities.Canvass;
|
|
using CPRNIMS.Infrastructure.Entities.Purchasing;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.ViewModel.Common;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static CPRNIMS.Domain.Services.OutputParamMessage;
|
|
|
|
namespace CPRNIMS.Domain.Services.Canvass
|
|
{
|
|
public class Canvass : Contracts.Canvass.ICanvass
|
|
{
|
|
private readonly NonInventoryDbContext _dbContext;
|
|
private readonly SMTPHelper _smptHelper;
|
|
private readonly IMapper _mapper;
|
|
public Canvass(NonInventoryDbContext dbContext, SMTPHelper smptHelper,IMapper mapper)
|
|
{
|
|
_dbContext = dbContext;
|
|
_smptHelper = smptHelper;
|
|
_mapper = mapper;
|
|
}
|
|
#region Get
|
|
public async Task<List<ItemListWOEmail>> GetItemSupplierWOEmail(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.ItemListWOEmails
|
|
.FromSqlRaw($"EXEC GetItemSupplierWOEmail @PRNo = '{CanvassDto.PRNo}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<ItemListWOEmail>();
|
|
}
|
|
public async Task<List<BiddingItem>> GetSupplierBid(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.BiddingItems
|
|
.FromSqlRaw($"EXEC GetSupplierBid @UserId,@IsHistory",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@IsHistory", CanvassDto.IsHistory))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<BiddingItem>();
|
|
}
|
|
public async Task<List<PerSupplier>> GetCanvassPerSupplier(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PerSuppliers
|
|
.FromSqlRaw($"EXEC GetCanvassPerSupplier @UserId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PerSupplier>();
|
|
}
|
|
public async Task<List<RFQPerSupplier>> GetSupplierBidByItem(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.RFQPerSuppliers
|
|
.FromSqlRaw($"EXEC GetSupplierBidByItem @UserId,@Status,@ItemNo,@CanvassId,@IsHistory,@PRDetailsId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@Status", CanvassDto.Status),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo),
|
|
new SqlParameter("@CanvassId", CanvassDto.CanvassId),
|
|
new SqlParameter("@IsHistory", CanvassDto.IsHistory),
|
|
new SqlParameter("@PRDetailsId", CanvassDto.PRDetailsId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<RFQPerSupplier>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetCanvassById(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw("EXEC GetCanvassById @UserId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetCanvassByItemNo(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw($"EXEC GetCanvassByItemNo @UserId, @ItemNo",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetCanvassByPRNo(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw("EXEC GetCanvassByPRNo @UserId, @PRNo",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@PRNo", CanvassDto.PRNo))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<CanvassGroupByPRNo>> GetCanvassGroupByPRNo(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.CanvassGroupByPRNos
|
|
.FromSqlRaw("EXEC GetCanvassGroupByPRNo @UserId,@PRNo,@AggreItemNo,@IsTagging",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@PRNo", CanvassDto.PRNo),
|
|
new SqlParameter("@AggreItemNo", CanvassDto.AggreItemNo ?? "N/A"),
|
|
new SqlParameter("@IsTagging", CanvassDto.IsTagging))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<CanvassGroupByPRNo>();
|
|
}
|
|
public async Task<List<SupplierResponse>> GetSupplierItemWOEmail(CanvassDto canvassDto)
|
|
{
|
|
// 1. Use Interpolated string to prevent SQL injection and pass the parameter safely
|
|
var suppliers = await _dbContext.Suppliers
|
|
.FromSqlInterpolated($"EXEC GetSupplierItemWOEmail @ItemNo = {canvassDto.ItemNo}")
|
|
.ToListAsync();
|
|
|
|
// 2. Map the List of entities to a List of Response objects
|
|
// AutoMapper handles collections automatically if the types are configured
|
|
return _mapper.Map<List<SupplierResponse>>(suppliers);
|
|
}
|
|
|
|
public async Task<List<SupplierResponse>> GetSupplierById(CanvassDto CanvassDto)
|
|
{
|
|
var item = await _dbContext.Suppliers
|
|
.FromSqlRaw($"EXEC GetSupplierById @SupplierId",
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId))
|
|
.ToListAsync();
|
|
// 2. Map the List of entities to a List of Response objects
|
|
// AutoMapper handles collections automatically if the types are configured
|
|
return _mapper.Map<List<SupplierResponse>>(item);
|
|
}
|
|
public async Task<List<RFQReference>> GetRFQ(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.RFQReferences
|
|
.FromSqlRaw($"EXEC GetRFQPerSupplier @SupplierId,@UserId",
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId),
|
|
new SqlParameter("@UserId", CanvassDto.UserId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<RFQReference>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetPRItemList(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw($"EXEC GetPRItemList @UserId = '{CanvassDto.UserId}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetCanvassPerSupplierEmail(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw($"EXEC GetCanvassPerSupplierEmail @UserId = '{CanvassDto.UserId}', @EmailAddress = '{CanvassDto.EmailAddress}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<PRCanvassDetail>> GetPRItem(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw($"EXEC GetPRItem @UserId = '{CanvassDto.UserId}', @ItemNo = {CanvassDto.ItemNo}")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
public async Task<List<WOResponse>> GetCanvassWOResponse(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.WOResponses
|
|
.FromSqlRaw($"EXEC GetCanvassWOResponse @UserId = '{CanvassDto.UserId}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<WOResponse>();
|
|
}
|
|
public async Task<int> GetCanvassNo()
|
|
{
|
|
var latestCanvassNo = await _dbContext.Canvasses
|
|
.OrderByDescending(ic => ic.CanvassNo)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (latestCanvassNo != null)
|
|
{
|
|
return latestCanvassNo.CanvassNo;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
public async Task<List<ItemWithoutSupplier>> GetItemWithoutSupplier()
|
|
{
|
|
var allItems = await _dbContext.ItemWithoutSuppliers
|
|
.FromSqlRaw("EXEC GetItemWithoutSupplier")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<ItemWithoutSupplier>();
|
|
}
|
|
public async Task<List<WOResponseById>> GetWOResponseBySuppId(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.WOResponseByIds
|
|
.FromSqlRaw($"EXEC GetWOResponseBySuppId @UserId = '{CanvassDto.UserId}',@SupplierId = '{CanvassDto.SupplierId}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<WOResponseById>();
|
|
}
|
|
public async Task<RFQ> PostPerSupplierToken(CanvassDto CanvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PostPerSupplierToken @UserId,@SupplierId,@PRNo,@ItemNo,@CanvassNo,@PRDetailsId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId),
|
|
new SqlParameter("@PRNo", CanvassDto.PRNo),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo),
|
|
new SqlParameter("@CanvassNo", CanvassDto.CanvassNo),
|
|
new SqlParameter("@PRDetailsId", CanvassDto.PRDetailsId));
|
|
|
|
return new RFQ();
|
|
}
|
|
public async Task<List<SupplierBidById>> GetSupplierBidById(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.SupplierBidByIds
|
|
.FromSqlRaw($"EXEC GetSupplierBidById @CanvassDetailId",
|
|
new SqlParameter("@CanvassDetailId", CanvassDto.CanvassDetailId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<SupplierBidById>();
|
|
}
|
|
public async Task<List<SupplierResponse>> GetMySuppliers(CanvassDto CanvassDto)
|
|
{
|
|
var items = await _dbContext.Suppliers
|
|
.FromSqlRaw($"EXEC GetMySuppliers @UserId,@SupplierId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId))
|
|
.ToListAsync();
|
|
|
|
return _mapper.Map<List<SupplierResponse>>(items);
|
|
}
|
|
public async Task<List<MyPRWOCanvass>> GetMyPRWOCanvass(CanvassDto itemDto)
|
|
{
|
|
var allItems = await _dbContext.MyPRWOCanvass
|
|
.FromSqlRaw($"EXEC GetMyPRWOCanvass @UserId,@SupplierId,@Query",
|
|
new SqlParameter("@UserId", itemDto.UserId),
|
|
new SqlParameter("@SupplierId", itemDto.SupplierId),
|
|
new SqlParameter("@Query", itemDto.Query))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<MyPRWOCanvass>();
|
|
}
|
|
public async Task<List<Infrastructure.Entities.Canvass.PRList>>
|
|
GetPRListByPRNo(CanvassDto canvassDto)
|
|
{
|
|
var allItems = await _dbContext.PRItemList
|
|
.FromSqlRaw($"EXEC GetPRListByPRNo @PRNo,@UserId",
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
new SqlParameter("@PRNo", canvassDto.PRNo))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<Infrastructure.Entities.Canvass.PRList>();
|
|
}
|
|
|
|
public async Task<List<PRCanvassDetail>> GetCanvassPerSupplierId(CanvassDto itemCodeDto)
|
|
{
|
|
var allItems = await _dbContext.PRCanvassDetails
|
|
.FromSqlRaw($"EXEC GetCanvassPerSupplierId @UserId,@SupplierId",
|
|
new SqlParameter("@UserId", itemCodeDto.UserId),
|
|
new SqlParameter("@SupplierId", itemCodeDto.SupplierId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<PRCanvassDetail>();
|
|
}
|
|
|
|
public async Task<List<AlternativeOfferDetails>>
|
|
GetAlternativeOfferByPRDetailId(CanvassDto canvassDto)
|
|
{
|
|
var allItems = await _dbContext.AlternativeOfferDetails
|
|
.FromSqlRaw($"EXEC GetAlternativeOfferByPRDetailId @UserId,@PRDetailsId",
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
new SqlParameter("@PRDetailsId", canvassDto.PRDetailsId))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<AlternativeOfferDetails>();
|
|
}
|
|
public async Task<List<ForCanvass>> GetForCanvassPerItem(CanvassDto CanvassDto)
|
|
{
|
|
var allItems = await _dbContext.ForCanvasses
|
|
.FromSqlRaw($"EXEC GetForCanvassPerItem @UserId,@ItemNo",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo))
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<ForCanvass>();
|
|
}
|
|
public async Task<List<ForCanvassFollowUp>> GetCanvassForFollowUp(CanvassDto canvassDto)
|
|
{
|
|
var allItems = await _dbContext.ForCanvassFollowUps
|
|
.FromSqlRaw($"EXEC GetCanvassForFollowUp")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<ForCanvassFollowUp>();
|
|
}
|
|
public async Task<List<AllForCanvass>> GetAllForCanvass()
|
|
{
|
|
var allForCanvass = await _dbContext.AllForCanvasses
|
|
.FromSqlRaw("EXEC GetAllForCanvass").ToListAsync();
|
|
return allForCanvass ?? new List<AllForCanvass>();
|
|
}
|
|
#endregion
|
|
#region Post Put
|
|
public async Task<Result<SupplierResponse>> PostSupplierAsync(SupplierRequest request, CancellationToken ct)
|
|
{
|
|
var strategy = _dbContext.Database.CreateExecutionStrategy();
|
|
|
|
return await strategy.ExecuteAsync(async () =>
|
|
{
|
|
await using var transaction = await _dbContext.Database.BeginTransactionAsync(ct);
|
|
|
|
try
|
|
{
|
|
var supplier = await _dbContext.Suppliers
|
|
.FirstOrDefaultAsync(s => s.SupplierName == request.SupplierName, ct);
|
|
|
|
if (supplier == null)
|
|
{
|
|
supplier = _mapper.Map<Suppliers>(request);
|
|
await _dbContext.AddAsync(supplier, ct);
|
|
await _dbContext.SaveChangesAsync(ct);
|
|
}
|
|
|
|
await PostSupplierItems(supplier.SupplierId, request.ItemNo, ct);
|
|
|
|
await _dbContext.SaveChangesAsync(ct);
|
|
|
|
await transaction.CommitAsync(ct);
|
|
|
|
return Result<SupplierResponse>.Success(_mapper.Map<SupplierResponse>(supplier));
|
|
}
|
|
catch (DbUpdateException ex)
|
|
{
|
|
await transaction.RollbackAsync(ct);
|
|
|
|
// handle unique constraint violation here if needed
|
|
throw;
|
|
}
|
|
});
|
|
}
|
|
private async Task PostSupplierItems(int supplierId, long itemNo, CancellationToken ct)
|
|
{
|
|
var exists = await _dbContext.SupplierItems.AnyAsync(
|
|
s => s.SupplierId == supplierId && s.ItemNo == itemNo && s.IsActive,
|
|
ct);
|
|
|
|
if (!exists)
|
|
{
|
|
await _dbContext.SupplierItems.AddAsync(new SupplierItems
|
|
{
|
|
SupplierId = supplierId,
|
|
ItemNo = itemNo,
|
|
IsActive = true
|
|
}, ct);
|
|
}
|
|
}
|
|
public async Task<SupplierResponse> PostApprovedSupp(CanvassDto CanvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PostApprovedSupp @UserId,@CanvassId,@ItemNo",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@CanvassId", CanvassDto.CanvassId != null ? CanvassDto.CanvassId : 0L),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo != null ? CanvassDto.ItemNo : 0L));
|
|
|
|
return new SupplierResponse();
|
|
}
|
|
public async Task<CanvassDetail> PostSuggestedSupp(CanvassDto CanvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PostSuggestedSupp @UserId,@CanvassDetailId,@ItemNo,@SupplierId,@CanvassId",
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@CanvassDetailId", CanvassDto.CanvassDetailId),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo),
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId),
|
|
new SqlParameter("@CanvassId", CanvassDto.CanvassId));
|
|
return new CanvassDetail();
|
|
}
|
|
public async Task<PRCanvassDetail> PostCanvass(CanvassDto CanvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PostCanvass @UserId, @SupplierId, @Status,@Remarks",
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId != null ? CanvassDto.SupplierId : 0L),
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@Status", CanvassDto.Status),
|
|
new SqlParameter("@Remarks", CanvassDto.Remarks ?? "N/A"));
|
|
return new PRCanvassDetail();
|
|
}
|
|
public async Task<SupplierResponse> PostTaggingSupplier(CanvassDto CanvassDto)
|
|
{
|
|
var (messCode, message) = CreateOutputParams();
|
|
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PostPutSupplier @SupplierId, @ItemNo, @IsActive, @UserId, @SupplierName, " +
|
|
"@EmailAddress, @Address, @ContactNo, @ContactPerson,@IsTagging, @MessCode OUTPUT, @Message OUTPUT",
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId != null ? CanvassDto.SupplierId : 0L),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo),
|
|
new SqlParameter("@IsActive", CanvassDto.IsActive),
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@SupplierName", CanvassDto.SupplierName),
|
|
new SqlParameter("@EmailAddress", CanvassDto.EmailAddress),
|
|
new SqlParameter("@Address", CanvassDto.Address ?? "NONE"),
|
|
new SqlParameter("@ContactNo", CanvassDto.ContactNo ?? "NONE"),
|
|
new SqlParameter("@ContactPerson", CanvassDto.ContactPerson ?? "NONE"),
|
|
new SqlParameter("@IsTagging", CanvassDto.IsTagging),
|
|
messCode,
|
|
message);
|
|
|
|
if ((byte)messCode.Value == 0)
|
|
{
|
|
throw new Exception(message.Value.ToString());
|
|
}
|
|
return new SupplierResponse();
|
|
}
|
|
public async Task<SupplierResponse> PostPutItemTagging(CanvassDto canvassDto)
|
|
{
|
|
var (messCode, message) = CreateOutputParams();
|
|
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PostPutItemTagging @SupplierId, @ItemNo, @IsActive, @UserId," +
|
|
"@MessCode OUTPUT, @Message OUTPUT",
|
|
new SqlParameter("@SupplierId", canvassDto.SupplierId != null ? canvassDto.SupplierId : 0L),
|
|
new SqlParameter("@ItemNo", canvassDto.ItemNo),
|
|
new SqlParameter("@IsActive", canvassDto.IsActive),
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
messCode,
|
|
message);
|
|
|
|
if ((byte)messCode.Value == 0)
|
|
{
|
|
throw new Exception(message.Value.ToString());
|
|
}
|
|
return new SupplierResponse();
|
|
}
|
|
public async Task<SupplierResponse> PostPutSupplier(CanvassDto CanvassDto)
|
|
{
|
|
var messCode = new SqlParameter("@MessCode", SqlDbType.TinyInt) { Direction = ParameterDirection.Output };
|
|
var message = new SqlParameter("@Message", SqlDbType.VarChar, 8000) { Direction = ParameterDirection.Output };
|
|
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PostPutSupplier @SupplierId, @ItemNo, @IsActive, @UserId, @SupplierName, " +
|
|
"@EmailAddress, @Address, @ContactNo, @ContactPerson,@IsTagging, @MessCode OUTPUT, @Message OUTPUT",
|
|
new SqlParameter("@SupplierId", CanvassDto.SupplierId != null ? CanvassDto.SupplierId : 0L),
|
|
new SqlParameter("@ItemNo", CanvassDto.ItemNo),
|
|
new SqlParameter("@IsActive", CanvassDto.IsActive),
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@SupplierName", CanvassDto.SupplierName),
|
|
new SqlParameter("@EmailAddress", CanvassDto.EmailAddress),
|
|
new SqlParameter("@Address", CanvassDto.Address ?? "NONE"),
|
|
new SqlParameter("@ContactNo", CanvassDto.ContactNo ?? "NONE"),
|
|
new SqlParameter("@ContactPerson", CanvassDto.ContactPerson ?? "NONE"),
|
|
new SqlParameter("@IsTagging", CanvassDto.IsTagging),
|
|
messCode,
|
|
message);
|
|
|
|
if ((byte)messCode.Value == 0)
|
|
{
|
|
throw new Exception(message.Value.ToString());
|
|
}
|
|
|
|
return new SupplierResponse();
|
|
}
|
|
public async Task<SupplierResponse> PostPutMySupplier(CanvassDto canvassDto)
|
|
{
|
|
var messCode = new SqlParameter("@MessCode", SqlDbType.TinyInt) { Direction = ParameterDirection.Output };
|
|
var message = new SqlParameter("@Message", SqlDbType.VarChar, 8000) { Direction = ParameterDirection.Output };
|
|
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PostPutMySupplier @SupplierId, @ItemNo, @IsActive, @UserId, @SupplierName," +
|
|
"@EmailAddress, @Address, @ContactNo, @ContactPerson,@TinNo,@LeadTime,@CurrencyId,@VatInc,@PaymentTermsId," +
|
|
"@MessCode OUTPUT, @Message OUTPUT",
|
|
new SqlParameter("@SupplierId", canvassDto.SupplierId != null ? canvassDto.SupplierId : 0L),
|
|
new SqlParameter("@ItemNo", canvassDto.ItemNo),
|
|
new SqlParameter("@IsActive", canvassDto.IsActive),
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
new SqlParameter("@SupplierName", canvassDto.SupplierName),
|
|
new SqlParameter("@EmailAddress", canvassDto.EmailAddress),
|
|
new SqlParameter("@Address", canvassDto.Address ?? "NONE"),
|
|
new SqlParameter("@ContactNo", canvassDto.ContactNo ?? "NONE"),
|
|
new SqlParameter("@ContactPerson", canvassDto.ContactPerson ?? "NONE"),
|
|
new SqlParameter("@TinNo", canvassDto.TinNo ?? "NONE"),
|
|
new SqlParameter("@LeadTime", canvassDto.LeadTime ?? "NONE"),
|
|
new SqlParameter("@CurrencyId", canvassDto.CurrencyId),
|
|
new SqlParameter("@VatInc", canvassDto.VatInc),
|
|
new SqlParameter("@PaymentTermsId", canvassDto.PaymentTermsId),
|
|
messCode,
|
|
message);
|
|
|
|
if ((byte)messCode.Value == 0)
|
|
{
|
|
throw new Exception(message.Value.ToString());
|
|
}
|
|
|
|
return new SupplierResponse();
|
|
}
|
|
public async Task<CanvassDetail> PutSuppUnitPrice(CanvassDto CanvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PutSuppUnitPrice @UserId, @CanvassDetailId, @UnitPrice",
|
|
new SqlParameter("@CanvassDetailId", CanvassDto.CanvassDetailId != null ? CanvassDto.CanvassDetailId : 0L),
|
|
new SqlParameter("@UserId", CanvassDto.UserId),
|
|
new SqlParameter("@UnitPrice", CanvassDto.UnitPrice));
|
|
return new CanvassDetail();
|
|
}
|
|
public async Task<ForCanvassFollowUp> PutSupplierCanvass(long canvassSupplierId)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PutCanvassForFollowUp @CanvassSupplierId",
|
|
new SqlParameter("@CanvassSupplierId", canvassSupplierId));
|
|
return new ForCanvassFollowUp();
|
|
}
|
|
public async Task<CanvassDetail> PutSuppBidDetails(CanvassDto canvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync($"EXEC PutSuppBidDetails @UserId,@CanvassDetailId,@PRDetailsId,@UnitPrice,@Terms," +
|
|
$"@ItemName,@Specification,@Qty,@DeliveryDate,@CurrencyId,@Remarks,@Manufacturer,@UOMName,@IsReset",
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
new SqlParameter("@CanvassDetailId", canvassDto.CanvassDetailId),
|
|
new SqlParameter("@PRDetailsId", canvassDto.PRDetailsId),
|
|
new SqlParameter("@UnitPrice", canvassDto.UnitPrice),
|
|
new SqlParameter("@Terms", canvassDto.Terms),
|
|
new SqlParameter("@ItemName", canvassDto.ItemName),
|
|
new SqlParameter("@Specification", canvassDto.Specification),
|
|
new SqlParameter("@Qty", canvassDto.Qty),
|
|
new SqlParameter("@DeliveryDate", canvassDto.CommitmentDate),
|
|
new SqlParameter("@CurrencyId", canvassDto.CurrencyId),
|
|
new SqlParameter("@Remarks", canvassDto.Remarks),
|
|
new SqlParameter("@Manufacturer", canvassDto.Manufacturer),
|
|
new SqlParameter("@UOMName", canvassDto.UOMName),
|
|
new SqlParameter("@IsReset", canvassDto.IsReset));
|
|
return new CanvassDetail();
|
|
}
|
|
public async Task<CanvassSupplier> UnlockFormLink(CanvassDto canvassDto)
|
|
{
|
|
await _dbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC UnlockFormLink @UserId,@CanvassSupplierId",
|
|
new SqlParameter("@UserId", canvassDto.UserId),
|
|
new SqlParameter("@CanvassSupplierId", canvassDto.CanvassSupplierId));
|
|
return new CanvassSupplier();
|
|
}
|
|
|
|
public async Task SendRFQ(SupplierEmailRequest supplierEmailRequest)
|
|
{
|
|
var baseTemplate = EMailTemplate("Content\\SMTPEmailContent", "SendToSupplier.cshtml");
|
|
|
|
var message = new StringBuilder(baseTemplate);
|
|
|
|
message.Replace("@ViewBag.FormLink", Convert.ToString(supplierEmailRequest.FormLink + supplierEmailRequest.Token));
|
|
message.Replace("@ViewBag.Supplier", supplierEmailRequest.SupplierName);
|
|
message.Replace("@ViewBag.Signature", supplierEmailRequest.Purchaser);
|
|
|
|
var messageDetails = new EmailMessageDetailsVM
|
|
{
|
|
Recipient = supplierEmailRequest.Recipient,
|
|
Message = message.ToString(),
|
|
Subject = supplierEmailRequest.Subject,
|
|
CC = supplierEmailRequest.CC,
|
|
IsSuccess = supplierEmailRequest.IsSuccess,
|
|
SenderEmail = supplierEmailRequest.UserName,
|
|
DisplayName = "llipurchasing.com",
|
|
NewPassword = supplierEmailRequest.Password,
|
|
OutGoingPort = supplierEmailRequest.OutGoingPort,
|
|
Server = supplierEmailRequest.Server,
|
|
UserName = supplierEmailRequest.UserName,
|
|
IsCanvass= supplierEmailRequest.IsCanvass,
|
|
AttachPath=supplierEmailRequest.AttachPath
|
|
};
|
|
|
|
await _smptHelper.SendEmailAsync(messageDetails);
|
|
}
|
|
public string EMailTemplate(string relativePath, string emailTemplate)
|
|
{
|
|
string basePath = AppContext.BaseDirectory;
|
|
string templateFolderPath = Path.Combine(basePath, relativePath);
|
|
string templateFilePath = Path.Combine(templateFolderPath, emailTemplate);
|
|
|
|
if (System.IO.File.Exists(templateFilePath))
|
|
{
|
|
return System.IO.File.ReadAllText(templateFilePath);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"File not found: {templateFilePath}");
|
|
return "Template file not found";
|
|
}
|
|
}
|
|
|
|
public async Task<bool> SearchingUpdate(long pRDetailsId)
|
|
{
|
|
var rowsAffected = await _dbContext.PRDetails
|
|
.Where(p => p.PRDetailsId == pRDetailsId)
|
|
.ExecuteUpdateAsync(s => s.SetProperty(p => p.IsSearched, true));
|
|
|
|
return rowsAffected > 0;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|