public async Task<ActionResult> Edit(int id) { if (id != null) { var calendarEvent = await db.Events.FindAsync(id); var isAdmin = User.IsInRole("Admin") || User.IsInRole("Moderator"); if (calendarEvent != null) { if (isAdmin || (calendarEvent.OwnerId != null && calendarEvent.OwnerId == User.Identity.GetUserId())) { var model = new EventEditModel() { Id = calendarEvent.Id, Name = calendarEvent.Name, Description = calendarEvent.Description, GameId = calendarEvent.GameId, StartDate = calendarEvent.DateTimeSchedualed.Date.ToString("yyyy-MM-dd"), StartTime = calendarEvent.DateTimeSchedualed.TimeOfDay.ToString(), Duration = calendarEvent.Duration, Durations = this.Durations(), Games = await db.Games.ToDictionaryAsync(e => (int) e.GameId, e => e.Name) }; ViewBag.Title = "Edit Event: " + calendarEvent.Name; return View(model); } return RedirectToActionPermanent("AccessDenied", "Home"); } } return RedirectToAction("Create"); }
public async Task<ActionResult> Create(int gameId = 0) { var model = new EventEditModel { Durations = this.Durations(), Games = await db.Games.ToDictionaryAsync(e => (int) e.GameId, e => e.Name), GameId = gameId }; ViewBag.Title = "Create Event"; return View("Edit", model); }