2019-06-30 01:26:03 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Cicm.Database.Models;
|
2019-06-30 11:49:19 +01:00
|
|
|
using cicm_web.Areas.Admin.Models;
|
2019-06-30 01:26:03 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-06-30 01:57:21 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2019-06-30 01:26:03 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace cicm_web.Areas.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Area("Admin")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DocumentCompaniesController : Controller
|
|
|
|
|
{
|
|
|
|
|
readonly cicmContext _context;
|
|
|
|
|
|
|
|
|
|
public DocumentCompaniesController(cicmContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: DocumentCompanies
|
2019-06-30 01:41:42 +01:00
|
|
|
public async Task<IActionResult> Index()
|
|
|
|
|
{
|
2019-06-30 11:49:19 +01:00
|
|
|
return View(await _context.DocumentCompanies
|
|
|
|
|
.Select(d => new DocumentCompanyViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = d.Id,
|
|
|
|
|
Name = d.Name,
|
|
|
|
|
Company = d.Company.Name,
|
|
|
|
|
CompanyId = d.CompanyId
|
|
|
|
|
}).ToListAsync());
|
2019-06-30 01:41:42 +01:00
|
|
|
}
|
2019-06-30 01:26:03 +01:00
|
|
|
|
|
|
|
|
// GET: DocumentCompanies/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
2019-06-30 11:49:19 +01:00
|
|
|
DocumentCompanyViewModel documentCompany =
|
|
|
|
|
await _context.DocumentCompanies
|
|
|
|
|
.Select(d => new DocumentCompanyViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = d.Id,
|
|
|
|
|
Name = d.Name,
|
|
|
|
|
Company = d.Company.Name,
|
|
|
|
|
CompanyId = d.CompanyId
|
|
|
|
|
}).FirstOrDefaultAsync(m => m.Id == id);
|
2019-06-30 01:26:03 +01:00
|
|
|
if(documentCompany == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(documentCompany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: DocumentCompanies/Create
|
2019-06-30 01:57:21 +01:00
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
ViewData["CompanyId"] =
|
|
|
|
|
new SelectList(_context.Companies.OrderBy(c => c.Name).Select(c => new {c.Id, c.Name}), "Id", "Name");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2019-06-30 01:26:03 +01:00
|
|
|
|
|
|
|
|
// POST: DocumentCompanies/Create
|
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> Create([Bind("Name,CompanyId,Id")] DocumentCompany documentCompany)
|
|
|
|
|
{
|
2019-06-30 01:57:21 +01:00
|
|
|
if(!ModelState.IsValid) return View(documentCompany);
|
2019-06-30 01:26:03 +01:00
|
|
|
|
2019-06-30 01:57:21 +01:00
|
|
|
_context.Add(documentCompany);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
2019-06-30 01:26:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: DocumentCompanies/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FindAsync(id);
|
2019-06-30 12:22:49 +01:00
|
|
|
|
2019-06-30 01:26:03 +01:00
|
|
|
if(documentCompany == null) return NotFound();
|
|
|
|
|
|
2019-06-30 12:29:20 +01:00
|
|
|
ViewData["CompanyId"] =
|
|
|
|
|
new SelectList(_context.Companies.OrderBy(c => c.Name).Select(c => new {c.Id, c.Name}), "Id", "Name",
|
|
|
|
|
documentCompany.CompanyId);
|
2019-06-30 12:22:49 +01:00
|
|
|
|
2019-06-30 01:26:03 +01:00
|
|
|
return View(documentCompany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: DocumentCompanies/Edit/5
|
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> Edit(int id, [Bind("Name,CompanyId,Id")] DocumentCompany documentCompany)
|
|
|
|
|
{
|
|
|
|
|
if(id != documentCompany.Id) return NotFound();
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(documentCompany);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
{
|
|
|
|
|
if(!DocumentCompanyExists(documentCompany.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-30 12:29:20 +01:00
|
|
|
ViewData["CompanyId"] =
|
|
|
|
|
new SelectList(_context.Companies.OrderBy(c => c.Name).Select(c => new {c.Id, c.Name}), "Id", "Name",
|
|
|
|
|
documentCompany.CompanyId);
|
2019-06-30 12:22:49 +01:00
|
|
|
|
2019-06-30 01:26:03 +01:00
|
|
|
return View(documentCompany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: DocumentCompanies/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
2019-06-30 12:29:20 +01:00
|
|
|
DocumentCompanyViewModel documentCompany =
|
|
|
|
|
await _context.DocumentCompanies
|
|
|
|
|
.Select(d => new DocumentCompanyViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = d.Id,
|
|
|
|
|
Name = d.Name,
|
|
|
|
|
Company = d.Company.Name,
|
|
|
|
|
CompanyId = d.CompanyId
|
|
|
|
|
}).FirstOrDefaultAsync(m => m.Id == id);
|
2019-06-30 01:26:03 +01:00
|
|
|
if(documentCompany == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(documentCompany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: DocumentCompanies/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
|
|
|
|
DocumentCompany documentCompany = await _context.DocumentCompanies.FindAsync(id);
|
|
|
|
|
_context.DocumentCompanies.Remove(documentCompany);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DocumentCompanyExists(int id)
|
|
|
|
|
{
|
|
|
|
|
return _context.DocumentCompanies.Any(e => e.Id == id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|