diff --git a/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs b/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs index 697ca27e..9e3a5e0e 100644 --- a/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs +++ b/cicm_web/Areas/Admin/Controllers/MachinePhotosController.cs @@ -5,6 +5,7 @@ using Cicm.Database.Models; using cicm_web.Areas.Admin.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; namespace cicm_web.Areas.Admin.Controllers @@ -28,11 +29,12 @@ namespace cicm_web.Areas.Admin.Controllers { Id = p.Id, Author = p.Author, - License = p.License, + License = p.License.Name, Machine = $"{p.Machine.Company.Name} {p.Machine.Name}", UploadDate = p.UploadDate, - UploadUser = p.User.UserName + UploadUser = p.User.UserName, + LicenseId = p.License.Id }).OrderBy(p => p.Machine) .ThenBy(p => p.UploadUser).ThenBy(p => p.UploadDate).ToListAsync()); } @@ -49,28 +51,37 @@ namespace cicm_web.Areas.Admin.Controllers } // GET: MachinePhotos/Create - public IActionResult Create() => View(); + 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(); + } // 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. - [HttpPost] - [ValidateAntiForgeryToken] - public async Task 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); - } + // [HttpPost] + // [ValidateAntiForgeryToken] + // public async Task 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); + // } // GET: MachinePhotos/Edit/5 public async Task Edit(Guid? id) diff --git a/cicm_web/Areas/Admin/Models/MachinePhotoViewModel.cs b/cicm_web/Areas/Admin/Models/MachinePhotoViewModel.cs index 63b4aeab..3a1c10f9 100644 --- a/cicm_web/Areas/Admin/Models/MachinePhotoViewModel.cs +++ b/cicm_web/Areas/Admin/Models/MachinePhotoViewModel.cs @@ -1,5 +1,8 @@ using System; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.AspNetCore.Http; namespace cicm_web.Areas.Admin.Models { @@ -12,5 +15,11 @@ namespace cicm_web.Areas.Admin.Models public DateTime UploadDate { get; set; } [DisplayName("Uploaded by")] public string UploadUser { get; set; } + [NotMapped] + [Required(ErrorMessage = "Image file required")] + [DisplayName("Upload photo:")] + public IFormFile Photo { get; set; } + public int MachineId { get; set; } + public int LicenseId { get; set; } } } \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MachinePhotos/Create.cshtml b/cicm_web/Areas/Admin/Views/MachinePhotos/Create.cshtml index 7f997a4f..a9ca1934 100644 --- a/cicm_web/Areas/Admin/Views/MachinePhotos/Create.cshtml +++ b/cicm_web/Areas/Admin/Views/MachinePhotos/Create.cshtml @@ -1,4 +1,7 @@ -@model Cicm.Database.Models.MachinePhoto +@using Cicm.Database.Models +@using Microsoft.AspNetCore.Identity +@model cicm_web.Areas.Admin.Models.MachinePhotoViewModel +@inject UserManager UserManager @{ ViewData["Title"] = "Create"; @@ -6,353 +9,90 @@

Create

-

MachinePhoto

+

Machine photo


-
-
-
-
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- -
-
+
+

+ By uploading this photo you confirm you have the rights on it, and you authorize us the non-exclusive rights of show, and distribution, of the photo in database, and the associated mobile application, under the license chosen below. +

+

+ You also confirm that this photo corresponds, to the best of your knowledge, to the specified machine, accompanying materials (such as box, cabling or manuals on the time of retail). +

+

+ Photos that are not clear enough or of too small resolution will be removed of the database. +

+

+ @* TODO Detect roles *@ + This photo will not appear publicly until approved to an administrator. +

+

+ Upload of inappropriate or unrelated photos will create a warning in your account. Several warnings mean your account would be terminated. +

+

+ Removal of your account do not automatically revoke our license to use your photos. If you want to remove your photos contact with an administrator before you remove your account. Failure to do so makes us technically unable to remove your photos in the future. +

+
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + + + +
+
+ + + + +
+ +
+
- \ No newline at end of file +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MachinePhotos/Edit.cshtml b/cicm_web/Areas/Admin/Views/MachinePhotos/Edit.cshtml index 2872fdd4..483b662e 100644 --- a/cicm_web/Areas/Admin/Views/MachinePhotos/Edit.cshtml +++ b/cicm_web/Areas/Admin/Views/MachinePhotos/Edit.cshtml @@ -357,4 +357,8 @@ \ No newline at end of file +
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index c20e2345..994bff73 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.603 + 3.0.99.604 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website