Exemplo n.º 1
0
        public async Task<IHttpActionResult> CreateCourseCategory(CourseCategory courseCategory)
        {
            courseCategory.ClientId = this.ClientId;

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            this.db.CourseCategories.Add(courseCategory);
            this.db.SaveChanges();

            return this.Ok(courseCategory);
        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> UpdateCourseCategory(int id, CourseCategory courseCategory)
        {
            courseCategory.ClientId = this.ClientId;

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (id != courseCategory.CourseCategoryId)
            {
                return this.BadRequest();
            }

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

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

                throw;
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }