示例#1
0
        public async Task<IHttpActionResult> CreateCourseSession(CourseSession courseSession)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            this.db.CourseSessions.Add(courseSession);
            this.db.SaveChanges();

            return this.Ok(courseSession);
        }
示例#2
0
        public async Task<IHttpActionResult> UpdateCourseSession(int id, CourseSession courseSession)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (id != courseSession.CourseSessionId)
            {
                return this.BadRequest();
            }

            this.db.Entry(courseSession).State = EntityState.Modified;

            try
            {
                this.db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.CourseSessionExists(id))
                {
                    return this.NotFound();
                }

                throw;
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }