Spaces:
Sleeping
Sleeping
File size: 1,715 Bytes
b0a0ed0 6f32ae8 b0a0ed0 25f925e b0a0ed0 7fe61c9 b0a0ed0 7fe61c9 b0a0ed0 25f925e b0a0ed0 25f925e b0a0ed0 6f32ae8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | using Microsoft.AspNetCore.Mvc;
using Frontend.Services;
using LibraryManagement.Shared.Models;
using Frontend.Models;
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
using System.Linq;
namespace Frontend.Controllers
{
[Authorize(Roles = "Admin,Librarian")]
public class SubscriptionsController : Controller
{
private readonly LibraryApiClient _apiClient;
public SubscriptionsController(LibraryApiClient apiClient)
{
_apiClient = apiClient;
}
public async Task<IActionResult> Index()
{
var memberships = await _apiClient.GetMembershipsAsync();
var activeSubscriptions = await _apiClient.GetAllSubscriptionsAsync();
var viewModel = new SubscriptionsViewModel
{
AvailableMemberships = memberships?.ToList() ?? new List<MembershipDto>(),
ActiveSubscriptions = activeSubscriptions?.ToList() ?? new List<SubscriptionDto>()
};
return View(viewModel);
}
public async Task<IActionResult> Rewards()
{
var pendingClaims = await _apiClient.GetPendingRedemptionsAsync();
return View("LoyaltyClaims", pendingClaims.ToList());
}
[HttpPost]
public async Task<IActionResult> FulfillRedemption(string id)
{
var (success, message) = await _apiClient.FulfillRedemptionAsync(id);
if (success)
{
TempData["Success"] = message;
}
else
{
TempData["Error"] = message;
}
return RedirectToAction("Rewards");
}
}
}
|