public async Task <IActionResult> Store([FromBody] TermEditForm model) { var termYear = await termService.GetTermYearByIdAsync(model.term.termYearId); if (termYear == null) { throw new Exception(String.Format("TermYear not found.id = {0}", model.term.termYearId)); } int number = ViewService.CreateTermNumber(termYear.Year, model.order); var exist = termService.GetTermByNumber(number); if (exist != null) { ModelState.AddModelError("order", "年度與順序重複了"); return(BadRequest(ModelState)); } var term = model.term.MapToEntity(number); term = await termService.CreateAsync(term); return(Ok(term)); }