public ActionResult AddFile(ContributorProjectViewModel cur_project, HttpPostedFileBase new_file) { //User role security check int role = (int)HttpContext.Session["userRole"]; //Ensure user is contributor if (role == UserRole.CONTRIBUTOR) { //Function body foreach (string file_name in Request.Files) { if ((Request.Files[file_name] != null) && (Request.Files[file_name].ContentLength > 0)) { string path = AppDomain.CurrentDomain.BaseDirectory + "/uploads/"; string filename = Path.GetFileName(Request.Files[file_name].FileName); Request.Files[file_name].SaveAs(Path.Combine(path, filename)); return(RedirectToAction(ActionName.AN_CONTRIBUTE_IDEA, PermissionSpace.PS_CONTRIBUTOR_HOME)); } else { // *** Handle issue gracefully return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(View()); } else if (role == UserRole.ADMIN) { //Output error message box *** REWRITE ERROR MESSAGES *** MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "edit and, unfortunately, your edit will be lost. " + "Please re-submit your edit after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct return(RedirectToAction(ActionName.AN_ADD_FILE, PermissionSpace.PS_ADMIN_HOME)); } else if (role == UserRole.AMBASSADOR) { //Output error message box MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "edit and, unfortunately, your edit will be lost. " + "Please re-submit your edit after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct return(RedirectToAction(ActionName.AN_ADD_FILE, PermissionSpace.PS_AMBASSADOR_HOME)); } else { //Redirect to correct return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_DEFAULT_HOME)); } }
public ActionResult ContributeIdea(ContributorProjectViewModel idea) { //User role security check int role = (int)HttpContext.Session["userRole"]; //Ensure user is contributor if (role == UserRole.CONTRIBUTOR) { if (ModelState.IsValid) { //If commit(idea) is successful it returns true if (contributor_access.SubmitProject(idea)) { return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_CONTRIBUTOR_HOME)); } else { //Gracefully indicate that project submission was unsuccessful *** } } return(View(idea)); } else if (role == UserRole.ADMIN) { //Output error message box MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "submission and, unfortunately, your idea will be lost. " + "Please re-submit your idea after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct index return(RedirectToAction(ActionName.AN_CONTRIBUTE_IDEA, PermissionSpace.PS_ADMIN_HOME)); } else if (role == UserRole.AMBASSADOR) { //Output error message box MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "submission and, unfortunately, your idea will be lost. " + "Please re-submit your idea after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct index return(RedirectToAction(ActionName.AN_CONTRIBUTE_IDEA, PermissionSpace.PS_AMBASSADOR_HOME)); } else { //Redirect to correct index return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_DEFAULT_HOME)); } }
public ActionResult EditIdea([Bind(Include = "ProjectID,ProjectName,ProjectDesc,BusinessJustification,PostDate,Username,IsArchived")] ContributorProjectViewModel proj) { //User role security check int role = (int)HttpContext.Session["userRole"]; //Ensure user is contributor if (role == UserRole.CONTRIBUTOR) { if (ModelState.IsValid) { //Edit the project contributor_access.EditProject(proj); return(RedirectToAction("Index", "ContributorHome")); } return(View(proj)); } else if (role == UserRole.ADMIN) { //Output error message box MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "edit and, unfortunately, your edit will be lost. " + "Please re-submit your edit after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct return(RedirectToAction(ActionName.AN_EDIT_IDEA, PermissionSpace.PS_ADMIN_HOME, new { id = proj.ProjectID })); } else if (role == UserRole.AMBASSADOR) { //Output error message box MessageBox.Show(" :-( We're extremely sorry about the inconvenience! " + "There was an error while processing your " + "edit and, unfortunately, your edit will be lost. " + "Please re-submit your edit after we redirect you. ", Popups.POP_UP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); //Redirect to correct return(RedirectToAction(ActionName.AN_EDIT_IDEA, PermissionSpace.PS_AMBASSADOR_HOME, new { id = proj.ProjectID })); } else { //Redirect to correct return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_DEFAULT_HOME)); } }
public ActionResult ViewIdea(int?id) { //User role security check int role = (int)HttpContext.Session["userRole"]; //Ensure user is contributor if (role == UserRole.CONTRIBUTOR) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //Retrieve project view model ContributorProjectViewModel proj = (ContributorProjectViewModel)contributor_access.GetProject(id); //If project found is null if (proj == null) { return(HttpNotFound()); } return(View(proj)); } else if (role == UserRole.ADMIN) { //Redirect to correct index return(RedirectToAction(ActionName.AN_VIEW_IDEA, PermissionSpace.PS_ADMIN_HOME, new { id = id })); } else if (role == UserRole.AMBASSADOR) { //Redirect to correct index return(RedirectToAction(ActionName.AN_VIEW_IDEA, PermissionSpace.PS_AMBASSADOR_HOME, new { id = id })); } else { //Redirect to correct index return(RedirectToAction(ActionName.AN_INDEX, PermissionSpace.PS_DEFAULT_HOME)); } }
//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); } } }