public ActionResult Details([Bind(Include = "ReportId, EmployeeName")] int?ReportId, string EmployeeName) { if (ReportId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Report report = db.Reports.Find(ReportId); if (report == null) { return(HttpNotFound()); } if (report.ApprovalStatus == 1) { report.ApprovalStatus = 0; } else { report.ApprovalStatus = 1; } db.Entry(report).State = EntityState.Modified; db.SaveChanges(); ReportsDetailsViewModel detailsViewModel = new ReportsDetailsViewModel { Id = (int)ReportId }; ApplicationUser reportUser = db.Users.Find(report.EmployeeId); string loginUserId = User.Identity.GetUserId(); detailsViewModel.EmployeeName = reportUser.EmployeeName; detailsViewModel.IsReportCreater = loginUserId == report.EmployeeId; detailsViewModel.ApprovalStatus = report.ApprovalStatus == 1 ? "承認済み" : "未承認"; string reportUserRole = UserManager.GetRoles(reportUser.Id).Count() != 0 ? UserManager.GetRoles(reportUser.Id)[0] : "Normal"; string loginUserRole = UserManager.GetRoles(loginUserId).Count() != 0 ? UserManager.GetRoles(loginUserId)[0] : "Normal"; if (RolesEnumUtil.GetRoleNum(reportUserRole) < RolesEnumUtil.GetRoleNum(loginUserRole)) { detailsViewModel.Approvable = true; } else { detailsViewModel.Approvable = false; } return(PartialView("_Approval", detailsViewModel)); }
// GET: Reports/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Report report = db.Reports.Find(id); if (report == null) { return(HttpNotFound()); } ReportsDetailsViewModel detailsViewModel = new ReportsDetailsViewModel { Id = report.Id, ReportDate = report.ReportDate, Title = report.Title, Content = report.Content, NegotiationStatus = report.NegotiationStatus, AttendanceTime = report.AttendanceTime, LeavingTime = report.LeavingTime, CreatedAt = report.CreatedAt, UpdatedAt = report.UpdatedAt }; ApplicationUser reportUser = db.Users.Find(report.EmployeeId); string loginUserId = User.Identity.GetUserId(); detailsViewModel.EmployeeName = reportUser.EmployeeName; detailsViewModel.IsReportCreater = loginUserId == report.EmployeeId; detailsViewModel.ApprovalStatus = report.ApprovalStatus == 1 ? "承認済み" : "未承認"; string reportUserRole = UserManager.GetRoles(reportUser.Id).Count() != 0 ? UserManager.GetRoles(reportUser.Id)[0] : "Normal"; string loginUserRole = UserManager.GetRoles(loginUserId).Count() != 0 ? UserManager.GetRoles(loginUserId)[0] : "Normal"; if (RolesEnumUtil.GetRoleNum(reportUserRole) < RolesEnumUtil.GetRoleNum(loginUserRole)) { detailsViewModel.Approvable = true; } else { detailsViewModel.Approvable = false; } //リアクション //リアクション種類別GROUP分け var reactionsCategory = db.Reactions .Where(r => r.ReportId == report.Id) .GroupBy(r => r.Category); var reactionQuantity = new Dictionary <string, int>(); var reactionFlag = new Dictionary <string, bool>(); var reactionString = new Dictionary <string, string>(); //Dictionary初期値設定(null防止) foreach (ReactionCategoryEnum c in Enum.GetValues(typeof(ReactionCategoryEnum))) { reactionQuantity.Add(c.ToString(), 0); reactionFlag.Add(c.ToString(), false); } reactionString.Add("Like", "いいね"); reactionString.Add("Love", "超いいね"); reactionString.Add("Haha", "笑い"); reactionString.Add("Wow", "びっくり"); //Dictionaryに値設定 foreach (var reactions in reactionsCategory) { reactionQuantity[reactions.Key] = reactions.Count(); foreach (var r in reactions) { if (r.EmployeeId == loginUserId) { reactionFlag[reactions.Key] = true; } } } detailsViewModel.ReactionQuantity = reactionQuantity; detailsViewModel.ReactionFlag = reactionFlag; detailsViewModel.ReactionString = reactionString; return(View(detailsViewModel)); }