Exemplo n.º 1
0
        public IHttpActionResult Get([FromUri] int id)
        {
            CourseStudentModel courseStudent = courseStudentBll.GetCourseStudentById(id);

            if (courseStudent != null)
            {
                return(Ok(courseStudent));
            }
            return(NotFound());
        }
Exemplo n.º 2
0
 public IHttpActionResult Put([FromUri] int id, [FromBody] CourseStudentModel value)
 {
     if (ModelState.IsValid)
     {
         bool succsess = courseStudentBll.UpdateCourseStudent(id, value);
         if (succsess)
         {
             return(Ok());
         }
     }
     return(BadRequest());
 }
Exemplo n.º 3
0
 public IHttpActionResult post([FromBody] CourseStudentModel value)
 {
     if (ModelState.IsValid)
     {
         bool succsess = courseStudentBll.AddCourseStudent(value);
         if (succsess)
         {
             return(Ok());
         }
         return(BadRequest());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemplo n.º 4
0
        public CourseStudentModel GetCourseStudentById(int id)
        {
            CourseStudentModel courseStudents = null;

            using (AttenderEntities ef = new AttenderEntities())
            {
                CourseStudent item = ef.CourseStudents.FirstOrDefault(a => a.Id == id);
                if (item != null)
                {
                    courseStudents = new CourseStudentModel()
                    {
                        Id        = item.Id,
                        StudentId = item.StudentId,
                        CourseId  = item.CourseId
                    };
                }
            }
            return(courseStudents);
        }
Exemplo n.º 5
0
 // Create;
 public bool AddCourseStudent(CourseStudentModel newCourseStudent)
 {
     using (AttenderEntities ef = new AttenderEntities())
     {
         CourseStudent courseStudents = new CourseStudent()
         {
             //Id = newCourseStudent.Id,
             StudentId = newCourseStudent.StudentId,
             CourseId  = newCourseStudent.CourseId
         };
         //ef.CourseStudents.Add(courseStudents);
         try
         {
             ef.Database.ExecuteSqlCommand($"INSERT INTO [dbo].[CourseStudents] ([StudentId],[CourseId]) VALUES ({courseStudents.StudentId} , {courseStudents.CourseId})");
             //ef.SaveChanges();
         }
         catch
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 6
0
        // update
        public bool UpdateCourseStudent(int id, CourseStudentModel courseStudents)
        {
            using (AttenderEntities ef = new AttenderEntities())
            {
                CourseStudent updateCourseStudents = ef.CourseStudents.FirstOrDefault(a => a.Id == id);
                if (updateCourseStudents == null)
                {
                    return(false);
                }

                updateCourseStudents.StudentId = courseStudents.StudentId;
                updateCourseStudents.CourseId  = courseStudents.CourseId;
                try
                {
                    ef.Database.ExecuteSqlCommand($"UPDATE [dbo].[CourseStudents] SET [StudentId] = {updateCourseStudents.StudentId},[CourseId] = {updateCourseStudents.CourseId} WHERE [Id] = {id}");
                    //ef.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }