yavsc/src/Yavsc.Org/Controllers/Contracting/GeneralSettingsController.cs

119 lines
3.5 KiB
C#
Raw Normal View History

2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
2018-05-04 13:56:22 +02:00
using Yavsc.Models;
using Yavsc.Models.Musical.Profiles;
namespace Yavsc.Controllers
{
public class GeneralSettingsController : Controller
{
2020-10-09 19:35:39 +01:00
private readonly ApplicationDbContext _context;
2018-05-04 13:56:22 +02:00
public GeneralSettingsController(ApplicationDbContext context)
{
2026-06-30 23:32:05 +01:00
_context = context;
2018-05-04 13:56:22 +02:00
}
// GET: GeneralSettings
public async Task<IActionResult> Index()
{
return View(await _context.GeneralSettings.ToListAsync());
}
// GET: GeneralSettings/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
2026-06-30 23:32:05 +01:00
MusicLoverSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id);
2018-05-04 13:56:22 +02:00
if (generalSettings == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(generalSettings);
}
// GET: GeneralSettings/Create
public IActionResult Create()
{
return View();
}
// POST: GeneralSettings/Create
[HttpPost]
[ValidateAntiForgeryToken]
2026-06-30 23:32:05 +01:00
public async Task<IActionResult> Create(MusicLoverSettings generalSettings)
2018-05-04 13:56:22 +02:00
{
if (ModelState.IsValid)
{
_context.GeneralSettings.Add(generalSettings);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(generalSettings);
}
// GET: GeneralSettings/Edit/5
public async Task<IActionResult> Edit(string id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
2026-06-30 23:32:05 +01:00
MusicLoverSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id);
2018-05-04 13:56:22 +02:00
if (generalSettings == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(generalSettings);
}
// POST: GeneralSettings/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
2026-06-30 23:32:05 +01:00
public async Task<IActionResult> Edit(MusicLoverSettings generalSettings)
2018-05-04 13:56:22 +02:00
{
if (ModelState.IsValid)
{
_context.Update(generalSettings);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(generalSettings);
}
// GET: GeneralSettings/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
2026-06-30 23:32:05 +01:00
MusicLoverSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id);
2018-05-04 13:56:22 +02:00
if (generalSettings == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(generalSettings);
}
// POST: GeneralSettings/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
2026-06-30 23:32:05 +01:00
MusicLoverSettings generalSettings = await _context.GeneralSettings.SingleAsync(m => m.UserId == id);
2018-05-04 13:56:22 +02:00
_context.GeneralSettings.Remove(generalSettings);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}