public ActionResult Create([DataSourceRequest]DataSourceRequest request, ProjectAssignment projectAssignments)
        {
           try
            {
                var entity = new ProjectAssignment
                {
                    O_Id = projectAssignments.O_Id,
                    P_Id = projectAssignments.P_Id,
                    M_Id = projectAssignments.M_Id,
                    PA_Rotation_Num = projectAssignments.PA_Rotation_Num,
                    PA_Start_Date = projectAssignments.PA_Start_Date,
                    PA_End_Date = projectAssignments.PA_End_Date
                };
                db.ProjectAssignments.Add(entity);
                db.SaveChanges();
                projectAssignments.PA_Id = entity.PA_Id;
                ViewBag.msg = "Assigned";
                return View("Create");

            }
            catch (Exception e1)
            {
                ViewBag.msg = "Assignment of same project to onboarder";
                return View("Create");
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,EmpKey,ProjKey,authorized_assignment")] ProjectAssignment projectAssignment)
        {
            if (id != projectAssignment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(projectAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectAssignmentExists(projectAssignment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(projectAssignment));
        }
        protected virtual void Assign(int projId, int devId)
        {
            var assignment = new ProjectAssignment {
                ProjectId = projId, DeveloperId = devId
            };

            Assignments.Add(assignment);
        }
示例#4
0
        public RedirectToActionResult CreateProject(Project project)
        {
            Project           newProject    = _projectRepository.Add(project);
            ProjectAssignment newAssignment = new ProjectAssignment {
                ProjectId = newProject.ProjectId, UsersId = userManager.GetUserId(HttpContext.User)
            };

            _projectRepository.Assign(newAssignment);
            return(RedirectToAction("projectdetails", new { id = newProject.ProjectId }));
        }
        public async Task <IActionResult> Create([Bind("ID,EmpKey,ProjKey,authorized_assignment")] ProjectAssignment projectAssignment)
        {
            if (!ModelState.IsValid)
            {
                return(View(projectAssignment));
            }
            _context.Add(projectAssignment);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#6
0
        public ProjectAssignment Add(ProjectAssignment entity, long projectId)
        {
            RestRequest r = new RestRequest("/projects/{projectId}/{module}", Method.POST);

            r.AddUrlSegment("projectId", projectId);
            r.AddUrlSegment("module", module);
            r.JsonSerializer = client.serializer;
            r.AddJsonBody(entity);

            return(client.Execute <ProjectAssignment>(r));
        }
        public bool AdminUpdateProjectStatus(int project_id, string new_status)
        {
            //Perform input validation
            if (new_status == null || new_status == "")
            {
                return(false);
            }
            if ((new_status != ProjectStatus.ASSIGNED) &&
                (new_status != ProjectStatus.IN_PROGRESS) &&
                (new_status != ProjectStatus.INTERN) &&
                (new_status != ProjectStatus.PRODUCTION) &&
                (new_status != ProjectStatus.ARCHIVED))
            {
                return(false);
            }

            using (var context = new MainDBEntities())
            {
                //Access object checks
                if (this.GetType() == typeof(AdminAccess))
                {
                    ProjectAssignment current_project = new ProjectAssignment();

                    //Read in necessary object
                    current_project = context.ProjectAssignments.Find(project_id);

                    //Modify status
                    current_project.ProgressStatus = new_status;

                    //Indicate that that value has been modified
                    context.ProjectAssignments.Attach(current_project);
                    var entry = context.Entry(current_project);

                    //Indicate that IsArchived property has been modified (indicates to EF that property
                    //needs update
                    entry.Property(x => x.ProgressStatus).IsModified = true;

                    //Save update
                    context.SaveChanges();

                    //Indicate successful update
                    return(true);
                }
                else
                {
                    //Invalid access object
                    return(false);
                }
            }
        }
        //Func Desc:
        //    Input:
        //   Output:
        public bool AssignProjectToSchool(int?project_id, int?school_id)
        {
            if (project_id == null)
            {
                return(false);
            }
            if (school_id == null)
            {
                return(false);
            }
            if (school_id < 0)
            {
                return(false);
            }
            if (project_id < 0)
            {
                return(false);
            }

            using (var context = new MainDBEntities())
            {
                //Find project with id = project_id, store in temp_project
                Project temp_project = context.Projects.Find(project_id);

                //Verify that valid project was found
                if (temp_project == null)
                {
                    return(false);
                }

                //Create Project Assignment
                ProjectAssignment new_assignment = new ProjectAssignment();

                //Set starting assignment values
                new_assignment.ProgressStatus = ProjectStatus.ASSIGNED;
                new_assignment.ProjectID      = (int)project_id;
                new_assignment.SchoolID       = (int)school_id;
                new_assignment.DateAssigned   = DateTime.Now;

                //Save changes to the database
                context.ProjectAssignments.Add(new_assignment);

                //Save update
                context.SaveChanges();

                //Indicate successful assignment
                return(true);
            }
        }
示例#9
0
 public RedirectToActionResult AddMembers(ProjectDetailsViewModel model)
 {
     //if (ModelState.IsValid)
     {
         ProjectAssignment newAssignment = new ProjectAssignment {
             ProjectId = model.Project.ProjectId, UsersId = model.User.Id
         };
         _projectRepository.Assign(newAssignment);
         var selectedUser = userManager.Users.FirstOrDefault(u => u.Id == model.User.Id);
         UsersList.Remove(selectedUser);
         ViewBag.List     = UsersList;
         ViewBag.AssignID = newAssignment.Id;
     }
     return(RedirectToAction("projectdetails", new { id = model.Project.ProjectId }));
 }
 public ActionResult Delete(int id)
 {
      try
     {
         ProjectAssignment record = db.ProjectAssignments.FirstOrDefault(m => m.PA_Id == id);
         db.ProjectAssignments.Remove(record);
         db.SaveChanges();
         return JavaScript("<script>alert('Record Deleted')</script>");
         //return View("Delete");
     }
     catch (Exception e)
     {
     }
     return View("Delete");
 }
        public bool UpdateActiveStatusToInProg(int?active_project_id)
        {
            //Input checks
            if (active_project_id == null)
            {
                return(false);
            }
            if (active_project_id < 0)
            {
                return(false);
            }

            using (var context = new MainDBEntities())
            {
                //Access object checks
                if ((this.GetType() == typeof(AdminAccess)) ||
                    (this.GetType() == typeof(AmbassadorAccess)))
                {
                    ProjectAssignment active_project = new ProjectAssignment();

                    //Read in necessary object
                    active_project = context.ProjectAssignments.Find(active_project_id);

                    //Modify status
                    active_project.ProgressStatus = ProjectStatus.IN_PROGRESS;

                    //Indicate that that value has been modified
                    context.ProjectAssignments.Attach(active_project);
                    var entry = context.Entry(active_project);

                    //Indicate that IsArchived property has been modified (indicates to EF that property
                    //needs update
                    entry.Property(x => x.ProgressStatus).IsModified = true;

                    //Save update
                    context.SaveChanges();

                    //Indicate successful archive
                    return(true);
                }
                else
                {
                    //Invalid access object
                    return(false);
                }
            }
        }
示例#12
0
        public async Task <IActionResult> CreateAssignments([FromBody] CreateProjectAssignmentsViewModel model, string projectUrl)
        {
            int projectId = Database.Project
                            .Where(p => p.Url == projectUrl)
                            .Select(p => p.Id)
                            .FirstOrDefault();

            int userId = int.Parse(User.Claims.First(c => c.Type == "UserId").Value);

            foreach (int id in model.UserIdList)
            {
                var user = Database.User
                           .Where(u => u.Id == id)
                           .FirstOrDefault();

                string roleName = Database.ProjectAssignmentRole
                                  .Where(r => r.Id == model.RoleId)
                                  .Select(r => r.Name)
                                  .FirstOrDefault();

                var assignment = new ProjectAssignment
                {
                    ProjectId  = projectId,
                    RoleId     = model.RoleId,
                    AssigneeId = id
                };
                Database.ProjectAssignment.Add(assignment);

                ProjectActivity activity = new ProjectActivity
                {
                    ProjectId = projectId,
                    AuthorId  = userId,
                    Content   = $"{user.FirstName} {user.LastName} was assigned as {roleName}"
                };
                Database.ProjectActivity.Add(activity);
            }


            await Database.SaveChangesAsync();

            return(Json(new
            {
                status = true,
                url = Url.Action("Assignments")
            }));
        }
示例#13
0
        public ProjectAssignment Update(ProjectAssignment entity, long projectId)
        {
            if (entity.Id.HasValue)
            {
                RestRequest r = new RestRequest("/projects/{projectId}/{module}/{id}", Method.Patch);
                r.AddUrlSegment("id", entity.Id.Value);
                r.AddUrlSegment("projectId", projectId);
                r.AddUrlSegment("module", module);

                r.AddJsonBody(entity);

                return(client.Execute <ProjectAssignment>(r));
            }
            else
            {
                throw new Exception("Id of object must be specified.");
            }
        }
        public Task <Developer> AssignProject(ProjectAssignment operation)
        {
            return(Task.Run(() => {
                var developer = GetDeveloper(operation.Developer);
                if (developer == null)
                {
                    return null;
                }
                var project = GetProject(operation.Project);
                if (project == null)
                {
                    return null;
                }

                assignments[developer.Id] = project.Id;
                return developer;
            }));
        }
示例#15
0
        public ActionResult Edit(int id, ProjectAssignment projAsgnmt)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                UpdateModel(GetProjectAssignmentByID(id));
                _dataModel.SaveChanges();
                return(RedirectToAction("Index", "Project"));
            }
            catch
            {
                return(RedirectToAction("Index", "Project"));
            }
        }
示例#16
0
        public ActionResult Create([Bind(Exclude = "ProjectAssignmentID")] ProjectAssignment newProjAsgnmt)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                _dataModel.AddToProjectAssignments(newProjAsgnmt);
                _dataModel.SaveChanges();

                return(RedirectToAction("Index", "Project"));
            }
            catch
            {
                return(RedirectToAction("Index", "Project"));
            }
        }
示例#17
0
        public static ProjectAssignment Select_Record(ProjectAssignment ProjectAssignmentPara)
        {
            ProjectAssignment ProjectAssignment = new ProjectAssignment();
            SqlConnection     connection        = PMMSData.GetConnection();
            string            selectProcedure   = "[ProjectAssignmentSelect]";
            SqlCommand        selectCommand     = new SqlCommand(selectProcedure, connection);

            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.Parameters.AddWithValue("@ProjectAssignmentID", ProjectAssignmentPara.ProjectAssignmentID);
            try
            {
                connection.Open();
                SqlDataReader reader
                    = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    ProjectAssignment.ProjectAssignmentID = System.Convert.ToInt32(reader["ProjectAssignmentID"]);
                    ProjectAssignment.ProjectID           = System.Convert.ToInt32(reader["ProjectID"]);
                    ProjectAssignment.EmployeeID          = System.Convert.ToInt32(reader["EmployeeID"]);
                    ProjectAssignment.AssignmentDate      = System.Convert.ToDateTime(reader["AssignmentDate"]);
                    ProjectAssignment.Remarks             = reader["Remarks"] is DBNull ? null : reader["Remarks"].ToString();
                    ProjectAssignment.AddUserID           = System.Convert.ToInt32(reader["AddUserID"]);
                    ProjectAssignment.AddDate             = System.Convert.ToDateTime(reader["AddDate"]);
                    ProjectAssignment.ArchiveUserID       = reader["ArchiveUserID"] is DBNull ? null : (Int32?)reader["ArchiveUserID"];
                    ProjectAssignment.ArchiveDate         = reader["ArchiveDate"] is DBNull ? null : (DateTime?)reader["ArchiveDate"];
                }
                else
                {
                    ProjectAssignment = null;
                }
                reader.Close();
            }
            catch (SqlException)
            {
                return(ProjectAssignment);
            }
            finally
            {
                connection.Close();
            }
            return(ProjectAssignment);
        }
示例#18
0
        //
        // GET: /ProjectAssignment/Delete/5

        public ActionResult Delete(int id)
        {
            try
            {
                ProjectAssignment projAsgnmt = GetProjectAssignmentByID(id);

                if (projAsgnmt == null)
                {
                    return(RedirectToAction("Index", "Project"));
                }
                else
                {
                    return(View(projAsgnmt));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Project"));
            }
        }
        // Add user to project
        public async Task AddUser(long projectid, string userName)
        {
            // Check if project exists
            NullCheck(await standardRepository.FindByIdAsync(projectid));
            // Assign user
            try
            {
                var projectAssignment = new ProjectAssignment()
                {
                    ProjectId = projectid,
                    Username  = userName
                };
                await projectAssignmentRepository.AddAsync(projectAssignment);

                await unitOfWork.CompleteAsync();
            }
            catch (DbUpdateException e)
            {
                throw new BadRequestException(e.InnerException?.Message, typeof(Project).ToString());
            }
        }
示例#20
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                ProjectAssignment projAsgnmt = GetProjectAssignmentByID(id);

                if (projAsgnmt == null)
                {
                    return(RedirectToAction("Index", "Project"));
                }

                _dataModel.DeleteObject(projAsgnmt);
                _dataModel.SaveChanges();

                return(RedirectToAction("Index", "Project"));
            }
            catch
            {
                return(RedirectToAction("Index", "Project"));
            }
        }
示例#21
0
 public IActionResult AddProjectMember(int id, ProjectAssignmentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var project    = _context.Projects.SingleOrDefault(x => x.ProjectId == id);
         var individual = _context.ApplicationUsers.SingleOrDefault(x => x.Email == model.SearchEmail);
         if (individual != null && project != null)
         {
             var Project_Assignment = new ProjectAssignment();
             Project_Assignment.EmployeeId = individual.Id;
             Project_Assignment.ProjectId  = project.ProjectId;
             Project_Assignment.Status     = "Pending";
             _context.ProjectAssignment.Add(Project_Assignment);
             _context.SaveChanges();
             return(RedirectToAction("ProjectMembers", new { Id = id }));
         }
         else
         {
         }
     }
     return(View(model));
 }
        public ActionResult DeleteConfirmed(
            Int32?ProjectAssignmentID
            )
        {
            ProjectAssignment ProjectAssignment = new ProjectAssignment();

            ProjectAssignment.ProjectAssignmentID = System.Convert.ToInt32(ProjectAssignmentID);
            ProjectAssignment = ProjectAssignmentData.Select_Record(ProjectAssignment);

            bool bSucess = false;

            bSucess = ProjectAssignmentData.Delete(ProjectAssignment);
            if (bSucess == true)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Can Not Delete");
            }
            return(null);
        }
        // GET: /ProjectAssignment/Delete/<id>
        public ActionResult Delete(
            Int32?ProjectAssignmentID
            )
        {
            if (
                ProjectAssignmentID == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            dtProject  = ProjectAssignment_ProjectData.SelectAll();
            dtEmployee = ProjectAssignment_EmployeeData.SelectAll();

            ProjectAssignment ProjectAssignment = new ProjectAssignment();

            ProjectAssignment.ProjectAssignmentID = System.Convert.ToInt32(ProjectAssignmentID);
            ProjectAssignment         = ProjectAssignmentData.Select_Record(ProjectAssignment);
            ProjectAssignment.Project = new Project()
            {
                ProjectID     = (Int32)ProjectAssignment.ProjectID
                , ProjectName = (from DataRow rowProject in dtProject.Rows
                                 where ProjectAssignment.ProjectID == (int)rowProject["ProjectID"]
                                 select(String) rowProject["ProjectName"]).FirstOrDefault()
            };
            ProjectAssignment.Employee = new Employee()
            {
                EmployeeID  = (Int32)ProjectAssignment.EmployeeID
                , FirstName = (from DataRow rowEmployee in dtEmployee.Rows
                               where ProjectAssignment.EmployeeID == (int)rowEmployee["EmployeeID"]
                               select(String) rowEmployee["FirstName"]).FirstOrDefault()
            };

            if (ProjectAssignment == null)
            {
                return(HttpNotFound());
            }
            return(View(ProjectAssignment));
        }
 public JsonResult ProjectAssignment_Delete_Fetch(string o_id,string rotation_no)
 {
     try
     {
         int id1 = Int32.Parse(o_id), rotation = Int32.Parse(rotation_no);
         ProjectAssignment projectAssignmet = db.ProjectAssignments.FirstOrDefault(m => m.O_Id == id1 && m.PA_Rotation_Num == rotation);
         if (projectAssignmet != null)
         {
             TempProjectAssignment tpa = new TempProjectAssignment
             {
                 PA_Id = id1,
                 Project = db.Projects.Find(projectAssignmet.P_Id),
                 Onboarder = db.Onboarders.Find(projectAssignmet.O_Id),
                 Mentor = db.Mentors.Find(projectAssignmet.M_Id),
                 Psn = projectAssignmet
             };
             return Json(tpa, JsonRequestBehavior.AllowGet);
         }
     }
     catch (Exception e) {
         return Json(null, JsonRequestBehavior.AllowGet);
     }
     return Json(null, JsonRequestBehavior.AllowGet);
 }
示例#25
0
        public async Task <IActionResult> Create(CreateProjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.StartDate > model.DueDate)
                {
                    ModelState.AddModelError("DueDate", "Due date cannot be before start date.");
                    return(View(model));
                }

                string[] routeNames = { "create", "index", "delete", "activities", "gantt", "assignments", "update", "wiki" };
                int      urlCount   = Database.Project
                                      .Count(p => p.Url == model.Url);
                if (urlCount == 0 && !routeNames.Contains(model.Url))
                {
                    Project project = new Project
                    {
                        Name            = model.Name,
                        Url             = model.Url.ToLower(),
                        Overview        = model.Overview ?? "todo: ADD PROJECT OVERVIEW",
                        StartDate       = model.StartDate,
                        DueDate         = model.DueDate,
                        ParentProjectId = model.ParentProjectId == 0 ? (int?)null : model.ParentProjectId,
                        Wiki            = "todo: ADD PROJECT WIKI"
                    };
                    Database.Project.Add(project);

                    int userId = int.Parse(User.Claims.First(c => c.Type == "UserId").Value);
                    int roleId = Database.ProjectAssignmentRole
                                 .Where(r => r.Name == "Creator")
                                 .Select(r => r.Id)
                                 .FirstOrDefault();
                    ProjectAssignment assignment = new ProjectAssignment
                    {
                        ProjectId  = project.Id,
                        AssigneeId = userId,
                        RoleId     = roleId
                    };
                    Database.ProjectAssignment.Add(assignment);

                    ProjectVersion version = new ProjectVersion
                    {
                        ProjectId = project.Id,
                        Url       = "default",
                        Name      = $"{project.Name} // Default version",
                        Overview  = "Default project version",
                        StartDate = project.StartDate,
                        DueDate   = project.DueDate
                    };
                    Database.ProjectVersion.Add(version);

                    ProjectActivity activity = new ProjectActivity
                    {
                        ProjectId = project.Id,
                        AuthorId  = userId,
                        Content   = $"Project created"
                    };
                    Database.ProjectActivity.Add(activity);

                    await Database.SaveChangesAsync();

                    return(RedirectToAction("Index", new { projectUrl = project.Url }));
                }
                else
                {
                    ModelState.AddModelError("Url", "Such url is taken.");
                }
            }

            return(View(model));
        }
示例#26
0
        public static bool Delete(ProjectAssignment ProjectAssignment)
        {
            SqlConnection connection      = PMMSData.GetConnection();
            string        deleteProcedure = "[ProjectAssignmentDelete]";
            SqlCommand    deleteCommand   = new SqlCommand(deleteProcedure, connection);

            deleteCommand.CommandType = CommandType.StoredProcedure;
            deleteCommand.Parameters.AddWithValue("@OldProjectAssignmentID", ProjectAssignment.ProjectAssignmentID);
            deleteCommand.Parameters.AddWithValue("@OldProjectID", ProjectAssignment.ProjectID);
            deleteCommand.Parameters.AddWithValue("@OldEmployeeID", ProjectAssignment.EmployeeID);
            deleteCommand.Parameters.AddWithValue("@OldAssignmentDate", ProjectAssignment.AssignmentDate);
            if (ProjectAssignment.Remarks != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldRemarks", ProjectAssignment.Remarks);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldRemarks", DBNull.Value);
            }
            deleteCommand.Parameters.AddWithValue("@OldAddUserID", ProjectAssignment.AddUserID);
            deleteCommand.Parameters.AddWithValue("@OldAddDate", ProjectAssignment.AddDate);
            if (ProjectAssignment.ArchiveUserID.HasValue == true)
            {
                deleteCommand.Parameters.AddWithValue("@OldArchiveUserID", ProjectAssignment.ArchiveUserID);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldArchiveUserID", DBNull.Value);
            }
            if (ProjectAssignment.ArchiveDate.HasValue == true)
            {
                deleteCommand.Parameters.AddWithValue("@OldArchiveDate", ProjectAssignment.ArchiveDate);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldArchiveDate", DBNull.Value);
            }
            deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
            deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
            try
            {
                connection.Open();
                deleteCommand.ExecuteNonQuery();
                int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException)
            {
                return(false);
            }
            finally
            {
                connection.Close();
            }
        }
示例#27
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;
    }