OElite.Services.Platform 5.0.9-develop.472

OElite.Services.Platform

NuGet Version Target Framework

Enterprise business logic layer for the OElite platform, providing comprehensive business services, eCommerce functionality, and platform-specific business rules and operations.

Overview

OElite.Services.Platform contains the core business logic layer for the OElite eCommerce and business platform. It implements comprehensive business services for customer management, product operations, pricing, payments, orders, inventory, and platform-specific functionality. Built on top of the OElite.Common.Platform and OElite.Data.Platform layers, it provides enterprise-grade business logic with robust validation, security, and performance optimization.

Features

Customer Management

  • Customer Segmentation: Advanced customer segmentation and targeting capabilities
  • Loyalty Rewards: Comprehensive loyalty and rewards program management
  • Review & Rating System: Customer review and product rating management
  • Wishlist Management: Customer wishlist and favorites functionality
  • Customer Support: Integrated customer support and ticketing system

Product Management

  • Product Operations: Complete product lifecycle management
  • Performance Analytics: Product performance tracking and analytics
  • Pricing Management: Dynamic pricing, discounts, and promotional pricing
  • Inventory Management: Stock tracking, availability, and inventory optimization
  • Category Management: Product categorization and taxonomy management

eCommerce Operations

  • Order Management: Complete order lifecycle from cart to fulfillment
  • Shopping Cart: Persistent cart management with session handling
  • Checkout Process: Secure checkout flow with validation and processing
  • Payment Integration: Multiple payment gateway integration and processing
  • Shipping & Fulfillment: Shipping calculation, tracking, and fulfillment

Business Intelligence

  • Analytics Services: Business metrics, KPIs, and performance analytics
  • Reporting: Automated reporting and business intelligence
  • Data Synchronization: Platform data sync with OElite.Runners.DataSync integration
  • Performance Monitoring: Service performance tracking and optimization

Installation

dotnet add package OElite.Services.Platform

Quick Start

Dependency Injection Registration

using OElite.Services.Platform;
using Microsoft.Extensions.DependencyInjection;

// Register platform services
services.AddOElitePlatformServices(configuration);

// Or register specific service groups
services.AddProductServices();
services.AddCustomerServices();
services.AddOrderServices();
services.AddPaymentServices();

Customer Services

public class CustomerController : ControllerBase
{
    private readonly CustomerSegmentationService _segmentationService;
    private readonly LoyaltyRewardsService _loyaltyService;
    private readonly CustomerSupportService _supportService;

    public CustomerController(
        CustomerSegmentationService segmentationService,
        LoyaltyRewardsService loyaltyService,
        CustomerSupportService supportService)
    {
        _segmentationService = segmentationService;
        _loyaltyService = loyaltyService;
        _supportService = supportService;
    }

    [HttpGet("segments/{customerId}")]
    public async Task<ActionResult<CustomerSegment[]>> GetCustomerSegments(string customerId)
    {
        var segments = await _segmentationService.GetCustomerSegmentsAsync(customerId);
        return Ok(segments);
    }

    [HttpPost("loyalty/points")]
    public async Task<ActionResult> AwardLoyaltyPoints(string customerId, int points, string reason)
    {
        await _loyaltyService.AwardPointsAsync(customerId, points, reason);
        return Ok();
    }

    [HttpPost("support/ticket")]
    public async Task<ActionResult<SupportTicket>> CreateSupportTicket(CreateSupportTicketRequest request)
    {
        var ticket = await _supportService.CreateTicketAsync(request);
        return Ok(ticket);
    }
}

Product Services

public class ProductController : ControllerBase
{
    private readonly ProductService _productService;
    private readonly PriceService _priceService;
    private readonly ProductPerformanceService _performanceService;

    public ProductController(
        ProductService productService,
        PriceService priceService,
        ProductPerformanceService performanceService)
    {
        _productService = productService;
        _priceService = priceService;
        _performanceService = performanceService;
    }

    [HttpGet("{productId}")]
    public async Task<ActionResult<Product>> GetProduct(string productId)
    {
        var product = await _productService.GetProductByIdAsync(productId);
        return product != null ? Ok(product) : NotFound();
    }

    [HttpGet("{productId}/price")]
    public async Task<ActionResult<ProductPrice>> GetProductPrice(string productId, string? customerId = null)
    {
        var price = await _priceService.GetProductPriceAsync(productId, customerId);
        return Ok(price);
    }

    [HttpGet("{productId}/performance")]
    public async Task<ActionResult<ProductPerformanceMetrics>> GetPerformance(string productId)
    {
        var metrics = await _performanceService.GetPerformanceMetricsAsync(productId);
        return Ok(metrics);
    }

    [HttpPost]
    public async Task<ActionResult<Product>> CreateProduct(CreateProductRequest request)
    {
        var product = await _productService.CreateProductAsync(request);
        return CreatedAtAction(nameof(GetProduct), new { productId = product.Id }, product);
    }
}

Core Services

Customer Management Services

Customer Segmentation Service

public class CustomerSegmentationService
{
    public async Task<CustomerSegment[]> GetCustomerSegmentsAsync(string customerId)
    {
        // Analyze customer data and return applicable segments
        var customer = await GetCustomerDataAsync(customerId);
        var segments = await AnalyzeSegmentsAsync(customer);
        return segments;
    }

    public async Task<bool> AssignCustomerToSegmentAsync(string customerId, string segmentId)
    {
        // Manually assign customer to segment with validation
        return await AssignToSegmentAsync(customerId, segmentId);
    }

    public async Task<SegmentAnalytics> GetSegmentAnalyticsAsync(string segmentId)
    {
        // Get performance metrics for customer segment
        return await CalculateSegmentMetricsAsync(segmentId);
    }
}

Loyalty Rewards Service

public class LoyaltyRewardsService
{
    public async Task<int> GetCustomerPointsBalanceAsync(string customerId)
    {
        return await GetPointsBalanceAsync(customerId);
    }

    public async Task<bool> AwardPointsAsync(string customerId, int points, string reason)
    {
        var transaction = new PointsTransaction
        {
            CustomerId = customerId,
            Points = points,
            Type = TransactionType.Award,
            Reason = reason,
            CreatedAt = DateTime.UtcNow
        };

        return await ProcessPointsTransactionAsync(transaction);
    }

    public async Task<bool> RedeemPointsAsync(string customerId, int points, string reason)
    {
        // Validate sufficient balance and process redemption
        var balance = await GetPointsBalanceAsync(customerId);
        if (balance < points)
            throw new InsufficientPointsException(customerId, balance, points);

        var transaction = new PointsTransaction
        {
            CustomerId = customerId,
            Points = -points,
            Type = TransactionType.Redemption,
            Reason = reason,
            CreatedAt = DateTime.UtcNow
        };

        return await ProcessPointsTransactionAsync(transaction);
    }

    public async Task<RewardOption[]> GetAvailableRewardsAsync(string customerId)
    {
        var balance = await GetPointsBalanceAsync(customerId);
        return await GetRewardsForPointsAsync(balance);
    }
}

Customer Support Service

public class CustomerSupportService
{
    public async Task<SupportTicket> CreateTicketAsync(CreateSupportTicketRequest request)
    {
        var ticket = new SupportTicket
        {
            Id = Guid.NewGuid().ToString(),
            CustomerId = request.CustomerId,
            Subject = request.Subject,
            Description = request.Description,
            Priority = DeterminePriority(request),
            Status = TicketStatus.Open,
            CreatedAt = DateTime.UtcNow
        };

        await SaveTicketAsync(ticket);
        await NotifyAgentsAsync(ticket);

        return ticket;
    }

    public async Task<SupportTicket> UpdateTicketStatusAsync(string ticketId, TicketStatus status, string? note = null)
    {
        var ticket = await GetTicketByIdAsync(ticketId);
        ticket.Status = status;
        ticket.UpdatedAt = DateTime.UtcNow;

        if (!string.IsNullOrEmpty(note))
        {
            await AddTicketNoteAsync(ticketId, note);
        }

        await UpdateTicketAsync(ticket);
        return ticket;
    }

    public async Task<SupportTicket[]> GetCustomerTicketsAsync(string customerId)
    {
        return await GetTicketsByCustomerAsync(customerId);
    }
}

Product Management Services

Product Service

public class ProductService
{
    public async Task<Product> CreateProductAsync(CreateProductRequest request)
    {
        var product = new Product
        {
            Id = Guid.NewGuid().ToString(),
            Name = request.Name,
            Description = request.Description,
            CategoryId = request.CategoryId,
            BrandId = request.BrandId,
            SKU = await GenerateSkuAsync(request),
            Status = ProductStatus.Draft,
            CreatedAt = DateTime.UtcNow
        };

        // Validate business rules
        await ValidateProductAsync(product);

        // Save product
        await SaveProductAsync(product);

        // Trigger data sync
        await TriggerDataSyncAsync(product.Id, "Product", "Created");

        return product;
    }

    public async Task<Product> UpdateProductAsync(string productId, UpdateProductRequest request)
    {
        var product = await GetProductByIdAsync(productId);
        if (product == null)
            throw new ProductNotFoundException(productId);

        // Update properties
        product.Name = request.Name ?? product.Name;
        product.Description = request.Description ?? product.Description;
        product.UpdatedAt = DateTime.UtcNow;

        // Validate changes
        await ValidateProductAsync(product);

        // Save changes
        await UpdateProductAsync(product);

        // Trigger data sync
        await TriggerDataSyncAsync(product.Id, "Product", "Updated");

        return product;
    }

    public async Task<bool> SetProductStatusAsync(string productId, ProductStatus status)
    {
        var product = await GetProductByIdAsync(productId);
        if (product == null) return false;

        product.Status = status;
        product.UpdatedAt = DateTime.UtcNow;

        await UpdateProductAsync(product);
        await TriggerDataSyncAsync(product.Id, "Product", "StatusChanged");

        return true;
    }
}

Price Service

public class PriceService
{
    public async Task<ProductPrice> GetProductPriceAsync(string productId, string? customerId = null)
    {
        var basePrice = await GetBasePriceAsync(productId);
        var discounts = await GetApplicableDiscountsAsync(productId, customerId);
        var customerSegment = customerId != null ? await GetCustomerSegmentAsync(customerId) : null;

        var finalPrice = CalculateFinalPrice(basePrice, discounts, customerSegment);

        return new ProductPrice
        {
            ProductId = productId,
            BasePrice = basePrice.Amount,
            Discounts = discounts,
            FinalPrice = finalPrice,
            Currency = basePrice.Currency,
            CustomerId = customerId
        };
    }

    public async Task<bool> SetProductPriceAsync(string productId, decimal price, string currency = "USD")
    {
        var priceEntity = new ProductPricing
        {
            ProductId = productId,
            BasePrice = price,
            Currency = currency,
            EffectiveFrom = DateTime.UtcNow,
            IsActive = true
        };

        await SavePricingAsync(priceEntity);
        await TriggerDataSyncAsync(productId, "ProductPricing", "Updated");

        return true;
    }

    public async Task<Discount> CreateDiscountAsync(CreateDiscountRequest request)
    {
        var discount = new Discount
        {
            Id = Guid.NewGuid().ToString(),
            Name = request.Name,
            Type = request.Type,
            Value = request.Value,
            ProductIds = request.ProductIds,
            CustomerSegments = request.CustomerSegments,
            StartDate = request.StartDate,
            EndDate = request.EndDate,
            IsActive = true
        };

        await SaveDiscountAsync(discount);
        return discount;
    }
}

eCommerce Operations

Order Service

public class OrderService
{
    public async Task<Order> CreateOrderAsync(CreateOrderRequest request)
    {
        var order = new Order
        {
            Id = Guid.NewGuid().ToString(),
            CustomerId = request.CustomerId,
            Items = request.Items,
            Status = OrderStatus.Pending,
            CreatedAt = DateTime.UtcNow
        };

        // Calculate totals
        await CalculateOrderTotalsAsync(order);

        // Validate inventory
        await ValidateInventoryAsync(order.Items);

        // Reserve inventory
        await ReserveInventoryAsync(order.Items);

        // Save order
        await SaveOrderAsync(order);

        // Trigger workflows
        await TriggerOrderCreatedWorkflowAsync(order);

        return order;
    }

    public async Task<bool> UpdateOrderStatusAsync(string orderId, OrderStatus status)
    {
        var order = await GetOrderByIdAsync(orderId);
        if (order == null) return false;

        var previousStatus = order.Status;
        order.Status = status;
        order.UpdatedAt = DateTime.UtcNow;

        await UpdateOrderAsync(order);

        // Trigger status change workflows
        await TriggerOrderStatusChangedWorkflowAsync(order, previousStatus);

        return true;
    }

    public async Task<Order[]> GetCustomerOrdersAsync(string customerId, int pageIndex = 0, int pageSize = 20)
    {
        return await GetOrdersByCustomerAsync(customerId, pageIndex, pageSize);
    }
}

Payment Service

public class PaymentService
{
    public async Task<PaymentResult> ProcessPaymentAsync(ProcessPaymentRequest request)
    {
        // Validate payment details
        await ValidatePaymentRequestAsync(request);

        // Get payment gateway
        var gateway = GetPaymentGateway(request.PaymentMethod);

        // Process payment
        var result = await gateway.ProcessPaymentAsync(new GatewayPaymentRequest
        {
            Amount = request.Amount,
            Currency = request.Currency,
            PaymentToken = request.PaymentToken,
            OrderId = request.OrderId
        });

        // Save payment record
        await SavePaymentRecordAsync(request, result);

        // Update order if successful
        if (result.IsSuccessful)
        {
            await UpdateOrderPaymentStatusAsync(request.OrderId, PaymentStatus.Paid);
        }

        return result;
    }

    public async Task<RefundResult> ProcessRefundAsync(ProcessRefundRequest request)
    {
        var payment = await GetPaymentByIdAsync(request.PaymentId);
        if (payment == null)
            throw new PaymentNotFoundException(request.PaymentId);

        var gateway = GetPaymentGateway(payment.PaymentMethod);
        var result = await gateway.ProcessRefundAsync(new GatewayRefundRequest
        {
            OriginalTransactionId = payment.GatewayTransactionId,
            Amount = request.Amount,
            Reason = request.Reason
        });

        await SaveRefundRecordAsync(request, result);

        return result;
    }
}

Data Synchronization Integration

The platform services integrate seamlessly with OElite.Runners.DataSync for maintaining data consistency:

public abstract class BasePlatformService
{
    protected async Task TriggerDataSyncAsync(string entityId, string entityType, string operation)
    {
        var syncMessage = new DataSyncMessage
        {
            EntityId = entityId,
            EntityType = entityType,
            Operation = operation,
            Timestamp = DateTime.UtcNow,
            Source = "Platform.Services"
        };

        await _messagingService.PublishAsync("data.sync.trigger", syncMessage);
    }
}

// Example usage in services
public class ProductService : BasePlatformService
{
    public async Task<Product> UpdateProductAsync(string productId, UpdateProductRequest request)
    {
        // ... business logic ...

        // Trigger denormalized field updates across platform
        await TriggerDataSyncAsync(productId, "Product", "Updated");

        return product;
    }
}

Mock Payment Gateway

For development and testing, the package includes a mock payment gateway:

public class MockPaymentGateway : IPaymentGateway
{
    public async Task<PaymentResult> ProcessPaymentAsync(GatewayPaymentRequest request)
    {
        // Simulate payment processing delay
        await Task.Delay(TimeSpan.FromSeconds(1));

        // Mock successful payment for amounts under $1000
        var isSuccessful = request.Amount < 1000;

        return new PaymentResult
        {
            IsSuccessful = isSuccessful,
            TransactionId = Guid.NewGuid().ToString(),
            GatewayResponse = isSuccessful ? "APPROVED" : "DECLINED",
            ProcessedAt = DateTime.UtcNow
        };
    }
}

// Register in DI
services.AddSingleton<IPaymentGateway, MockPaymentGateway>();

Integration with OElite Platform

With OElite.Common.Platform

// Services automatically use shared entities and DTOs
public async Task<Product> GetProductAsync(string productId)
{
    return await _productRepository.GetByIdAsync(productId);
}

With OElite.Data.Platform

// Services use platform-specific repositories
public class ProductService
{
    private readonly IProductRepository _productRepository;
    private readonly ICategoryRepository _categoryRepository;

    public ProductService(IProductRepository productRepository, ICategoryRepository categoryRepository)
    {
        _productRepository = productRepository;
        _categoryRepository = categoryRepository;
    }
}

Configuration

Services can be configured through dependency injection:

services.Configure<PlatformServicesOptions>(options =>
{
    options.EnableDataSync = true;
    options.CacheExpirationMinutes = 15;
    options.MaxRetryAttempts = 3;
});

services.Configure<PaymentOptions>(options =>
{
    options.DefaultCurrency = "USD";
    options.PaymentTimeoutMinutes = 15;
    options.EnableMockGateway = environment.IsDevelopment();
});

Requirements

  • .NET 10.0+
  • OElite.Common.Platform (domain entities and DTOs)
  • OElite.Data.Platform (data access layer)
  • OElite.Services (base service abstractions)
  • OElite.Restme packages (S3, Redis, RabbitMQ)
  • Microsoft.AspNetCore.Identity 2.3.1+
  • Microsoft.AspNetCore.SignalR.Core 1.1.0+

Performance Features

  • Caching Integration: Automatic caching of frequently accessed data
  • Async Operations: Full async/await pattern throughout
  • Data Sync Integration: Automated denormalized field updates
  • Connection Pooling: Efficient database connection management
  • Memory Optimization: Careful object lifecycle management

Thread Safety

All services are designed for thread-safe operations and can be registered as singletons in dependency injection containers.

License

Copyright © OElite Limited. All rights reserved.

No packages depend on OElite.Services.Platform.

Version Downloads Last updated
5.0.9-develop.511 3 11/26/2025
5.0.9-develop.510 2 11/26/2025
5.0.9-develop.509 2 11/23/2025
5.0.9-develop.480 2 11/17/2025
5.0.9-develop.478 2 11/17/2025
5.0.9-develop.477 2 11/17/2025
5.0.9-develop.476 2 11/17/2025
5.0.9-develop.472 2 11/15/2025
5.0.9-develop.471 2 11/15/2025
5.0.9-develop.470 2 11/15/2025
5.0.9-develop.462 2 11/14/2025
5.0.9-develop.448 2 11/11/2025
5.0.9-develop.446 2 11/11/2025
5.0.9-develop.443 2 11/11/2025
5.0.9-develop.441 2 11/09/2025
5.0.9-develop.415 3 10/28/2025
5.0.9-develop.412 3 10/27/2025
5.0.9-develop.411 3 10/27/2025
5.0.9-develop.410 3 10/27/2025
5.0.9-develop.409 3 10/27/2025
5.0.9-develop.402 3 10/26/2025
5.0.9-develop.399 3 10/26/2025
5.0.9-develop.394 3 10/25/2025
5.0.9-develop.391 3 10/25/2025
5.0.9-develop.389 3 10/25/2025
5.0.9-develop.376 3 10/25/2025
5.0.9-develop.374 3 10/24/2025
5.0.9-develop.373 3 10/24/2025
5.0.9-develop.372 3 10/24/2025
5.0.9-develop.259 4 10/20/2025
5.0.9-develop.258 4 10/20/2025
5.0.9-develop.244 4 10/19/2025
5.0.9-develop.240 4 10/18/2025
5.0.9-develop.239 4 10/18/2025
5.0.9-develop.238 4 10/18/2025
5.0.9-develop.236 4 10/18/2025
5.0.9-develop.235 4 10/18/2025
5.0.9-develop.234 4 10/17/2025
5.0.9-develop.227 4 10/17/2025
5.0.9-develop.226 4 10/17/2025
5.0.9-develop.225 4 10/17/2025
5.0.9-develop.224 4 10/16/2025
5.0.9-develop.222 4 10/16/2025
5.0.9-develop.216 4 10/16/2025
5.0.9-develop.215 4 10/16/2025
5.0.9-develop.212 4 10/15/2025
5.0.9-develop.211 4 10/14/2025
5.0.9-develop.210 4 10/14/2025