summaryrefslogtreecommitdiff
path: root/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'Controllers')
-rw-r--r--Controllers/FigureController.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Controllers/FigureController.cs b/Controllers/FigureController.cs
new file mode 100644
index 0000000..5785f86
--- /dev/null
+++ b/Controllers/FigureController.cs
@@ -0,0 +1,58 @@
+using System.Data;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using MyDarling.Models;
+
+namespace MyDarling.Controllers
+{
+ public class FigureController : Controller
+ {
+ private DataContext context;
+ public FigureController(DataContext context)
+ {
+ this.context = context;
+ }
+
+ public async Task<IActionResult> Details(int id)
+ {
+ return View(await context.Figures.Where(f => f.Id == id).FirstOrDefaultAsync());
+ }
+
+ [HttpPost]
+ public async Task<IActionResult> Edit(int? id)
+ {
+ if (id == null)
+ {
+ return NotFound();
+ }
+
+ var figure = await context.Figures.FindAsync(id);
+
+ if (figure == null)
+ {
+ return NotFound();
+ }
+
+ var bundle = await context.UnderwearBundles
+ .Where(b => b.Figures.Contains(figure))
+ .FirstOrDefaultAsync();
+
+ if (await TryUpdateModelAsync<Figure>(
+ figure,
+ "",
+ f => f.Description))
+ {
+ try
+ {
+ await context.SaveChangesAsync();
+ return RedirectToAction("Details", "Bundle", new { Id = bundle?.Id});
+ }
+ catch (SystemException)
+ {
+ ModelState.AddModelError("", "Unable to save changes");
+ }
+ }
+ return View(figure);
+ }
+ }
+} \ No newline at end of file