public ApiSimpleResult<StudentCourseModel> DeleteStudentCourse(StudentCourseModel queryModel)
 {
     var result = new ApiSimpleResult<StudentCourseModel>();
     var response = FacultySvc.DeleteStudentCourse(queryModel);
     if (response != null)
         result = response;
     return result;
 }
 public ApiSimpleResult<StudentCourseModel> DeleteStudentCourse(StudentCourseModel queryModel)
 {
     var status = DbContext.GeneralStatuses.Find(queryModel.GeneralStatus.StatusId);
     DbContext.Entry(status).State = EntityState.Deleted;
     var deleteItem = DbContext.StudentCourses.Find(queryModel.StudentCourseId);
     DbContext.Entry(deleteItem).State = EntityState.Deleted;
     var result = new ApiSimpleResult<StudentCourseModel>();
     try
     {
         DbContext.SaveChanges();
         result.StatusString = "Successful";
         result.Message = "Delete data successfully";
         result.Data = queryModel;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         result.Message = "Error";
         result.StatusString = "Error";
     }
     return result;
 }
        public StudentCourseModel GetStudentCourseDetails(int id)
        {
            var response = new StudentCourseModel();
            var detailItem = DbContext.StudentCourses.Find(id);
            if (detailItem != null)
            {
                response.StudentCourseId = detailItem.StudentCourseId;
                response.CourseCode = detailItem.Course.CourseCode;
                response.FullName = detailItem.Student.FullName;
                response.StudentCode = detailItem.Student.StudentCode;
                response.Mark = detailItem.Mark;
                response.Comment = detailItem.Comment;
                response.GradeGroupId = detailItem.GradeGroup.Id;
                response.GradeGroupName = detailItem.GradeGroup.Name;
                response.GeneralStatus = detailItem.GeneralStatus;
                response.Status = detailItem.GeneralStatus.StatusName;
            }

            return response;
        }
 public StudentCourseModel SaveStudentCourse(StudentCourseModel queryModel)
 {
     var result = new StudentCourseModel();
     var status = DbContext.GeneralStatuses.Find(queryModel.GeneralStatus.StatusId);
     status.UpdateTime = DateTime.Now;
     status.StatusName = queryModel.Status;
     DbContext.Entry(status).State = EntityState.Modified;
     var editItem = DbContext.StudentCourses.Find(queryModel.StudentCourseId);
     if (editItem != null)
     {
         editItem.StudentId = queryModel.StudentId;
         editItem.CourseId = queryModel.CourseId;
         editItem.Mark = queryModel.Mark;
         editItem.Comment = queryModel.Comment;
         editItem.GradeGroupId = queryModel.GradeGroupId;
         DbContext.Entry(editItem).State = EntityState.Modified;
     }
     try
     {
         DbContext.SaveChanges();
         result.StudentCourseId = queryModel.StudentCourseId;
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return null;
     }
     return result;
 }
 public StudentCourseModel AddStudentCourse(StudentCourseModel queryModel)
 {
     var result = new StudentCourseModel();
     var status = new GeneralStatus
     {
         StatusName = queryModel.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newItem = new StudentCourse
     {
         StudentId = queryModel.StudentId,
         CourseId = queryModel.CourseId,
         Mark = queryModel.Mark,
         Comment = queryModel.Comment,
         GradeGroupId = queryModel.GradeGroupId,
         GeneralStatusId = status.StatusId
     };
     DbContext.StudentCourses.Add(newItem);
     DbContext.SaveChanges();
     result.StudentCourseId = newItem.StudentCourseId;
     return result;
 }