public static Form SubmitForm(int formId, string formName, string formData) { string defaultApproved = "0"; string defaultDenied = "0"; Form f = GetForm(formId); Form ft = GetFormTemplate(f.FormTemplateId); string[] approvalIDs = new string[0]; if (ft.ApproverIDs.Length > 0) { approvalIDs = ft.ApproverIDs.Split(','); } if (approvalIDs.Length > 0) { int i = 0; foreach (string roleID in approvalIDs) { if (i != 0) { defaultApproved += ",0"; defaultDenied += ",0"; } i++; } } f.FormName = formName; f.FormData = formData; MySqlCommand cmd = new MySqlCommand("UPDATE Forms SET FormName=@formName, FormData=@formData, Submission=1, Approved=@approved, Denied=@denied, DenialReason=\"\" WHERE FormID=@formId"); cmd.Parameters.AddWithValue("@formName", formName); cmd.Parameters.AddWithValue("@formData", formData); cmd.Parameters.AddWithValue("@formId", formId); cmd.Parameters.AddWithValue("@denied", defaultDenied); cmd.Parameters.AddWithValue("@approved", defaultApproved); DBConn conn = new DBConn(); conn.ExecuteInsertCommand(cmd); conn.CloseConnection(); Project p = ProjectUtil.GetProject(f.ProjectId); FeedUtil.CreateProjectFormFeedItem(p.Name + " has form " + formName + " ready for your approval", p.CoachId, p.ProjectId, formId); return(f); }
public static Project CreateProject(string name, int workflowId, int companyId, int coachId, string notes) { Project p = new Project(workflowId, companyId, 0, coachId, name, notes); MySqlCommand cmd = new MySqlCommand("INSERT INTO Project (WorkflowID, CompanyID, StatusID, CoachID, ProjectName, ProjectNotes) VALUES (@workflowId, @companyId, @statusId, @coachId, @name, @notes)"); cmd.Parameters.AddWithValue("@workflowId", workflowId); cmd.Parameters.AddWithValue("@companyId", companyId); cmd.Parameters.AddWithValue("@statusId", 0); cmd.Parameters.AddWithValue("@coachId", coachId); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@notes", notes); DBConn conn = new DBConn(); p.ProjectId = conn.ExecuteInsertCommand(cmd); //creates notification for the coach FeedUtil.CreateProjectFeedItem("Added as a coach for " + name, coachId, p.ProjectId); List <WorkflowComponent> workflowComponents = WorkflowComponentUtil.GetWorkflowComponents(workflowId); foreach (WorkflowComponent wc in workflowComponents) { //create completion status and forms for the project if (wc.FormID != -1) { Form f = FormUtil.CreateForm(wc.FormID, p.ProjectId); //creates notifications for each member of the company and each form List <User> clients = UserUtil.GetClients(companyId); foreach (User client in clients) { FeedUtil.CreateProjectFormFeedItem("Form " + f.FormName + " needs completion for " + name, client.UserId, p.ProjectId, f.FormId); } } } conn.CloseConnection(); return(p); }
public static Form DenyForm(int formId, string denialReason, int roleId) { Form f = GetForm(formId); Form ft = GetFormTemplate(f.FormTemplateId); int denialItemCt = -1; string[] approvalIDs = new string[0]; if (ft.ApproverIDs.Length > 0) { approvalIDs = ft.ApproverIDs.Split(','); } if (approvalIDs.Length > 0) { int i = 0; foreach (string roleID in approvalIDs) { int userRoleID = int.Parse(roleID); //if they are one of the users who needs to approve the form if (userRoleID == roleId) { denialItemCt = i; } i++; } } if (denialItemCt != -1) { string newDenial = ""; string[] currentDenial = f.Denied.Split(','); if (currentDenial.Length > denialItemCt) { int i = 0; foreach (string approval in currentDenial) { if (i == denialItemCt) { newDenial += "1"; } else { newDenial += currentDenial[i]; } i++; if (i != currentDenial.Length) { newDenial += ","; } } } MySqlCommand cmd = new MySqlCommand("UPDATE Forms SET Denied=@denied, DenialReason=@denialReason, Submission=0 WHERE FormID=@formId"); cmd.Parameters.AddWithValue("@denialReason", denialReason); cmd.Parameters.AddWithValue("@formId", formId); cmd.Parameters.AddWithValue("@denied", newDenial); DBConn conn = new DBConn(); conn.ExecuteInsertCommand(cmd); conn.CloseConnection(); Project p = ProjectUtil.GetProject(f.ProjectId); //notify all clients of the approval List <User> clients = UserUtil.GetClients(p.CompanyId); foreach (User client in clients) { FeedUtil.CreateProjectFormFeedItem(f.FormName + " was denied by " + UserUtil.GetCoachName(p.CoachId) + " for " + denialReason, client.UserId, p.ProjectId, formId); } } return(f); }