public async Task<IHttpActionResult> PostDegree(Degree degree)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.degrees.Add(degree);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (DegreeExists(degree.id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = degree.id }, degree);
        }
        public async Task<IHttpActionResult> PutDegree(string id, Degree degree)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != degree.id)
            {
                return BadRequest();
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DegreeExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 3
0
        private void PopulateDegree()
        {
            Degree bachelor = new Degree()
            {
                id = "bachelor",
                name = "Bachelor"
            };

            Degree master = new Degree()
            {
                id = "master",
                name = "Master"
            };

            db.degrees.Add(bachelor);
            db.degrees.Add(master);
            db.SaveChanges();




        }