public async Task <IActionResult> Create([FromForm] SemesterInputModel input) { if (!ModelState.IsValid) { return(View(input)); } var activeSemesters = await _database.Semesters .Expressionify() .AnyAsync(s => s.IsActive()); if (activeSemesters) { return(RedirectToAction(nameof(Index))); } _database.Semesters.Add(new Data.Semester { Title = input.Title, SignupOpensAt = input.SignupOpensAtDate.GetUtc(input.SignupOpensAtTime), SignupHelpText = input.SignupHelpText }); await _database.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit([FromForm] SemesterInputModel input) { if (!ModelState.IsValid) { return(View(input)); } var semester = await _database.Semesters .Include(s => s.Courses) .ThenInclude(c => c.SignupOptions) .Expressionify() .Where(s => s.IsActive()) .OrderByDescending(s => s.SignupOpensAt) .FirstOrDefaultAsync(); semester.Title = input.Title; semester.SignupOpensAt = input.SignupOpensAtDate.GetUtc(input.SignupOpensAtTime); semester.SignupHelpText = input.SignupHelpText; foreach (var course in semester.Courses) { if (course.SignupOptions.SignupOpensAt < semester.SignupOpensAt) { course.SignupOptions.SignupOpensAt = semester.SignupOpensAt; } } await _database.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Create() { var now = TimeProvider.UtcToday; var season = now.Month >= 7 ? "Høsten" : "Våren"; var year = now.Year; var(date, _) = now.AddDays(7).GetLocalDateAndTime(); var model = new SemesterInputModel { Title = $"{season} {year}", SignupOpensAtDate = date, SignupOpensAtTime = "12:00" }; return(View(model)); }
public async Task <IActionResult> Edit() { var semester = await _database.Semesters .Expressionify() .Where(s => s.IsActive()) .OrderByDescending(s => s.SignupOpensAt) .FirstOrDefaultAsync(); var(date, time) = semester.SignupOpensAt.GetLocalDateAndTime(); var model = new SemesterInputModel { Title = semester.Title, SignupOpensAtDate = date, SignupOpensAtTime = time, SignupHelpText = semester.SignupHelpText }; return(View(model)); }