//Func Desc: Used to delete project idea. Admin function. // Input: The id of the project to delete // Output: Bool indicating deletion status. T = successful deletion, F = failure to delete. public bool DeleteProject(int? project_id) { if (project_id == null) { return false; } try { Project domain_model = new Project(); using (var context = new MainDBEntities()) { domain_model = context.Projects.Find(project_id); IEnumerable<ProjectAssignment> dependent_projects = context.ProjectAssignments.Where( x => x.ProjectID == project_id ); if (dependent_projects != null) { foreach (ProjectAssignment assignment in dependent_projects.ToList()) { //Remove project context.ProjectAssignments.Remove(assignment); } context.SaveChanges(); } context.Projects.Remove(domain_model); context.SaveChanges(); //Indicate delete success return true; } } catch { //Indicate deletion failure return false; } }
//Func Desc: Used to submit project idea // Input: A ProjectView instance // Output: Bool indicating submission status. T = successful submission, F = failure to submit. public bool SubmitProject(object new_project) { //Input checks if (new_project == null) { return false; } using(var context = new MainDBEntities()) { //Determine response based on access privilages if (this.GetType() == typeof(AdminAccess)) // IF ADMINISTRATOR { try { //Cast object to admin project view model type AdminProjectViewModel admin_project = (AdminProjectViewModel)new_project; //Create new project instance Project proj = new Project(); //Transfer necessary values proj.ProjectName = admin_project.ProjectName; proj.ProjectDesc = admin_project.ProjectDesc; proj.BusinessJustification = admin_project.BusinessJustification; proj.Username = admin_project.Username; proj.Status = IdeaStatus.SUBMITTED; proj.IsArchived = false; //Not yet archived proj.PostDate = DateTime.Now; proj.AssignDate = null; proj.FinishDate = null; //Submit the project to the db context.Projects.Add(proj); //Save changes context.SaveChanges(); //Indicate successful submission return true; } catch { //Return false indicating failure to submit project return false; } } else if (this.GetType() == typeof(AmbassadorAccess)) { try { //Cast object to contributor project view model type AmbassProjectViewModel contributor_project = (AmbassProjectViewModel)new_project; //Create new project instance Project proj = new Project(); //Transfer necessary values proj.ProjectName = contributor_project.ProjectName; proj.ProjectDesc = contributor_project.ProjectDesc; proj.BusinessJustification = contributor_project.BusinessJustification; proj.Username = contributor_project.Username; proj.Status = IdeaStatus.SUBMITTED; proj.IsArchived = false; //Not yet archived proj.PostDate = DateTime.Now; proj.AssignDate = null; proj.FinishDate = null; //Submit the project to the db context.Projects.Add(proj); //Save changes context.SaveChanges(); //Indicate successful submission return true; } catch { //Return false indicating failure to submit project return false; } } else if (this.GetType() == typeof(ContributorAccess)) { try { // ContributorProjectViewModel contributor_project = (ContributorProjectViewModel)new_project; //Create new project instance Project proj = new Project(); //Transfer necessary values proj.ProjectName = contributor_project.ProjectName; proj.ProjectDesc = contributor_project.ProjectDesc; proj.BusinessJustification = contributor_project.BusinessJustification; proj.Username = contributor_project.Username; proj.Status = IdeaStatus.SUBMITTED; proj.IsArchived = false; //Not yet archived proj.PostDate = DateTime.Now; proj.AssignDate = null; proj.FinishDate = null; //Submit the project to the db context.Projects.Add(proj); //Save changes context.SaveChanges(); //Indicate successful submission return true; } catch { //Return false indicating failure to submit project return false; } } else { //Access object not recognized Debug.WriteLine("\n\n***** " + "Access object type wasn't recognized during SubmitProject(). " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess SubmitProject()" + "*****\n\n"); //Indicate error return false; } } }