public ActionResult ContributeIdea(AmbassProjectViewModel idea) { //User role security check int role = (int)HttpContext.Session["userRole"]; //Ensure user is contributor if (role == UserRole.AMBASSADOR) { //Input checks if (idea == null) /* do something *** */ } { if (ModelState.IsValid) { //If commit(idea) is successful it returns true if (ambassador.SubmitProject(idea)) { return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_AMBASSADOR_HOME)); } else { //Gracefully indicate that project submission was unsuccessful *** } } else { //Gracefully indicate error *** } return(View(idea)); }
//Func Desc: Used to return a project from its id. // Input: Int representing id of project to locate. // Output: An instance of the project that has the specified id, or null public object GetProject(int?project_id) //Should this be nullable? *** { //Input checks if (project_id == null) { return(null); } if (project_id < 0) { return(null); } using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); if (this.GetType() == typeof(AdminAccess)) { //Map located project to project view model AdminProjectViewModel vm_project = (AdminProjectViewModel)mapper.Map(context.Projects.Find(project_id), typeof(AdminProjectViewModel)); //Return project with given id or null return(vm_project); } else if (this.GetType() == typeof(AmbassadorAccess)) { //Map located project to project view model AmbassProjectViewModel vm_project = (AmbassProjectViewModel)mapper.Map(context.Projects.Find(project_id), typeof(AmbassProjectViewModel)); //Make sure project isn't archived if (vm_project.IsArchived == true) { return(null); } //Return project with given id or null return(vm_project); } else if (this.GetType() == typeof(ContributorAccess)) { //Map located project to project view model ContributorProjectViewModel vm_project = (ContributorProjectViewModel)mapper.Map(context.Projects.Find(project_id), typeof(ContributorProjectViewModel)); //Make sure project isn't archived if (vm_project.IsArchived == true) { return(null); } //Return project with given id or null return(vm_project); } else if (this.GetType() == typeof(DefaultAccess)) { //Map located project to project view model ProjectViewModel vm_project = (ProjectViewModel)mapper.Map(context.Projects.Find(project_id), typeof(ProjectViewModel)); //Make sure project isn't archived if (vm_project.IsArchived == true) { return(null); } //Return project with given id or null return(vm_project); } else { //Invalid access object Debug.WriteLine("\n\n***** " + "Access object type wasn't recognized during GetProject(). " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess GetProject()" + "*****\n\n"); return(null); } } }
//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); } } }