Exemple #1
0
        public ActionResult Change(FullFlowModel model)
        {
            User user = (User)Session["users"];

            if (user == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            NH.NHibernateOperation operation = new NH.NHibernateOperation();

            string id   = (string)RouteData.Values["id"];
            int    f    = Int32.Parse(id);
            Flow   flow = operation.FindFlowById(f);

            Position p = operation.FindPositionById(flow.id_position.Id_position);

            ViewBag.Pos = p.Id_position;
            Step step = operation.FindStep(p);

            ViewBag.Model = model;

            if (step != null)
            {
                flow.id_position = step.End_position_id;

                String cond = step.Condition;
                if (cond != null)
                {
                    Parser   parser = new Parser();
                    string[] list   = parser.Parse(cond);
                    Dictionary <string, string> dict = new Dictionary <string, string>();

                    foreach (FlowModel <string> mdl in model.list)
                    {
                        dict.Add(mdl.name, mdl.value);
                    }
                    foreach (FlowModel <int> mdl in model.list_int)
                    {
                        dict.Add(mdl.name, mdl.value.ToString());
                    }

                    List <bool>   bool_list = new List <bool>();
                    List <string> sign      = new List <string>();
                    foreach (string s in list)
                    {
                        string temp  = s;
                        char   start = s[0];
                        char   end   = s[s.Length - 1];
                        string str   = "";
                        string en    = "";

                        if (start.Equals("|") || start.Equals("&"))
                        {
                            temp = s.Substring(2, s.Length - 2);
                            str  = "" + start + start;
                            sign.Add(str);
                        }
                        if (end.Equals("|") || end.Equals("&"))
                        {
                            temp = temp.Substring(0, temp.Length - 2);
                            en   = "" + end + end;
                            sign.Add(en);
                        }

                        bool result = parser.checkBracket(temp, dict);
                        bool_list.Add(result);
                    }

                    bool wynik = bool_list[0];
                    for (int i = 0; i < sign.Count; i++)
                    {
                        if (sign.Equals("||"))
                        {
                            wynik = wynik || bool_list[i + 1];
                        }
                        else
                        {
                            wynik = wynik && bool_list[i + 1];
                        }
                    }

                    if (wynik == true)
                    {
                        MailController mm = new MailController();


                        IList <Task> tasks = operation.GetTasksByPositionId(step.End_position_id);
                        foreach (Task t in tasks)
                        {
                            ModelMail mdl = new ModelMail();
                            mdl.from = "*****@*****.**";
                            User us = operation.GetUserById(t.Id_user.Id_user);
                            mdl.to      = us.Email;
                            mdl.subject = "Nowe zadanie";
                            mdl.value   = " Masz nowe zadanie wejdz na konto i sprawdz";
                            mm.sendMail(mdl);
                        }
                        //AddElements(flow, model);
                        //operation.Update<Flow>(flow);
                    }
                    // JESLI NIE SPELNI WARUNKOW TO ROB CO INNEGO
                }
                else
                {
                    MailController mm    = new MailController();
                    IList <Task>   tasks = operation.GetTasksByPositionId(step.End_position_id);
                    foreach (Task t in tasks)
                    {
                        ModelMail mdl = new ModelMail();
                        mdl.from = "*****@*****.**";
                        User us = operation.GetUserById(t.Id_user.Id_user);
                        mdl.to      = us.Email;
                        mdl.subject = "Nowe zadanie";
                        mdl.value   = " Masz nowe zadanie wejdz na konto i sprawdz";
                        mm.sendMail(mdl);
                    }
                    //AddElements(flow, model);
                    //operation.Update<Flow>(flow);
                }
            }
            else
            {
                flow.id_position = null;
                //AddElements(flow, model);
                //operation.Update<Flow>(flow);
            }
            return(View());
        }