2019-05-27 03:46:21 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Cicm.Database.Models;
|
2019-05-27 15:44:27 +01:00
|
|
|
using cicm_web.Areas.Admin.Models;
|
2019-05-27 03:46:21 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-05-27 19:38:17 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2019-05-27 03:46:21 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace cicm_web.Areas.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Area("Admin")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class MachinePhotosController : Controller
|
|
|
|
|
{
|
|
|
|
|
readonly cicmContext _context;
|
|
|
|
|
|
|
|
|
|
public MachinePhotosController(cicmContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: MachinePhotos
|
|
|
|
|
public async Task<IActionResult> Index()
|
|
|
|
|
{
|
|
|
|
|
return View(await _context.MachinePhotos.Include(m => m.Machine).Include(m => m.Machine.Company)
|
2019-05-27 15:44:27 +01:00
|
|
|
.Include(m => m.User).Select(p => new MachinePhotoViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = p.Id,
|
|
|
|
|
Author = p.Author,
|
2019-05-27 19:38:17 +01:00
|
|
|
License = p.License.Name,
|
2019-05-27 15:44:27 +01:00
|
|
|
Machine =
|
|
|
|
|
$"{p.Machine.Company.Name} {p.Machine.Name}",
|
|
|
|
|
UploadDate = p.UploadDate,
|
2019-05-27 19:38:17 +01:00
|
|
|
UploadUser = p.User.UserName,
|
|
|
|
|
LicenseId = p.License.Id
|
2019-05-27 15:44:27 +01:00
|
|
|
}).OrderBy(p => p.Machine)
|
|
|
|
|
.ThenBy(p => p.UploadUser).ThenBy(p => p.UploadDate).ToListAsync());
|
2019-05-27 03:46:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: MachinePhotos/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(Guid? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
MachinePhoto machinePhoto = await _context.MachinePhotos.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(machinePhoto == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(machinePhoto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: MachinePhotos/Create
|
2019-05-27 19:38:17 +01:00
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
ViewData["MachineId"] =
|
|
|
|
|
new
|
|
|
|
|
SelectList(_context.Machines.OrderBy(c => c.Company.Name).ThenBy(c => c.Name).Select(m => new {m.Id, Name = $"{m.Company.Name} {m.Name}"}),
|
|
|
|
|
"Id", "Name");
|
|
|
|
|
ViewData["LicenseId"] =
|
|
|
|
|
new SelectList(_context.Licenses.OrderBy(c => c.Name).Select(l => new {l.Id, l.Name}), "Id", "Name");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2019-05-27 03:46:21 +01:00
|
|
|
|
|
|
|
|
// POST: MachinePhotos/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.
|
2019-05-27 19:38:17 +01:00
|
|
|
// [HttpPost]
|
|
|
|
|
// [ValidateAntiForgeryToken]
|
|
|
|
|
// public async Task<IActionResult> Create(
|
|
|
|
|
// [Bind(
|
|
|
|
|
// "Author,CameraManufacturer,CameraModel,ColorSpace,Comments,Contrast,CreationDate,DigitalZoomRatio,ExifVersion,Exposure,ExposureMethod,ExposureProgram,Flash,Focal,FocalLength,FocalLengthEquivalent,HorizontalResolution,IsoRating,Lens,License,LightSource,MeteringMode,Orientation,PixelComposition,Saturation,SceneCaptureType,SceneControl,SensingMethod,Sharpness,SoftwareUsed,SubjectDistanceRange,UploadDate,VerticalResolution,WhiteBalance,Id")]
|
|
|
|
|
// MachinePhoto machinePhoto)
|
|
|
|
|
// {
|
|
|
|
|
// if(ModelState.IsValid)
|
|
|
|
|
// {
|
|
|
|
|
// machinePhoto.Id = Guid.NewGuid();
|
|
|
|
|
// _context.Add(machinePhoto);
|
|
|
|
|
// await _context.SaveChangesAsync();
|
|
|
|
|
// return RedirectToAction(nameof(Index));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return View(machinePhoto);
|
|
|
|
|
// }
|
2019-05-27 03:46:21 +01:00
|
|
|
|
|
|
|
|
// GET: MachinePhotos/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(Guid? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
MachinePhoto machinePhoto = await _context.MachinePhotos.FindAsync(id);
|
|
|
|
|
if(machinePhoto == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(machinePhoto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: MachinePhotos/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(Guid id, [Bind(
|
|
|
|
|
"Author,CameraManufacturer,CameraModel,ColorSpace,Comments,Contrast,CreationDate,DigitalZoomRatio,ExifVersion,Exposure,ExposureMethod,ExposureProgram,Flash,Focal,FocalLength,FocalLengthEquivalent,HorizontalResolution,IsoRating,Lens,License,LightSource,MeteringMode,Orientation,PixelComposition,Saturation,SceneCaptureType,SceneControl,SensingMethod,Sharpness,SoftwareUsed,SubjectDistanceRange,UploadDate,VerticalResolution,WhiteBalance,Id")]
|
|
|
|
|
MachinePhoto machinePhoto)
|
|
|
|
|
{
|
|
|
|
|
if(id != machinePhoto.Id) return NotFound();
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(machinePhoto);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
{
|
|
|
|
|
if(!MachinePhotoExists(machinePhoto.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(machinePhoto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: MachinePhotos/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(Guid? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
MachinePhoto machinePhoto = await _context.MachinePhotos.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(machinePhoto == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(machinePhoto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: MachinePhotos/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(Guid id)
|
|
|
|
|
{
|
|
|
|
|
MachinePhoto machinePhoto = await _context.MachinePhotos.FindAsync(id);
|
|
|
|
|
_context.MachinePhotos.Remove(machinePhoto);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MachinePhotoExists(Guid id)
|
|
|
|
|
{
|
|
|
|
|
return _context.MachinePhotos.Any(e => e.Id == id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|