491 lines
22 KiB
C#
491 lines
22 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AyCode.Core.Extensions;
|
|
using AyCode.Core.Loggers;
|
|
using AyCode.Services.SignalRs;
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
using FruitBank.Common.Dtos;
|
|
using FruitBank.Common.Entities;
|
|
using FruitBank.Common.Interfaces;
|
|
using FruitBank.Common.Loggers;
|
|
using FruitBank.Common.Models;
|
|
using FruitBank.Common.Server;
|
|
using FruitBank.Common.Server.Interfaces;
|
|
using FruitBank.Common.SignalRs;
|
|
using LinqToDB;
|
|
using Mango.Nop.Core.Dtos;
|
|
using Mango.Nop.Core.Loggers;
|
|
using Mango.Nop.Core.Models;
|
|
using Nop.Core;
|
|
using Nop.Core.Domain.Customers;
|
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
|
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
|
|
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
|
using Nop.Services.Customers;
|
|
using Nop.Services.Localization;
|
|
using Nop.Web.Framework.Controllers;
|
|
using NUglify.Helpers;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|
{
|
|
//https://linq2db.github.io/articles/sql/Join-Operators.html
|
|
public class FruitBankDataController(
|
|
FruitBankDbContext ctx,
|
|
MeasurementService measurementService,
|
|
IWorkContext workContext,
|
|
ICustomerService customerService,
|
|
ICustomerRegistrationService customerRegistrationService,
|
|
ILocalizationService localizationService,
|
|
IEnumerable<IAcLogWriterBase> logWriters)
|
|
: BasePluginController, IFruitBankDataControllerServer
|
|
{
|
|
private const int LastShippingDays = 15;
|
|
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
|
|
|
|
[SignalR(SignalRTags.ProcessAndSaveFullShippingJson)]
|
|
public async Task<List<Partner>> ProcessAndSaveFullShippingJson(string fullShippingJson, int customerId)
|
|
{
|
|
return await measurementService.ProcessAndSaveFullShippingJson(fullShippingJson, customerId);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetGenericAttributeDtosByEntityIdAndKeyGroup)]
|
|
public async Task<List<GenericAttributeDto>> GetGenericAttributeDtosByEntityIdAndKeyGroup(int productId, string keyGroup, int storeId)
|
|
{
|
|
return await ctx.GetGenericAttributeDtosByEntityIdAndKeyGroup(productId, keyGroup, storeId);
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddGenericAttributeDto)]
|
|
public async Task<GenericAttributeDto> AddGenericAttributeDto(GenericAttributeDto genericAttributeDto)
|
|
{
|
|
await ctx.GenericAttributeDtos.InsertAsync(genericAttributeDto);
|
|
return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateGenericAttributeDto)]
|
|
public async Task<GenericAttributeDto> UpdateGenericAttributeDto(GenericAttributeDto genericAttributeDto)
|
|
{
|
|
await ctx.GenericAttributeDtos.UpdateAsync(genericAttributeDto);
|
|
return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
|
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
|
|
{
|
|
_logger.Detail($"GetStockQuantityHistoryDtos invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
return await ctx.StockQuantityHistoryDtos.GetAll(true).Where(sqh => sqh.CreatedOnUtc >= fromDateUtc).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
|
|
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
|
|
{
|
|
_logger.Detail($"GetStockQuantityHistoryDtosByProductId invoked; productId: {productId}; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
return await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).Where(sqh => sqh.CreatedOnUtc >= fromDateUtc).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetMeasuringModels)]
|
|
public Task<List<MeasuringModel>> GetMeasuringModels()
|
|
{
|
|
throw new NotImplementedException("GetMeasuringModels");
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetPartners)]
|
|
public async Task<List<Partner>> GetPartners()
|
|
{
|
|
_logger.Detail($"GetPartners invoked");
|
|
|
|
return await ctx.Partners.GetAll().ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetPartnerById)]
|
|
public async Task<Partner> GetPartnerById(int id)
|
|
{
|
|
_logger.Detail($"GetPartnerById invoked; id: {id}");
|
|
|
|
//var customers = await ctx.GetCustormersBySystemRoleName("Measuring").ToListAsync();
|
|
//_logger.Error($"COUNT: {customers.Count}");
|
|
|
|
return await ctx.Partners.GetByIdAsync(id);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdatePartner)]
|
|
public async Task<Partner> UpdatePartner(Partner partner)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(partner);
|
|
|
|
_logger.Detail($"UpdatePartner invoked; id: {partner.Id}");
|
|
|
|
await ctx.Partners.UpdateAsync(partner);
|
|
return await ctx.Partners.GetByIdAsync(partner.Id, partner.ShippingDocuments != null);
|
|
}
|
|
|
|
|
|
[SignalR(SignalRTags.GetShippings)]
|
|
public async Task<List<Shipping>> GetShippings()
|
|
{
|
|
_logger.Detail($"GetShippings invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
return await ctx.Shippings.GetAll(true).Where(s => s.ShippingDate >= fromDateUtc).ToListAsync();
|
|
//return await ctx.Shippings.Table.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetNotMeasuredShippings)]
|
|
public async Task<List<Shipping>> GetNotMeasuredShippings()
|
|
{
|
|
_logger.Detail($"GetNotMeasuredShippings invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var startTime = DateTime.Now;
|
|
var shippings = await ctx.Shippings.GetAllNotMeasured(true, LastShippingDays).ToListAsync();
|
|
|
|
_logger.Detail($"GetNotMeasuredShippings; shippingsCount: {shippings.Count}; dbResponse: {(DateTime.Now - startTime).TotalSeconds} sec.");
|
|
return shippings;
|
|
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingById)]
|
|
public async Task<Shipping> GetShippingById(int id)
|
|
{
|
|
_logger.Detail($"GetShippingById invoked; id: {id}");
|
|
|
|
return await ctx.Shippings.GetByIdAsync(id, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddShipping)]
|
|
public async Task<Shipping> AddShipping(Shipping shipping)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shipping);
|
|
|
|
_logger.Detail($"AddShipping invoked; id: {shipping.Id}");
|
|
|
|
await ctx.Shippings.InsertAsync(shipping);
|
|
return await ctx.Shippings.GetByIdAsync(shipping.Id, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateShipping)]
|
|
public async Task<Shipping> UpdateShipping(Shipping shipping)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shipping);
|
|
|
|
_logger.Detail($"UpdateShipping invoked; id: {shipping.Id}");
|
|
|
|
await ctx.Shippings.UpdateAsync(shipping);
|
|
return await ctx.Shippings.GetByIdAsync(shipping.Id, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItems)]
|
|
public async Task<List<ShippingItem>> GetShippingItems()
|
|
{
|
|
_logger.Detail($"GetShippingItems invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
return await ctx.ShippingItems.GetAll(true).Where(si => si.ShippingDocument.Shipping == null ||
|
|
si.ShippingDocument.Shipping.ShippingDate >= fromDateUtc).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItemsByDocumentId)]
|
|
public async Task<List<ShippingItem>> GetShippingItemsByDocumentId(int shippingDocumentId)
|
|
{
|
|
_logger.Detail($"GetShippingItemsByDocumentId invoked");
|
|
|
|
return await ctx.ShippingItems.GetAllByShippingDocumentIdAsync(shippingDocumentId, true).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItemsByShippingId)]
|
|
public async Task<List<ShippingItem>> GetShippingItemsByShippingId(int shippingId)
|
|
{
|
|
_logger.Detail($"GetShippingItemsByShippingId invoked");
|
|
|
|
return await ctx.ShippingItems.GetAllByShippingIdAsync(shippingId, true).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItemsByPartnerId)]
|
|
public async Task<List<ShippingItem>> GetShippingItemsByPartnerId(int partnerId)
|
|
{
|
|
_logger.Detail($"GetShippingItemsByPartnerId invoked");
|
|
|
|
return await ctx.ShippingItems.GetAllByPartnerIdAsync(partnerId, true).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItemById)]
|
|
public async Task<ShippingItem> GetShippingItemById(int id)
|
|
{
|
|
_logger.Detail($"GetShippingItemById invoked; id: {id}");
|
|
|
|
var shippingItem = await ctx.ShippingItems.GetByIdAsync(id, true);
|
|
return shippingItem;
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddShippingItem)]
|
|
public async Task<ShippingItem> AddShippingItem(ShippingItem shippingItem)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItem);
|
|
|
|
_logger.Detail($"AddShippingItem invoked; id: {shippingItem.Id}");
|
|
|
|
if (!await ctx.AddShippingItemAsync(shippingItem)) return null;
|
|
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateShippingItem)]
|
|
public async Task<ShippingItem> UpdateShippingItem(ShippingItem shippingItem)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItem);
|
|
|
|
_logger.Detail($"UpdateShippingItem invoked; id: {shippingItem.Id}");
|
|
|
|
if (!await ctx.UpdateShippingItemSafeAsync(shippingItem)) return null;
|
|
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateMeasuredShippingItem)]
|
|
public async Task<ShippingItem> UpdateMeasuredShippingItem(ShippingItem shippingItem)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItem);
|
|
|
|
_logger.Detail($"UpdateMeasuredShippingItem invoked; id: {shippingItem.Id}");
|
|
|
|
if (!await ctx.UpdateMeasuredShippingItemSafeAsync(shippingItem)) return null;
|
|
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingItemPallets)]
|
|
public async Task<List<ShippingItemPallet>> GetShippingItemPallets()
|
|
{
|
|
_logger.Detail($"GetShippingItemPallets invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
|
|
return await ctx.ShippingItemPallets.GetAll(true).Where(sip => sip.ShippingItem.ShippingDocument.Shipping == null ||
|
|
sip.ShippingItem.ShippingDocument.Shipping.ShippingDate >= fromDateUtc).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddShippingItemPallet)]
|
|
public async Task<ShippingItemPallet> AddShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
|
|
|
_logger.Detail($"AddShippingItemPallet invoked; {shippingItemPallet}");
|
|
|
|
if (!await ctx.AddShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
|
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateShippingItemPallet)]
|
|
public async Task<ShippingItemPallet> UpdateShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
|
|
|
_logger.Detail($"UpdateShippingItemPallet invoked; {shippingItemPallet}");
|
|
|
|
if (!await ctx.UpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
|
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallets)]
|
|
public async Task<ShippingItem> AddOrUpdateMeasuredShippingItemPallets(List<ShippingItemPallet> shippingItemPallets)
|
|
{
|
|
// ArgumentNullException.ThrowIfNull(shippingItemPallets);
|
|
|
|
// _logger.Detail($"AddOrUpdateMeasuredShippingItemPallets invoked; count: {shippingItemPallets.Count}");
|
|
|
|
// if (shippingItemPallets.Count == 0) return null;
|
|
|
|
// var shippingItemId = shippingItemPallets.FirstOrDefault()!.ShippingItemId;
|
|
// if (shippingItemId <= 0 || shippingItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null;
|
|
|
|
// var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false);
|
|
// shippingItem.ShippingItemPallets = shippingItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList();
|
|
|
|
// return await UpdateMeasuredShippingItem(shippingItem);
|
|
|
|
return null;
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallet)]
|
|
public async Task<ShippingItemPallet> AddOrUpdateMeasuredShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
|
|
|
_logger.Detail($"AddOrUpdateMeasuredShippingItemPallet invoked; {shippingItemPallet}");
|
|
|
|
if (!await ctx.AddOrUpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
|
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingDocuments)]
|
|
public async Task<List<ShippingDocument>> GetShippingDocuments()
|
|
{
|
|
_logger.Detail($"GetShippingDocuments invoked; lastDaysCount: {LastShippingDays}");
|
|
|
|
var fromDateUtc = DateTime.UtcNow.Date.AddDays(-LastShippingDays);
|
|
return await ctx.ShippingDocuments.GetAll(true).Where(sd => sd.Shipping == null || sd.Shipping.ShippingDate >= fromDateUtc).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingDocumentById)]
|
|
public async Task<ShippingDocument> GetShippingDocumentById(int id)
|
|
{
|
|
_logger.Detail($"GetShippingDocumentById invoked; id: {id}");
|
|
|
|
return await ctx.ShippingDocuments.GetByIdAsync(id, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetShippingDocumentsByShippingId)]
|
|
public async Task<List<ShippingDocument>> GetShippingDocumentsByShippingId(int shippingId)
|
|
{
|
|
_logger.Detail($"GetShippingDocumentsByShippingId invoked; shippingId: {shippingId}");
|
|
|
|
return await ctx.ShippingDocuments.GetAllByShippingIdAsync(shippingId, true).ToListAsync();
|
|
}
|
|
[SignalR(SignalRTags.GetShippingDocumentsByProductId)]
|
|
public async Task<List<ShippingDocument>> GetShippingDocumentsByProductId(int productId)
|
|
{
|
|
_logger.Detail($"GetShippingDocumentsByProductId invoked; productId: {productId}");
|
|
|
|
return await ctx.ShippingDocuments.GetAllByProductIdAsync(productId, true).ToListAsync();
|
|
}
|
|
[SignalR(SignalRTags.GetShippingDocumentsByPartnerId)]
|
|
public async Task<List<ShippingDocument>> GetShippingDocumentsByPartnerId(int partnerId)
|
|
{
|
|
_logger.Detail($"GetShippingDocumentsByPartnerId invoked; partnerId: {partnerId}");
|
|
|
|
return await ctx.ShippingDocuments.GetAllByPartnerIdAsync(partnerId, true).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddShippingDocument)]
|
|
public async Task<ShippingDocument> AddShippingDocument(ShippingDocument shippingDocument)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingDocument);
|
|
|
|
_logger.Detail($"AddShippingDocument invoked; id: {shippingDocument.Id}");
|
|
|
|
await ctx.ShippingDocuments.InsertAsync(shippingDocument);
|
|
|
|
foreach (var item in shippingDocument.ShippingItems)
|
|
{
|
|
var product = await ctx.Products.GetByIdAsync(item.ProductId);
|
|
product.ProductCost = Convert.ToDecimal(item.UnitPriceOnDocument);
|
|
}
|
|
|
|
return await ctx.ShippingDocuments.GetByIdAsync(shippingDocument.Id, shippingDocument.Shipping != null || shippingDocument.Partner != null);
|
|
}
|
|
|
|
[SignalR(SignalRTags.UpdateShippingDocument)]
|
|
public async Task<ShippingDocument> UpdateShippingDocument(ShippingDocument shippingDocument)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(shippingDocument);
|
|
|
|
_logger.Detail($"UpdateShippingDocument invoked; id: {shippingDocument.Id}");
|
|
|
|
await ctx.ShippingDocuments.UpdateAsync(shippingDocument);
|
|
return await ctx.ShippingDocuments.GetByIdAsync(shippingDocument.Id, shippingDocument.Shipping != null || shippingDocument.Partner != null);
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetMeasuringUsers)]
|
|
public async Task<List<CustomerDto>> GetMeasuringUsers()
|
|
{
|
|
_logger.Detail($"GetMeasuringUsers invoked");
|
|
|
|
var customers = await ctx.GetCustomersBySystemRoleName(FruitBankConst.MeasuringRoleSystemName).Select(c => new CustomerDto(c)).ToListAsync();
|
|
return customers; //.ToModelDto<CustomerDto>();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetCustomerRolesByCustomerId)]
|
|
public async Task<List<CustomerRole>> GetCustomerRolesByCustomerId(int customerId)
|
|
{
|
|
_logger.Detail($"GetCustomerRolesByCustomerId invoked; customerId: {customerId}");
|
|
return await ctx.GetCustomerRolesByCustomerId(customerId).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetProductDtos)]
|
|
public async Task<List<ProductDto>> GetProductDtos()
|
|
{
|
|
_logger.Detail($"GetProductDtos invoked");
|
|
return await ctx.ProductDtos.GetAll(false).ToListAsync();
|
|
}
|
|
|
|
//[SignalR(SignalRTags.GetAllMeasuringProductDtos)]
|
|
//public async Task<List<MeasuringProductDto>> GetAllMeasuringProductDtos()
|
|
//{
|
|
// _logger.Detail($"GetAllMeasuringProductDtos invoked");
|
|
// return await ctx.GetAllMeasuringProductDtos(false).ToListAsync();
|
|
//}
|
|
|
|
[SignalR(SignalRTags.GetMeasuringProductDtoById)]
|
|
public async Task<ProductDto?> GetProductDtoById(int productId)
|
|
{
|
|
_logger.Detail($"GetProductDtoById invoked; productId: {productId}");
|
|
return await ctx.ProductDtos.GetByIdAsync(productId, true);
|
|
}
|
|
|
|
[SignalR(SignalRTags.AuthenticateUser)]
|
|
public async Task<MgLoginModelResponse> LoginMeasuringUser(MgLoginModelRequest loginModelRequest)
|
|
{
|
|
var customerEmail = loginModelRequest?.Email;
|
|
var customerPassword = loginModelRequest?.Password;
|
|
|
|
_logger.Detail($"LoginMeasuringUser invoked; customerEmail; {customerEmail}");
|
|
|
|
var resultLoginModel = new MgLoginModelResponse();
|
|
|
|
if (!customerEmail.IsNullOrWhiteSpace() && !customerPassword.IsNullOrWhiteSpace())
|
|
{
|
|
var loginResult = await customerRegistrationService.ValidateCustomerAsync(customerEmail, customerPassword);
|
|
|
|
switch (loginResult)
|
|
{
|
|
case CustomerLoginResults.Successful:
|
|
{
|
|
var customer = await customerService.GetCustomerByEmailAsync(customerEmail);
|
|
|
|
var isInMeasuringRole = await customerService.IsInCustomerRoleAsync(customer, FruitBankConst.MeasuringRoleSystemName);
|
|
if (!isInMeasuringRole)
|
|
{
|
|
resultLoginModel.ErrorMessage = "Is not in MeauringRole!";
|
|
break;
|
|
}
|
|
|
|
//var actionResult = await customerRegistrationService.SignInCustomerAsync(customer, returnUrl, loginModel.RememberMe);
|
|
|
|
//await _workContext.SetCurrentCustomerAsync(customer);
|
|
//await _authenticationService.SignInAsync(customer, isPersist);
|
|
////raise event
|
|
//await _eventPublisher.PublishAsync(new CustomerLoggedinEvent(customer));
|
|
|
|
resultLoginModel.CustomerDto = new CustomerDto(customer); //customer.ToModel<CustomerDto>();
|
|
break;
|
|
}
|
|
case CustomerLoginResults.CustomerNotExist:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.CustomerNotExist");
|
|
break;
|
|
case CustomerLoginResults.Deleted:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.Deleted");
|
|
break;
|
|
case CustomerLoginResults.NotActive:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.NotActive");
|
|
break;
|
|
case CustomerLoginResults.NotRegistered:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.NotRegistered");
|
|
break;
|
|
case CustomerLoginResults.LockedOut:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.LockedOut");
|
|
break;
|
|
case CustomerLoginResults.WrongPassword:
|
|
default:
|
|
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials");
|
|
break;
|
|
}
|
|
}
|
|
else resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials");
|
|
|
|
if (!resultLoginModel.ErrorMessage.IsNullOrWhiteSpace()) _logger.Error($"{resultLoginModel.ErrorMessage}; email: {customerEmail}");
|
|
return resultLoginModel;
|
|
}
|
|
}
|
|
}
|