public ActionResult Details(string id) { // idが無い場合、不正なリクエストとして処理 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // DBからidで検索して該当するユーザーを取得 ApplicationUser applicationUser = db.Users.Find(id); // ユーザーが取得できなければ、NotFoundエラーページへ if (applicationUser == null) { return(HttpNotFound()); } // ビューモデルにデータを詰め替える EmployeesDetailsViewModel employee = new EmployeesDetailsViewModel { Id = applicationUser.Id, Email = applicationUser.Email, EmployeeName = applicationUser.EmployeeName, CreatedAt = applicationUser.CreatedAt, UpdatedAt = applicationUser.UpdatedAt }; // RoleがAdminかどうか確認し、そうなら"管理者"、違うなら"一般"にする employee.Role = UserManager.IsInRole(applicationUser.Id, "Admin") ? "管理者" : "一般"; return(View(employee)); }
// GET: Employees/Details/5 public ActionResult Details(string id) { // idが無い場合、不正なリクエストとして処理 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // DBからidで検索して該当するユーザーを取得 ApplicationUser applicationUser = db.Users.Find(id); // ユーザーが取得できなければ、NotFoundエラーページへ if (applicationUser == null) { return(HttpNotFound()); } // ビューモデルにデータを詰め替える EmployeesDetailsViewModel employee = new EmployeesDetailsViewModel { Id = applicationUser.Id, Email = applicationUser.Email, EmployeeName = applicationUser.EmployeeName, CreatedAt = applicationUser.CreatedAt, UpdatedAt = applicationUser.UpdatedAt }; if (UserManager.IsInRole(applicationUser.Id, "Chief")) { employee.Role = "係長"; } else if (UserManager.IsInRole(applicationUser.Id, "Manager")) { employee.Role = "部長"; } else if (UserManager.IsInRole(applicationUser.Id, "GeneralManager")) { employee.Role = "本部長"; } else if (UserManager.IsInRole(applicationUser.Id, "ManagingDirector")) { employee.Role = "専務"; } else if (UserManager.IsInRole(applicationUser.Id, "President")) { employee.Role = "社長"; } else { employee.Role = "一般"; } return(View(employee)); }