Example #1
0
        public IHttpActionResult PostCohort(CohortModel cohort)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var dbCohort = new Cohort();

            dbCohort.Update(cohort);
            db.Cohorts.Add(dbCohort);
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception("Unable to add the cohort to the database.");
            }
            cohort.CohortId = dbCohort.CohortId;

            return CreatedAtRoute("DefaultApi", new { id = cohort.CohortId }, cohort);
        }
Example #2
0
        public IHttpActionResult PutCohort(int id, CohortModel cohort)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != cohort.CohortId)
            {
                return BadRequest();
            }
            var dbCohort = db.Cohorts.Find(id);

            dbCohort.Update(cohort);

            db.Entry(cohort).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CohortExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw new Exception("Unable to update cohort in the database.");
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Example #3
0
 public void Update(CohortModel cohort)
 {
     Name = cohort.Name;
     StartDate = cohort.StartDate;
     EndDate = cohort.EndDate;
 }