Comments (2)
Hello, there is a solution for this, you need to write a service and delete visitors at certain intervals.
from simplcommerce.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.Core.Models;
using SimplCommerce.Module.ProductComparison.Models;
using SimplCommerce.Module.ShoppingCart.Models;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NCrontab;
namespace SimplCommerce.Module.ShoppingCart.Services
{
public class DeleteguestsBackground : BackgroundService
{
private readonly long SystemUserId = 2;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;
public DeleteguestsBackground(IServiceProvider serviceProvider, ILogger<DeleteguestsBackground> logger)
{
_serviceProvider = serviceProvider;
_logger = logger;
}
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("DeleteguestsBackground is starting.");
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("DeleteguestsBackground is working.");
await Task.Delay(TimeSpan.FromSeconds(1800), stoppingToken);
using (var scope = _serviceProvider.CreateScope())
{
var userRepository = scope.ServiceProvider.GetRequiredService<IRepository<User>>();
var _cartRepository = scope.ServiceProvider.GetRequiredService<IRepository<Cart>>();
var _cartItemRepository = scope.ServiceProvider.GetRequiredService<IRepository<CartItem>>();
var _compareRepository = scope.ServiceProvider.GetRequiredService<IRepository<ComparingProduct>>();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
await DeleteFailedUsers(userRepository, _cartRepository, _cartItemRepository, _compareRepository);
}
}
}
private async Task DeleteFailedUsers(IRepository<User> userRepository, IRepository<Cart> _cartRepository, IRepository<CartItem> _cartItemRepository,
IRepository<ComparingProduct> _compareRepository)
{
var user = await userRepository.Query().Include(x => x.Roles).ThenInclude(x => x.Role)
.Where(x => x.FullName == "Guest").ToListAsync();
foreach (var guest in user)
{
guest.Roles.Clear();
var GetCartCompare = _compareRepository.Query().Where(x => x.UserId == guest.Id).ToList();
if (GetCartCompare.Count > 0)
{
foreach (var compares in GetCartCompare)
{
_compareRepository.Remove(compares);
}
}
var GetCartUser = _cartRepository.Query().Where(x => x.CustomerId == guest.Id).ToList();
if (GetCartUser.Count > 0)
{
foreach (var item in GetCartUser)
{
var GetCartItem = _cartItemRepository.Query().Where(x => x.CartId == item.Id).ToList();
foreach (var Deleteıtem in GetCartItem)
{
_cartItemRepository.Remove(Deleteıtem);
}
_cartRepository.Remove(item);
}
}
userRepository.Remove(guest);
await userRepository.SaveChangesAsync();
}
}
}
}
from simplcommerce.
Related Issues (20)
- Loading very slow first time
- Can't open create category edit category create product edit product in plesk web server hosting..
- Entity, entitybase, entityService & CategoryService
- URL Routing in Project HOT 1
- How to work for test
- demo is offline
- Sitemap HOT 3
- HttpClient api 401 (unauthorized) Error
- update net 8 HOT 1
- Developer Guide Documentation : Not Found HOT 3
- Any outstanding issue which I can contribute.
- Missing Instructions
- An unhandled exception occurs when clicking on the 'Download Invoice' option under the 'Cash on Delivery' payment method. (Operation System: Windows, Version: 11) HOT 1
- Highlighting the names of products when they are low in quantity on the Stock Management page in the Admin.
- Isn't this project no longer maintained ? HOT 7
- Unable to resolve the .NET SDK version as specified in the global.json located ..path HOT 2
- update to net 8 Full stack web UI with Blazor
- Update file global.json HOT 1
- An error occurred while processing your request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simplcommerce.