public async Task <IActionResult> Create([FromForm] EventInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var entity = model.ToEntity(await GetCurrentUser()); await _database.AddAsync(entity); await _database.SaveChangesAsync(); return(RedirectToAction(nameof(View), new { id = entity.Id })); }
public async Task <IActionResult> Create([FromForm] EventInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var entity = model.ToEntity(await GetCurrentUser()); if (model.SemesterId.HasValue) { var semester = await _database.Semesters.FindAsync(model.SemesterId.Value); semester.Courses.Add(entity); } else { _database.Events.Add(entity); } await _database.SaveChangesAsync(); return(RedirectToAction(nameof(View), new { id = entity.Id })); }