From 5d03419a794a6dc97340d1d68495cd855c658849 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 22 Feb 2023 07:56:30 +0300 Subject: [PATCH] Base figure edition --- Controllers/FigureController.cs | 58 +++++++++++++++++++++++++++++++++ Views/Bundle/Details.cshtml | 24 +++++++++++--- Views/Figure/Details.cshtml | 33 +++++++++++++++++++ 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 Controllers/FigureController.cs create mode 100644 Views/Figure/Details.cshtml 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 Details(int id) + { + return View(await context.Figures.Where(f => f.Id == id).FirstOrDefaultAsync()); + } + + [HttpPost] + public async Task 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, + "", + 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 diff --git a/Views/Bundle/Details.cshtml b/Views/Bundle/Details.cshtml index edaec11..b7df95b 100644 --- a/Views/Bundle/Details.cshtml +++ b/Views/Bundle/Details.cshtml @@ -11,22 +11,38 @@ -
+
- - @Html.TextAreaFor(model => model.Description, new { @class="form-control", @rows = 4 }) + + @Html.TextAreaFor(model => model.Description, new { @class="form-control", @rows = 2 }) +
+
+ +
+ @foreach (var figure in @Model.Figures) + { +
+
+ + @figure.Description + +
+
+ } +
- +
diff --git a/Views/Figure/Details.cshtml b/Views/Figure/Details.cshtml new file mode 100644 index 0000000..2148ed3 --- /dev/null +++ b/Views/Figure/Details.cshtml @@ -0,0 +1,33 @@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@model MyDarling.Models.Figure + + + + + + Figure + + + + +
+
+
+ + @Model.Description + +
+
+
+
+
+
+ + @Html.TextAreaFor(model => model.Description, new { @class="form-control", @rows = 2 }) +
+ +
+ + + +