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; } } }
public bool UpdateActiveStatusToProduction(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.PRODUCTION; //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; } } }
//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; } }