示例#1
0
        public string Save(CourseAssignToTeacher courseAssign)
        {
            if (courseAssignToTeacherGateway.IsSubjectAssigned(courseAssign))
            {
                return("This Course already Assigned");
            }
            else
            {
                float Credit          = Convert.ToSingle(courseGateway.GetCourseId(courseAssign.CourseCode).Credit);
                float AvailableCredit = Convert.ToSingle(teacherGateway.GetAvailableCreditByTeacherId(courseAssign.TeacherId).RemainingCredit);
                float RemainingCredit = (AvailableCredit - Credit);

                if (RemainingCredit > 0)
                {
                    int rowAffect = teacherGateway.UpdateTeacher(courseAssign.TeacherId, RemainingCredit);
                    if (rowAffect > 0)
                    {
                        int affect = courseAssignToTeacherGateway.Save(courseAssign);
                        if (affect > 0)
                        {
                            return("Save Successfull");
                        }
                        else
                        {
                            return("Failed");
                        }
                    }

                    else
                    {
                        return("Failed");
                    }
                }
                else
                {
                    return("Not Enough Credit Left");
                }
            }
        }