コード例 #1
0
        //public Result<object> GetStudentCourses(string studentUsername)
        //{
        // Not needed duo to list of sessions
        //    throw new NotImplementedException();
        //}

        public Result <CourseRequest> RequestCourse(string Username, string courseName)
        {
            Result <CourseRequest> result = new Result <CourseRequest>();

            try
            {
                UserManagementService ums         = new UserManagementService();
                Result <OlescUser>    currentUser = ums.GetUser(Username);

                if (currentUser.isSuccess)
                {
                    /*If the courserequest is 0, means that there is no request*/
                    if (dbConn.Courses.Where(c => c.CourseName.Equals(courseName)).Count() == 0)
                    {
                        CourseRequest cr = new CourseRequest();
                        cr.CourseName = courseName;
                        cr.UserID     = currentUser.resultObject.ID;
                        cr.CreatedBy  = currentUser.resultObject.Email;
                        /*NO cr.UpdatedBy. The role will never be updated, either created or deleted */

                        dbConn.CourseRequests.Add(cr);

                        int NumOfRecords = dbConn.SaveChanges();
                        if (NumOfRecords >= 1)
                        {
                            result.isSuccess    = true;
                            result.message      = "Course requested succesfully";
                            result.resultObject = cr;
                        }
                    }
                    else
                    {
                        result.isSuccess    = false;
                        result.message      = courseName + " already exist";
                        result.resultObject = null;
                    }
                }
                else
                {
                    result.isSuccess    = currentUser.isSuccess;
                    result.message      = currentUser.message;
                    result.resultObject = null;
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }
            return(result);
        }
コード例 #2
0
        public Result <TutorsRating> GetTutorRate(string tutorUsername)
        {
            Result <TutorsRating> result = new Result <TutorsRating>();
            UserManagementService ums    = new UserManagementService();

            try
            {
                Result <OlescUser> resultUser = ums.GetUser(tutorUsername);
                if (resultUser.isSuccess)
                {
                    TutorsRating tutorRating;
                    tutorRating = dbConn.TutorsRatings.Where(trv => trv.TutorID.Equals(resultUser.resultObject.ID)).FirstOrDefault();

                    if (tutorRating != null)
                    {
                        result.isSuccess    = true;
                        result.message      = "Tutor rating found";
                        result.resultObject = tutorRating;
                    }
                    else
                    {
                        result.isSuccess    = true;
                        result.message      = "Error retrieving Tutor rating";
                        result.resultObject = null;
                    }
                }
                else
                {
                    result.isSuccess    = resultUser.isSuccess;
                    result.message      = resultUser.message;
                    result.resultObject = null;
                }
            }
            catch (Exception e)
            {
                result.isSuccess    = false;
                result.message      = e.Message;
                result.resultObject = null;
            }

            return(result);
        }