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

            db.approvedCourses.Add(approvedCourse);

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

            return(CreatedAtRoute("DefaultApi", new { id = approvedCourse.id }, approvedCourse));
        }
Exemple #2
0
        public async Task <IHttpActionResult> PutApprovedCourse(string id, ApprovedCourse approvedCourse)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
        public async Task <IHttpActionResult> DeleteApprovedCourse(string id)
        {
            ApprovedCourse approvedCourse = await db.approvedCourses.FindAsync(id);

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

            db.approvedCourses.Remove(approvedCourse);
            await db.SaveChangesAsync();

            return(Ok(approvedCourse));
        }
Exemple #4
0
        public async Task <IHttpActionResult> GetApprovedCourse(string id)
        {
            ApprovedCourse approvedCourse = await db.approvedCourses.FindAsync(id);

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

            return(Ok(new
            {
                approvedCourse.id,
                approvedCourse.name
            }));
        }