Beispiel #1
0
        public IHttpActionResult PostCohort(CohortCreate cohort)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCohortService();

            if (!service.CreateCohort(cohort))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        // Create Class
        public async Task <bool> CreateCohortAsync(CohortCreate model)
        {
            var existingCohort = await _context.Cohorts.FirstOrDefaultAsync(c => c.Name == model.Name);

            if (existingCohort != null)
            {
                return(false);
            }

            var entity = new CohortEntity {
                Name = model.Name
            };

            _context.Cohorts.Add(entity);
            return(await _context.SaveChangesAsync() == 1);
        }
Beispiel #3
0
        public bool CreateCohort(CohortCreate model)
        {
            var entity =
                new Cohort()
            {
                StartDateUtc = model.StartDateUtc,
                EndDateUtc   = model.EndDateUtc,
                FullTime     = model.FullTime,
                Course       = model.Course,
            };

            using (var context = new ApplicationDbContext())
            {
                context.Cohorts.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }