using CarInspection.Data;
using CarInspection.Models;
using CarInspection.Models.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CarInspection.Controllers
{
/// <summary>
/// 車両情報と車検情報をを一覧で表示する
/// </summary>
[Authorize]
public class CarAndInspectionController : Controller
{
private CarInspectionContext db = new CarInspectionContext();
// GET: CarAndInspection
public ActionResult Index()
{
return View();
}
[Authorize]
public ActionResult Details(int? id)
{
var loginUser = GetLoginUser();
if (id == null)
{
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
}
var carAndInspection = new CarAndInspectionViewModel();
var car = loginUser.Cars.FirstOrDefault(c => c.Id == id);
if(car == null)
{
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
}
carAndInspection.Car = car;
carAndInspection.inspectionLicenses = car.InspectionLicenses;
return View(carAndInspection);
}
private User GetLoginUser()
{
return db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
}
}
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
Source収録記事
この snippet は記事の「前提条件の確認! / CarAndInspection」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
同じ記事から
6 件using System; using System.Collections.Generic; using System.Linq; using System.Web;未収録
CarAndInspection
#f3f711378e30
using System; using System.Collections.Generic; using System.Data; using System.Data.Entity;未収録
InspectionLicense
#b21a612f1892
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations;未収録
InspectionLicense
#65f916f3dc5a
// GET: InspectionLicenses/Create public ActionResult Create(int? ParentCarId) { if(ParentCarId == null)未収録
DetailsのViewsからGETのCreateへ値を投げる。
#abe6c1887ce3
// POST: InspectionLicenses/Create // 過多ポスティング攻撃を防止するには、バインド先とする特定のプロパティを有効にしてください。 // 詳細については、https://go.microsoft.com/fwlink/?LinkId=317598 を参照してください。 [HttpPost]未収録
GetからPOSTへ値を引き継ぐ
#a7744e61223a
private ActionResult RedirectToCarAndInspectionDetails(int? carId) { if(carId == null) {未収録
GetからPOSTへ値を引き継ぐ
#3ec38c0487a2
