Add OtpDialogService for mobile-friendly OTP authentication dialog
This commit is contained in:
@@ -35,20 +35,20 @@ public class AuthService
|
||||
public async Task<bool> IsCompleteRegisterAsync()
|
||||
{
|
||||
await InitUserAuthInfo();
|
||||
if (_userAuthInfo.NationalCode ==null || _userAuthInfo.FirstName == null || _userAuthInfo.LastName == null || !_userAuthInfo.IsSignMainContract)
|
||||
if (!string.IsNullOrWhiteSpace(_userAuthInfo.NationalCode) && !string.IsNullOrWhiteSpace(_userAuthInfo.FirstName) && !string.IsNullOrWhiteSpace(_userAuthInfo.LastName) && _userAuthInfo.IsSignMainContract)
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public bool IsCompleteRegister()
|
||||
{
|
||||
InitUserAuthInfo().GetAwaiter();
|
||||
if (_userAuthInfo.NationalCode ==null || _userAuthInfo.FirstName == null || _userAuthInfo.LastName == null || _userAuthInfo.IsSignMainContract)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (!string.IsNullOrWhiteSpace(_userAuthInfo.NationalCode) && !string.IsNullOrWhiteSpace(_userAuthInfo.FirstName) && !string.IsNullOrWhiteSpace(_userAuthInfo.LastName) && _userAuthInfo.IsSignMainContract)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public async Task<UserAuthInfo> GetUserAuthInfo()
|
||||
{
|
||||
|
||||
61
src/FrontOffice.Main/Utilities/CartService.cs
Normal file
61
src/FrontOffice.Main/Utilities/CartService.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record CartItem(long ProductId, string Title, string ImageUrl, long UnitPrice, int Quantity)
|
||||
{
|
||||
public long LineTotal => UnitPrice * Quantity;
|
||||
}
|
||||
|
||||
public class CartService
|
||||
{
|
||||
private readonly List<CartItem> _items = new();
|
||||
public event Action? OnChange;
|
||||
|
||||
public IReadOnlyList<CartItem> Items => _items.AsReadOnly();
|
||||
public long Total => _items.Sum(i => i.LineTotal);
|
||||
public int Count => _items.Sum(i => i.Quantity);
|
||||
|
||||
public void Add(Product product, int quantity = 1)
|
||||
{
|
||||
if (quantity <= 0) return;
|
||||
var existing = _items.FirstOrDefault(i => i.ProductId == product.Id);
|
||||
if (existing is null)
|
||||
{
|
||||
_items.Add(new CartItem(product.Id, product.Title, product.ImageUrl, product.Price, quantity));
|
||||
}
|
||||
else
|
||||
{
|
||||
var idx = _items.IndexOf(existing);
|
||||
_items[idx] = existing with { Quantity = existing.Quantity + quantity };
|
||||
}
|
||||
Notify();
|
||||
}
|
||||
|
||||
public void UpdateQuantity(long productId, int quantity)
|
||||
{
|
||||
var existing = _items.FirstOrDefault(i => i.ProductId == productId);
|
||||
if (existing is null) return;
|
||||
if (quantity <= 0)
|
||||
{
|
||||
Remove(productId);
|
||||
return;
|
||||
}
|
||||
var idx = _items.IndexOf(existing);
|
||||
_items[idx] = existing with { Quantity = quantity };
|
||||
Notify();
|
||||
}
|
||||
|
||||
public void Remove(long productId)
|
||||
{
|
||||
_items.RemoveAll(i => i.ProductId == productId);
|
||||
Notify();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_items.Clear();
|
||||
Notify();
|
||||
}
|
||||
|
||||
private void Notify() => OnChange?.Invoke();
|
||||
}
|
||||
|
||||
47
src/FrontOffice.Main/Utilities/OrderService.cs
Normal file
47
src/FrontOffice.Main/Utilities/OrderService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public enum PaymentMethod
|
||||
{
|
||||
Wallet = 1,
|
||||
}
|
||||
|
||||
public enum OrderStatus
|
||||
{
|
||||
Pending = 0,
|
||||
Paid = 1,
|
||||
}
|
||||
|
||||
public record OrderItem(long ProductId, string Title, string ImageUrl, long UnitPrice, int Quantity)
|
||||
{
|
||||
public long LineTotal => UnitPrice * Quantity;
|
||||
}
|
||||
|
||||
public class Order
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Pending;
|
||||
public PaymentMethod PaymentMethod { get; set; } = PaymentMethod.Wallet;
|
||||
public long AddressId { get; set; }
|
||||
public string AddressSummary { get; set; } = string.Empty;
|
||||
public List<OrderItem> Items { get; set; } = new();
|
||||
public long Total => Items.Sum(i => i.LineTotal);
|
||||
}
|
||||
|
||||
public class OrderService
|
||||
{
|
||||
private long _seq = 1000;
|
||||
private readonly List<Order> _orders = new();
|
||||
|
||||
public Task<List<Order>> GetOrdersAsync() => Task.FromResult(_orders.OrderByDescending(o => o.CreatedAt).ToList());
|
||||
|
||||
public Task<Order?> GetOrderAsync(long id) => Task.FromResult(_orders.FirstOrDefault(o => o.Id == id));
|
||||
|
||||
public Task<long> CreateOrderAsync(Order order)
|
||||
{
|
||||
order.Id = Interlocked.Increment(ref _seq);
|
||||
_orders.Add(order);
|
||||
return Task.FromResult(order.Id);
|
||||
}
|
||||
}
|
||||
|
||||
44
src/FrontOffice.Main/Utilities/ProductService.cs
Normal file
44
src/FrontOffice.Main/Utilities/ProductService.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record Product(long Id, string Title, string Description, string ImageUrl, long Price);
|
||||
|
||||
public class ProductService
|
||||
{
|
||||
private static readonly List<Product> _seed = new()
|
||||
{
|
||||
new(1, "ماسک پزشکی سهلایه", "ماسک سهلایه با فیلتراسیون بالا مناسب برای محیطهای عمومی.", "/images/store/mask.jpg", 49000),
|
||||
new(2, "دستکش لاتکس", "دستکش لاتکس مناسب معاینات پزشکی، بدون پودر.", "/images/store/gloves.jpg", 89000),
|
||||
new(3, "محلول ضدعفونی کننده", "محلول ضدعفونی بر پایه الکل ۷۰٪ مناسب دست و سطوح.", "/images/store/sanitizer.jpg", 69000),
|
||||
new(4, "تبسنج دیجیتال", "تبسنج دیجیتال با دقت بالا و نمایشگر LCD.", "/images/store/thermometer.jpg", 299000),
|
||||
new(5, "فشارسنج دیجیتال", "فشارسنج بازویی دیجیتال با حافظه داخلی.", "/images/store/bp-monitor.jpg", 1259000)
|
||||
};
|
||||
|
||||
private readonly ConcurrentDictionary<long, Product> _products = new();
|
||||
|
||||
public ProductService()
|
||||
{
|
||||
foreach (var p in _seed) _products[p.Id] = p;
|
||||
}
|
||||
|
||||
public Task<List<Product>> GetProductsAsync(string? query = null)
|
||||
{
|
||||
IEnumerable<Product> list = _products.Values.OrderBy(p => p.Id);
|
||||
if (!string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
query = query.Trim();
|
||||
list = list.Where(p =>
|
||||
p.Title.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
||||
p.Description.Contains(query, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
return Task.FromResult(list.ToList());
|
||||
}
|
||||
|
||||
public Task<Product?> GetByIdAsync(long id)
|
||||
{
|
||||
_products.TryGetValue(id, out var result);
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ public static class RouteConstants
|
||||
public static class Profile
|
||||
{
|
||||
public const string Index = "/profile";
|
||||
public const string Personal = "/profile/personal";
|
||||
public const string Addresses = "/profile/addresses";
|
||||
public const string Settings = "/profile/settings";
|
||||
public const string Tree = "/profile/tree";
|
||||
public const string Wallet = "/profile/wallet";
|
||||
}
|
||||
|
||||
public static class Package
|
||||
@@ -41,4 +46,14 @@ public static class RouteConstants
|
||||
{
|
||||
public const string Index = "/checkout";
|
||||
}
|
||||
|
||||
public static class Store
|
||||
{
|
||||
public const string Products = "/products";
|
||||
public const string ProductDetail = "/product/"; // usage: /product/{id}
|
||||
public const string Cart = "/cart";
|
||||
public const string CheckoutSummary = "/checkout-summary";
|
||||
public const string Orders = "/orders";
|
||||
public const string OrderDetail = "/order/"; // usage: /order/{id}
|
||||
}
|
||||
}
|
||||
|
||||
20
src/FrontOffice.Main/Utilities/WalletService.cs
Normal file
20
src/FrontOffice.Main/Utilities/WalletService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record WalletBalances(long CreditBalance, long NetworkBalance);
|
||||
public record WalletTransaction(DateTime Date, long Amount, string Channel, string Description);
|
||||
|
||||
public class WalletService
|
||||
{
|
||||
private WalletBalances _balances = new(350_000, 1_250_000);
|
||||
private readonly List<WalletTransaction> _transactions = new()
|
||||
{
|
||||
new(DateTime.Now.AddDays(-1), 500_000, "درگاه بانکی", "شارژ کیف پول"),
|
||||
new(DateTime.Now.AddDays(-2), 200_000, "شبکه/معرف", "پاداش شبکه"),
|
||||
new(DateTime.Now.AddDays(-4), -120_000, "خرید", "برداشت بابت سفارش #1452"),
|
||||
new(DateTime.Now.AddDays(-9), 900_000, "کیف پول شرکای تجاری", "اعتبار خرید"),
|
||||
};
|
||||
|
||||
public Task<WalletBalances> GetBalancesAsync() => Task.FromResult(_balances);
|
||||
public Task<List<WalletTransaction>> GetTransactionsAsync() => Task.FromResult(_transactions.OrderByDescending(t => t.Date).ToList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user