Exemplo n.º 1
0
    /**
     * Rejects a project
     *
     */
    public Project rejectProject(Project project)
    {
        if (session == null || !session.IsOpen)
        {
            session = hibernate.getSession();
        }
        if (project.PROJECT_ID == null || project.PROJECT_ID == 0)
            throw new ApproveProjectException("Project " + project.PROJECT_TITLE + " is not submitted yet. Please submit project first.");

        //Set to APPROVED
        project.PROJECT_STATUS = APPLICATION_STATUS.REJECTED;

        //Update project
        Project approvedProject = this.updateProject(project);

        //send out email
        string subject = "Sorry your project has been rejected.";
        string message = "Your project " + project.PROJECT_TITLE + " has been rejected.<br/>";
        message += "Reason: " + project.UC_REMARKS;
        EmailModule emailModule = new EmailModule();
        emailModule.sendEmail(subject, message, project.PROJECT_OWNER.EMAIL);

        return approvedProject;
    }
Exemplo n.º 2
0
    /**
     * Approve a particular project with a project object
     *
     * - change the status to APPROVED
     * - validate project atributes
     * - update the project object
     * - send out email to project owner
     *
     */
    public Project approveProject(Project project, long UCId)
    {
        if (session == null || !session.IsOpen)
        {
            session = hibernate.getSession();
        }
        if (project.PROJECT_ID == null || project.PROJECT_ID == 0)
            throw new ApproveProjectException("Project " + project.PROJECT_TITLE + " is not submitted yet. Please submit project first.");

        //Set to APPROVED
        project.PROJECT_STATUS = APPLICATION_STATUS.APPROVED;

        //Set approver ID
        project.UC_APPROVER = UCId;

        //Update project
        Project approvedProject = this.updateProject(project);

        //send out email
        string subject = "Congratulations! Your project has been approved!";
        string message = "<h2>Your project " + project.PROJECT_TITLE + " has been approved!</h2>";
        EmailModule emailModule = new EmailModule();
        emailModule.sendEmail(subject, message, project.PROJECT_OWNER.EMAIL);

        return approvedProject;
    }
Exemplo n.º 3
0
    /**
     * Assign project to a team of Students
     *
     * - If rejectOthers is TRUE, set all other Application statuses to REJECTED
     * - Change the application status of all studentIds to APPROVED
     * - Create a Team object with TeamAssignment to the studentIds
     * - For each student who is assigned to this project, close off
     */
    public Team assignProject(long projectId, IList<long> applicationIds, bool rejectOthers)
    {
        Project project = this.getProjectById(projectId);
        if (project == null)
            throw new ProjectAssignmentException("Project Id " + projectId + " not found.");

        if(project.PROJECT_STATUS != APPLICATION_STATUS.APPROVED)
            throw new ProjectAssignmentException("Project Id " + projectId + " is not in the APPROVED status.");

        if(applicationIds.Count <= 0 )
            throw new ProjectAssignmentException("Please select at least 1 application.");

        IList<ProjectApplication> allApplications = project.APPLICATIONS;
        IList<ProjectApplication> successfulApplications = new List<ProjectApplication>();
        IList<ProjectApplication> failedApplications = new List<ProjectApplication>();

        if (session == null || !session.IsOpen)
        {
            session = hibernate.getSession();
        }

        //Update successful applications
        session.BeginTransaction();
        foreach (ProjectApplication application in allApplications)
        {
            if (applicationIds.Contains(application.APPLICATION_ID))
            {
                application.APPLICATION_STATUS = APPLICATION_STATUS.APPROVED;
                successfulApplications.Add(application);
                session.Update(application);
            }

            if (successfulApplications.Count % MAX_FLUSH_SIZE == 0)
                session.Flush();
        }
        session.Flush();

        //If rejectOthers flag is set as true, reject the rest of the applications
        if (rejectOthers)
        {
            foreach (ProjectApplication application in allApplications)
            {
                if (!applicationIds.Contains(application.APPLICATION_ID))
                {
                    application.APPLICATION_STATUS = APPLICATION_STATUS.REJECTED;
                    failedApplications.Add(application);
                    session.Update(application);
                }

                if (failedApplications.Count % MAX_FLUSH_SIZE == 0)
                    session.Flush();
            }
            session.Flush();
        }

        //Set Project status to ASSIGNED
        project.PROJECT_STATUS = APPLICATION_STATUS.ASSIGNED;

        //Create Team first
        Team newTeam = new Team();
        session.Save(newTeam);

        //Create ProjectAssignment - relationship between Team and Project
        ProjectAssignment pAssignment = new ProjectAssignment();
        pAssignment.PROJECT = project;
        pAssignment.TEAM = newTeam;
        project.ASSIGNED_TEAMS.Add(pAssignment);
        newTeam.ASSIGNED_TO_PROJECT.Add(pAssignment);

        foreach (ProjectApplication application in successfulApplications)
        {
            //set team relationships
            TeamAssignment tAssignment = new TeamAssignment();
            Student student = application.APPLICANT;

            tAssignment.STUDENT = student;
            tAssignment.TEAM = newTeam;

            //Close off all this student's applications
            IList<ProjectApplication> existingApplications = student.PROJECTS_APPLIED;
            foreach(ProjectApplication existingApplication in existingApplications)
            {
                if (existingApplication.APPLICATION_ID == application.APPLICATION_ID)
                    continue;
                existingApplication.APPLICATION_STATUS = APPLICATION_STATUS.REJECTED;
                session.Save(existingApplication);
            }

            //set opposite direction relationships
            newTeam.TEAM_ASSIGNMENT.Add(tAssignment);
            student.TEAM_ASSIGNMENT.Add(tAssignment);

            //set assignment attributes
            tAssignment.ROLE = TEAM_ASSIGNMENT_ROLE.MEMBER;

            session.Save(tAssignment);
            session.Save(student);
        }

        session.Save(pAssignment);
        session.Save(project);
        session.Save(newTeam);
        //session.Flush();

        session.Transaction.Commit();

        //send emails to:
        //1. Project Owner
        //2. Project members
        EmailModule emailModule = new EmailModule();
        string ownerSubject = "Congratulations! Your project has been assigned!";
        string ownerMessage = "<h2>Your project " + project.PROJECT_TITLE + " has been assigned to the following students:<h2> <br />";
        foreach(TeamAssignment ta in newTeam.TEAM_ASSIGNMENT)
        {
            Student member = ta.STUDENT;
            ownerMessage += "- " + member.FIRSTNAME + " " + member.LASTNAME + " (Student ID: " + member.USER_ID + ", Email: " + member.EMAIL + ") <br />";
        }
        emailModule.sendEmail(ownerSubject, ownerMessage, project.PROJECT_OWNER.EMAIL);

        string studentSubject = "Congratulations! You have been assigned to a project!";
        string studentMessage = "<h2>You have been assigned to the following project:</h2> <br />";
        studentMessage += "'" + project.PROJECT_TITLE + "' (Project ID: " + project.PROJECT_ID + ") <br />";
        studentMessage += "By company: " + project.PROJECT_OWNER.USERNAME + " (Company reg num: " + project.PROJECT_OWNER.COMPANY_REG_NUM + ") <br />";
        studentMessage += "Contact person: " + project.CONTACT_NAME + " <br />";
        studentMessage += "Contact email: " + project.CONTACT_EMAIL + " <br />";
        studentMessage += "Contact phone: " + project.CONTACT_NUMBER + " <br />";

        IList<string> addresses = new List<string>();
        foreach (TeamAssignment ta in newTeam.TEAM_ASSIGNMENT)
        {
            Student member = ta.STUDENT;
            addresses.Add(member.EMAIL);
        }
        emailModule.sendEmailToMany(studentSubject, studentMessage,addresses);

        return newTeam;
    }