Exemple #1
0
        public async Task <IHttpActionResult> Postcursus(cursus cursus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.cursus.Add(cursus);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (cursusExists(cursus.CURSUSCODE))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cursus.CURSUSCODE }, cursus));
        }
Exemple #2
0
        public async Task <IHttpActionResult> Putcursus(int id, cursus cursus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
        public async Task <IHttpActionResult> Getcursus(int id)
        {
            cursus cursus = await db.cursus.FindAsync(id);

            if (cursus == null)
            {
                return(NotFound());
            }

            return(Ok(cursus));
        }
Exemple #4
0
        public async Task <IHttpActionResult> Deletecursus(int id)
        {
            cursus cursus = await db.cursus.FindAsync(id);

            if (cursus == null)
            {
                return(NotFound());
            }

            db.cursus.Remove(cursus);
            await db.SaveChangesAsync();

            return(Ok(cursus));
        }