Exemple #1
0
        public async Task <IActionResult> UpdateDepartment(int id, [FromBody] Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dept = await db.Departments.Include(x => x.Courses).FirstOrDefaultAsync(x => x.DepartmentId == id);

            if (dept == null)
            {
                return(new NotFoundObjectResult("Department not Found"));
            }

            // dept.DepartmentId = department.DepartmentId;
            dept.Budget       = department.Budget;
            dept.InstructorId = department.InstructorId;
            dept.Name         = department.Name;
            dept.StartDate    = department.StartDate;

            db.Update(dept);
            await db.SaveChangesAsync();

            return(new OkObjectResult(dept));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateInstructor(int id, [FromBody] Instructor instructor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Instructor i = instructor;

            i.Id = id;

            db.Update(i);
            await db.SaveChangesAsync();

            return(new OkObjectResult(i));
        }
        public async Task <IActionResult> UpdateCourse(int id, [FromBody] Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Course c = course;
            // c.CourseId = id;
            var c = await db.Courses
                    .Include(x => x.Department)
                    .FirstOrDefaultAsync(x => x.CourseId == id);

            c.CourseId     = course.CourseId;
            c.DepartmentId = course.DepartmentId;
            c.Title        = course.Title;
            c.Credits      = course.Credits;

            db.Update(c);

            await db.SaveChangesAsync();

            return(new OkObjectResult(c));
        }