User settings

This commit is contained in:
Paul Schneider
2025-02-24 23:29:48 +00:00
parent 7524e6323f
commit 76626f3ac4
16 changed files with 76 additions and 67 deletions

View File

@ -59,7 +59,7 @@ namespace Yavsc.Controllers
return NotFound();
}
bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
var settings = await billing.GetPerformerSettingsAsync(activityCode,id);
var settings = await billing.GetPerformersSettingsAsync(activityCode, id);
ViewBag.ProfileType = Config.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName);
var gift = new UserActivityViewModel {

View File

@ -9,6 +9,7 @@ namespace Yavsc.Controllers
public FormationSettingsController(ApplicationDbContext context) : base(context)
{
}
}

View File

@ -53,26 +53,26 @@ namespace Yavsc.Controllers
}
[AllowAnonymous]
public ActionResult Profiles(string id)
public async Task<ActionResult> Profiles(string id)
{
if (id == null)
{
throw new NotImplementedException("No Activity code");
}
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(_billing, id);
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
var result = await _context.ListPerformersAsync(_billing, id);
return View(result);
}
[AllowAnonymous]
public ActionResult HairCut(string id)
public async Task <ActionResult> HairCut(string id)
{
if (id == null)
{
throw new NotImplementedException("No Activity code");
}
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(_billing, id);
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
var result = await _context.ListPerformersAsync(_billing, id);
return View(result);
}

View File

@ -10,7 +10,7 @@ namespace Yavsc.Controllers.Generic
using Yavsc.Services;
[Authorize]
public abstract class SettingsController<TSettings> : Controller where TSettings : class, ISpecializationSettings, new()
public abstract class SettingsController<TSettings> : Controller where TSettings : class, IUserSettings, new()
{
protected ApplicationDbContext _context;
DbSet<TSettings> dbSet=null;
@ -21,11 +21,17 @@ namespace Yavsc.Controllers.Generic
if (dbSet == null) {
dbSet = (DbSet<TSettings>) BillingService.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context);
}
return dbSet;
} }
virtual protected async Task<TSettings> GetSettingsAsync(
string userId
)
{
return await Settings.SingleOrDefaultAsync(p=>p.UserId == userId);
}
public SettingsController(ApplicationDbContext context)
{
_context = context;
@ -33,8 +39,7 @@ namespace Yavsc.Controllers.Generic
public async Task<IActionResult> Index()
{
var existing = await this.Settings.SingleOrDefaultAsync(p=>p.UserId == User.GetUserId());
return View(existing);
return View(await GetSettingsAsync(User.GetUserId()));
}
// GET: BrusherProfile/Details/5
public async Task<IActionResult> Details(string id)
@ -44,7 +49,7 @@ namespace Yavsc.Controllers.Generic
id = User.GetUserId();
}
var profile = await Settings.SingleAsync(m => m.UserId == id);
var profile = await GetSettingsAsync(id);
if (profile == null)
{
return NotFound();
@ -68,7 +73,7 @@ namespace Yavsc.Controllers.Generic
id = User.GetUserId();
}
TSettings setting = await Settings.SingleOrDefaultAsync(m => m.UserId == id);
TSettings setting = await GetSettingsAsync(id);
if (setting == null)
{
setting = new TSettings { };
@ -87,13 +92,13 @@ namespace Yavsc.Controllers.Generic
return NotFound();
}
var brusherProfile = await Settings.SingleAsync(m => m.UserId == id);
if (brusherProfile == null)
var profile = await GetSettingsAsync(id);
if (profile == null)
{
return NotFound();
}
return View(brusherProfile);
return View(profile);
}
// POST: FormationSettings/Create
@ -135,8 +140,8 @@ namespace Yavsc.Controllers.Generic
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
TSettings formationSettings = await Settings.SingleAsync(m => m.UserId == id);
Settings.Remove(formationSettings);
TSettings userSettings = await GetSettingsAsync(id);
Settings.Remove(userSettings);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}