Добавил контроллер Supplier

parent 0b0a0b8b
using Microsoft.AspNetCore.Mvc;
using Store.Models;
namespace Store.Controllers
{
public class SupplierController : Controller
{
private ProductContext _context;
public SupplierController(ProductContext context)
{
_context = context;
}
[HttpGet]
public IActionResult Create()
{
return View(new Supplier());
}
[HttpPost]
public IActionResult Create(Supplier supplier)
{
_context.Suppliers.Add(supplier);
_context.SaveChanges();
return View(supplier);
}
}
}
...@@ -59,7 +59,7 @@ namespace Store ...@@ -59,7 +59,7 @@ namespace Store
name: "default", template: "{controller=Product}/{action=Index}"); name: "default", template: "{controller=Product}/{action=Index}");
routes.MapRoute( routes.MapRoute(
name: "details", template: "{controller=Product}/{action=Details}/{id}"); name: "details", template: "{controller=Product}/{action=Details}");
}); });
} }
} }
......
...@@ -27,10 +27,8 @@ ...@@ -27,10 +27,8 @@
<td>@product.Category</td> <td>@product.Category</td>
<td>@product.Amount</td> <td>@product.Amount</td>
<td>@product.Brand</td> <td>@product.Brand</td>
<td><a href="/Product/Details/@product.Id" class="btn btn-sm btn-link">Show</a></td> <td><a href="/Product/Details?id=@product.Id" class="btn btn-sm btn-link">Show</a></td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
<li> <li>
<a href="/Product/Create">Create</a> <a href="/Product/Create">Create</a>
</li> </li>
<li>
<a asp-controller="Supplier" asp-action="Create">Create supplier</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
......
@model Store.Models.Supplier
@{
Layout = "_MainLayout";
}
<h2>Create supplier:</h2>
<hr/>
<form asp-controller="Supplier" asp-action="Create" method="post">
<input asp-for="Name"/>
<input type="submit" value="Save"/>
</form>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment