mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Implement create page for document companies.
This commit is contained in:
@@ -4,6 +4,7 @@ using Cicm.Database.Models;
|
||||
using cicm_web.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace cicm_web.Areas.Admin.Controllers
|
||||
@@ -38,7 +39,12 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
}
|
||||
|
||||
// GET: DocumentCompanies/Create
|
||||
public IActionResult Create() => View();
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewData["CompanyId"] =
|
||||
new SelectList(_context.Companies.OrderBy(c => c.Name).Select(c => new {c.Id, c.Name}), "Id", "Name");
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: DocumentCompanies/Create
|
||||
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
||||
@@ -47,16 +53,13 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Create([Bind("Name,CompanyId,Id")] DocumentCompany documentCompany)
|
||||
{
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
if(!ModelState.IsValid) return View(documentCompany);
|
||||
|
||||
_context.Add(documentCompany);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
return View(documentCompany);
|
||||
}
|
||||
|
||||
// GET: DocumentCompanies/Edit/5
|
||||
public async Task<IActionResult> Edit(int? id)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<h1>Create</h1>
|
||||
|
||||
<h4>DocumentCompany</h4>
|
||||
<h4>Document company</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
@@ -25,24 +25,27 @@
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="CompanyId"
|
||||
<label asp-for="Company"
|
||||
class="control-label">
|
||||
</label>
|
||||
<input asp-for="CompanyId"
|
||||
class="form-control" />
|
||||
<span asp-validation-for="CompanyId"
|
||||
class="text-danger">
|
||||
</span>
|
||||
<select asp-for="CompanyId"
|
||||
class="form-control"
|
||||
asp-items="ViewBag.CompanyId">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="btn btn-primary"
|
||||
type="submit"
|
||||
value="Create" />
|
||||
<a asp-action="Index"
|
||||
class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</div>
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.842</Version>
|
||||
<Version>3.0.99.845</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user