public ActionResult Details(int?id) { if (id == null) { return(RedirectToAction("Index", "Home")); } var db = new FavorDbContext(); var fullFavor = db.Favors.Include(a => a.PayOff).FirstOrDefault(a => a.Id == id); if (fullFavor == null) { return(RedirectToAction("Index", "Home")); } FavorDetailViewModel favorDetailModel = new FavorDetailViewModel { Id = fullFavor.Id, Title = fullFavor.Title, Description = fullFavor.Description, CreationDate = fullFavor.CreationDate, UserFullName = fullFavor.User.FullName, PayOff = fullFavor.PayOff, FavorType = fullFavor.FavorType, User = fullFavor.User }; FavorDeleteViewModel.UrlOpenedFrom = $"/Favor/Details/{id}"; FavorEditViewModel.UrlOpenedFrom = $"/Favor/Details/{id}"; return(View(favorDetailModel)); }
public bool IsUserAuthorizedToEdit(FavorDetailViewModel favor) { var isAdmin = this.User.IsInRole("Admin"); var isAuthor = favor.IsAuthor(this.User.Identity.Name); return(isAdmin || isAuthor); }