Ejemplo n.º 1
0
        public static void CreateFeedItem(string feedText, int userId)
        {
            MySqlCommand cmd = new MySqlCommand("INSERT INTO ActivityFeed (FeedItemText, UserID) VALUES (@feedText, @userId)");

            cmd.Parameters.AddWithValue("@feedText", feedText);
            cmd.Parameters.AddWithValue("@userId", userId);
            DBConn conn = new DBConn();

            conn.ExecuteInsertCommand(cmd);
            conn.CloseConnection();
            UserUtil.SendEmail(userId, feedText);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }