コード例 #1
0
 public async Task Add(Route route)
 {
     if (route != null)
     {
         _schedulingDbContext.Routes.Add(route);
         await _schedulingDbContext.SaveChangesAsync();
     }
 }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] SaveAcademicYearResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var academicYear = mapper.Map <SaveAcademicYearResource, AcademicYear>(resource);

            context.AcademicYears.Add(academicYear);
            await context.SaveChangesAsync();

            academicYear = await context.AcademicYears
                           .Include(ay => ay.AcademicSemesters)
                           .SingleOrDefaultAsync(ay => ay.Id == academicYear.Id);

            var result = mapper.Map <AcademicYear, AcademicYearResource>(academicYear);

            return(Ok(result));
        }