public async Task <IActionResult> Store([FromBody] TermYearEditForm model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var exist = termService.GetTermYear(model.year.year); if (exist != null) { ModelState.AddModelError("year.year", "年度重複了"); return(BadRequest(ModelState)); } var termYear = model.year.MapToEntity(); if (termYear.Title.IsNullOrEmpty()) { termYear.Title = String.Format("{0}學年度", termYear.Year); } termYear = await termService.CreateTermYearAsync(termYear); return(Ok(termYear)); }
public async Task <IActionResult> Update(int id, [FromBody] TermYearEditForm model) { var termYear = await termService.GetTermYearByIdAsync(id); if (termYear == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var exist = termService.GetTermYear(model.year.year); if (exist != null && exist.Id != id) { ModelState.AddModelError("year.year", "年度重複了"); return(BadRequest(ModelState)); } termYear = model.year.MapToEntity(termYear); await termService.UpdateTermYearAsync(termYear); return(Ok(termYear)); }
public IActionResult Create() { var activeTermYear = termService.GetActiveTermYear(); var termYear = new TermYearViewModel { year = activeTermYear.Year + 1 }; var model = new TermYearEditForm { year = termYear }; return(Ok(model)); }
public async Task <IActionResult> Edit(int id) { var termYear = await termService.GetTermYearByIdAsync(id); if (termYear == null) { return(NotFound()); } var model = new TermYearEditForm { year = termYear.MapTermYearViewModel() }; return(Ok(model)); }