Пример #1
0
 public IEnumerable <TasksModel> GetEnd(DateTime end)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(entities.Tasks.Where(i => i.date_end == end).ToList().Select(c => modelFactory.Create(c)));
     }
 }
Пример #2
0
 public IEnumerable <BranchesModel> GetCreator(int c_id)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(entities.Branches.Where(i => i.creator_id == c_id).ToList().Select(c => modelFactory.Create(c)));
     }
 }
Пример #3
0
 public UsersModel Get(string username, string password)
 {
     using (TaskManagerDBEntities ctx = new TaskManagerDBEntities())
     {
         return(modelFactory.Create(ctx.Users.Where(i => i.username.Equals(username)).Where(i => i.password.Equals(password)).FirstOrDefault()));
     }
 }
Пример #4
0
 public IEnumerable <TasksModel> GetStatus(string status)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(entities.Tasks.Where(i => i.status.Equals(status)).ToList().Select(c => modelFactory.Create(c)));
     }
 }
Пример #5
0
 public UsersModel Get(int ID)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(modelFactory.Create(entities.Users.Where(i => i.id == ID).FirstOrDefault()));
     }
 }
Пример #6
0
 public IEnumerable <TasksModel> GetExecutor(int e_id)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(entities.Tasks.Where(i => i.executor_id == e_id).ToList().Select(c => modelFactory.Create(c)));
     }
 }
Пример #7
0
 public IEnumerable <BranchesModel> GetBegin(DateTime begin)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(entities.Branches.Where(i => i.created_date.Equals(begin)).ToList().Select(c => modelFactory.Create(c)));
     }
 }
Пример #8
0
 public TasksModel GetName(string name)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(modelFactory.Create(entities.Tasks.Where(i => i.taskname.Equals(name)).FirstOrDefault()));
     }
 }
Пример #9
0
 public TasksModel GetId(int id)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         return(modelFactory.Create(entities.Tasks.Where(i => i.id == id).FirstOrDefault()));
     }
 }
Пример #10
0
 public bool Post(Tasks task)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if (entities.Tasks.Where(t => t.taskname.Equals(task.taskname)).FirstOrDefault() != null)
         {
             return(false);
         }
         entities.Tasks.Add(task);
         entities.SaveChanges();
         return(true);
     }
 }
Пример #11
0
 public bool Post(Users user)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if (entities.Users.Where(t => t.username.Equals(user.username)).Where(t => t.password.Equals(user.password)).FirstOrDefault() != null)
         {
             return(false);
         }
         entities.Users.Add(new Users {
             username = user.username, password = user.password
         });
         entities.SaveChanges();
         return(true);
     }
 }
Пример #12
0
 public bool Post(Branches branch)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if (entities.Branches.Where(b => b.branchname.Equals(branch.branchname)).FirstOrDefault() != null)
         {
             return(false);
         }
         entities.Branches.Add(new Branches {
             branchname = branch.branchname, description = branch.description, creator_id = branch.creator_id, created_date = branch.created_date
         });
         entities.SaveChanges();
         return(true);
     }
 }
Пример #13
0
 public bool Delete(Users userDel)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if ((entities.UserBranch.Where(u => u.user_id == userDel.id).FirstOrDefault() != null) || (entities.UserTask.Where(u => u.user_id == userDel.id).FirstOrDefault() != null))
         {
             return(false);
         }
         if (userDel != null)
         {
             entities.Users.Remove(userDel);
             entities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Пример #14
0
 public bool Delete(Tasks taskDel)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if ((entities.TaskBranch.Where(i => i.task_id == taskDel.id).FirstOrDefault() != null) || (entities.UserTask.Where(i => i.task_id == taskDel.id).FirstOrDefault() != null))
         {
             return(false);
         }
         Tasks task = entities.Tasks.Where(i => i.taskname.Equals(taskDel.taskname)).FirstOrDefault();
         if (task != null)
         {
             entities.Tasks.Remove(task);
             entities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Пример #15
0
 public bool Delete(Branches branchDel)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         if ((entities.UserBranch.Where(i => i.branch_id == branchDel.id).FirstOrDefault() != null) || (entities.TaskBranch.Where(i => i.branch_id == branchDel.id).FirstOrDefault() != null))
         {
             return(false);
         }
         Branches branch = entities.Branches.Where(i => i.branchname == branchDel.branchname).FirstOrDefault();
         if (branch != null)
         {
             entities.Branches.Remove(branch);
             entities.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Пример #16
0
 public bool SetTB(int t_id, int b_id)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         try
         {
             if (entities.TaskBranch.Where(i => i.task_id == t_id).Where(i => i.branch_id == b_id).FirstOrDefault() != null)
             {
                 return(false);
             }
             entities.TaskBranch.Add(new TaskBranch {
                 task_id = t_id, branch_id = b_id
             });
             entities.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
Пример #17
0
 public bool SetTU(int t_id, int u_id)
 {
     using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
     {
         try
         {
             if (entities.UserTask.Where(i => i.task_id == t_id).Where(t => t.user_id == u_id).FirstOrDefault() != null)
             {
                 return(false);
             }
             entities.UserTask.Add(new UserTask {
                 task_id = t_id, user_id = u_id
             });
             entities.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
Пример #18
0
        public string Get(CallbackData update)
        {
            if (update.@event == "webhook")
            {
                //SendMessage(update.sender.id, "Hello, newcomer!");
            }
            else if (update.@event == "conversation_started")
            {
                SendMessage(update.sender.id, "Hello, your conversation with bot has just started!");
            }
            else if (update.@event == "subscribed")
            {
            }
            else if (update.@event == "unsubscribed")
            {
            }
            else if (update.@event == "delivered")
            {
            }
            else if (update.@event == "seen")
            {
            }
            else if (update.@event == "failed")
            {
            }
            #region Message
            else
            if (update.@event == "message")
            {
                if (Logic.isFilter && Logic.isFilterParameter)
                {
                    if (update.message.text == "Back")
                    {
                        /*if (Logic.isGetUsers)
                         * {
                         *  Logic.isGetUsers = false;
                         * }
                         * else if (Logic.isGetBranches)
                         * {
                         *  Logic.isGetBranches = false;
                         * }
                         * else if (Logic.isGetTasks)
                         * {
                         *  Logic.isGetTasks = false;
                         * }*/
                        Logic.isFilter          = false;
                        Logic.isFilterParameter = false;
                        return("");
                    }
                    else
                    {
                        Regex rxUID = new Regex(@"(ID)\s.*");
                        Regex rxUs  = new Regex(@"(Username)\s.*");
                        Regex rxBN  = new Regex(@"(Branchname)\s.*");
                        Regex rxCA  = new Regex(@"(CreatedAt)\s.*");
                        Regex rxCID = new Regex(@"(CreatorId)\s.*");
                        using (TaskManagerDBEntities entities = new TaskManagerDBEntities())
                        {
                            Match          m1   = rxUID.Match(update.message.text);
                            Match          m2   = rxUs.Match(update.message.text);
                            Match          m3   = rxBN.Match(update.message.text);
                            Match          m4   = rxCA.Match(update.message.text);
                            Match          m5   = rxCID.Match(update.message.text);
                            DataRepository data = new DataRepository();
                            string         text = update.message.text.Replace(" ", String.Empty);
                            if (m1.Success)
                            {
                                string param   = text.Substring(2, text.Length - 2);
                                int    ID      = Convert.ToInt32(param);
                                string message = ConvertUsers(modelFactory.Create(entities.Users.Where(i => i.id == ID).FirstOrDefault()));
                                SendMessage(update.sender.id, message);
                            }
                            else if (m2.Success)
                            {
                                string param   = text.Substring(8, text.Length - 8);
                                string message = ConvertUsers(modelFactory.Create(entities.Users.Where(i => i.username == param).FirstOrDefault()));
                                SendMessage(update.sender.id, message);
                            }
                            else if (m3.Success)
                            {
                                string param   = text.Substring(10, text.Length - 10);
                                string message = ConvertBranches(modelFactory.Create(entities.Branches.Where(i => i.branchname == param).FirstOrDefault()));
                                SendMessage(update.sender.id, message);
                            }
                            else if (m4.Success)
                            {
                                string param = text.Substring(9, text.Length - 9);

                                if (Logic.isGetTasks)
                                {
                                    string message = ConvertTasks(data.GetTaskViaBeginTime(Convert.ToDateTime(param)).ToList().Select(c => modelFactory.Create(c)));
                                    SendMessage(update.sender.id, message);
                                }
                                else if (Logic.isGetBranches)
                                {
                                    string message = ConvertBranches(data.GetBranchesViaBeginTime(Convert.ToDateTime(param)).ToList().Select(c => modelFactory.Create(c)));
                                    SendMessage(update.sender.id, message);
                                }
                            }
                            else if (m5.Success)
                            {
                                string param = text.Substring(9, text.Length - 9);
                                int    ID    = Convert.ToInt32(param);
                                if (Logic.isGetTasks)
                                {
                                    string message = ConvertTasks(data.GetTaskViaCreatorID(ID).ToList().Select(c => modelFactory.Create(c)));
                                    SendMessage(update.sender.id, message);
                                }
                                else if (Logic.isGetBranches)
                                {
                                    string message = ConvertBranches(data.GetBranchesViaCreatorID(ID).ToList().Select(c => modelFactory.Create(c)));
                                    SendMessage(update.sender.id, message);
                                }
                            }
                        }
                        SendMessage(update.sender.id, "Print Back to return");
                        return("");
                    }
                }

                else if ((Logic.isGetUsers || Logic.isGetBranches || Logic.isGetTasks) && Logic.isFilter)
                {
                    string s   = "";
                    string tmp = "";
                    if (Logic.isGetUsers)
                    {
                        s   = "Users";
                        tmp = "ID, Username";
                    }
                    else if (Logic.isGetBranches)
                    {
                        s   = "Branches";
                        tmp = "Branchname, CreatedAt, CreatorId";
                    }
                    else if (Logic.isGetTasks)
                    {
                        s   = "Tasks";
                        tmp = "CreatorId, CreatedAt, FinishAt, Description, Status, ExecutorId";
                    }
                    Logic.isFilterParameter = true;
                    SendMessage(update.sender.id, "Possible parameters for filtering are: " + tmp + "\\n"
                                + "Print Back to return, or enter the name of parameter, " + "\\n"
                                + "Print name and parameter and value (w whitespace) to search");
                }

                else if (Logic.isGet && Logic.isGetTasks)
                {
                    if (update.message.text == "All")
                    {
                        DataRepository repository = new DataRepository();
                        var            data       = repository.GetAllTasks().ToList().Select(c => modelFactory.Create(c));
                        //sb.Append(data.ElementAt(0).username);
                        //JsonConvert.SerializeObject(new { sb = sb });
                        string message = ConvertTasks(data);
                        SendMessage(update.sender.id, message);
                        return("");
                    }
                    else if (update.message.text == "Filter")
                    {
                        //Logic.isFilterParameter = true;
                        SendMessage(update.sender.id, "Oops");
                        return("");
                    }
                    else if (update.message.text == "Back")
                    {
                        Logic.isGetTasks = false;
                        Logic.isGet      = false;
                        SendMessage(update.sender.id, "If you want to get data from database, print Get + Users|Branches|Tasks; " + "\\n"
                                    + "if you want to Post new data into database, print Post + Users|Branches|Tasks; " + "\\n"
                                    + "if you need help, print Help; ");
                        return("");
                    }
                    else
                    {
                        SendMessage(update.sender.id, "Print All to get all data from Branches table, print Filter to start filtering, print Back to return ");
                        return("");
                    }
                }

                else if (Logic.isGet && Logic.isGetBranches)
                {
                    if (update.message.text == "All")
                    {
                        DataRepository repository = new DataRepository();
                        var            data       = repository.GetAllBranches().ToList().Select(c => modelFactory.Create(c));
                        //sb.Append(data.ElementAt(0).username);
                        //JsonConvert.SerializeObject(new { sb = sb });
                        string message = ConvertBranches(data);
                        SendMessage(update.sender.id, message);
                        return("");
                    }
                    else if (update.message.text == "Filter")
                    {
                        Logic.isFilter = true;
                        SendMessage(update.sender.id, "Press any key");
                        return("");
                    }
                    else if (update.message.text == "Back")
                    {
                        Logic.isGetBranches = false;
                        Logic.isGet         = false;
                        SendMessage(update.sender.id, "If you want to get data from database, print Get + Users|Branches|Tasks; " + "\\n"
                                    + "if you want to Post new data into database, print Post + Users|Branches|Tasks; " + "\\n"
                                    + "if you need help, print Help; ");
                        return("");
                    }
                    else
                    {
                        SendMessage(update.sender.id, "Print All to get all data from Branches table, print Filter to start filtering, print Back to return ");
                        return("");
                    }
                }

                else if (Logic.isGet && Logic.isGetUsers)
                {
                    if (update.message.text == "All")
                    {
                        DataRepository repository = new DataRepository();
                        var            data       = repository.GetAllUsers().ToList().Select(c => modelFactory.Create(c));
                        //sb.Append(data.ElementAt(0).username);
                        //JsonConvert.SerializeObject(new { sb = sb });
                        string message = ConvertUsers(data);
                        SendMessage(update.sender.id, message);
                        return("");
                    }
                    else if (update.message.text == "Filter")
                    {
                        Logic.isFilter = true;
                        SendMessage(update.sender.id, "Press any key");
                        return("");
                    }
                    else if (update.message.text == "Back")
                    {
                        Logic.isGetUsers = false;
                        Logic.isGet      = false;
                        SendMessage(update.sender.id, "If you want to get data from database, print Get + Users|Branches|Tasks; " + "\\n"
                                    + "if you want to Post new data into database, print Post + Users|Branches|Tasks; " + "\\n"
                                    + "if you need help, print Help; ");
                        return("");
                    }
                    else
                    {
                        SendMessage(update.sender.id, "Print All to get all data from Users table, print Filter to start filtering, print Back to return ");
                        return("");
                    }
                }

                /*else if (Logic.isGet)
                 * {
                 *
                 *
                 *  if (update.message.text == "Users")
                 *  {
                 *      Logic.isGetUsers = true;
                 *      SendMessage(update.sender.id, "Print All to get all data from Users table, print Filter to start filtering, print Back to return ");
                 *      return "";
                 *  }
                 *  else if (update.message.text == "Branches")
                 *  {
                 *      Logic.isGetBranches = true;
                 *      SendMessage(update.sender.id, "Print All to get all data from Branches table, print Filter to start filtering, print Back to return ");
                 *      return "";
                 *  }
                 *  else if (update.message.text == "Tasks")
                 *  {
                 *      Logic.isGetTasks = true;
                 *      SendMessage(update.sender.id, "Print All to get all data from Tasks table, print Filter to start filtering, print Back to return ");
                 *      return "";
                 *  }
                 *  else if (update.message.text == "Back")
                 *  {
                 *      Logic.isGet = false;
                 *      return "";
                 *  }
                 *
                 *
                 *  else SendMessage(update.sender.id, "Please, print what kind of data do you want to work with: Users, Branches, Tasks, or print Back to get back");
                 * }*/

                else if (!Logic.isGet && !Logic.isPost)
                {
                    Regex mGUser     = new Regex(@"(Get)\s(Users)");
                    Regex mGBranches = new Regex(@"(Get)\s(Branches)");
                    Regex mGTasks    = new Regex(@"(Get)\s(Tasks)");
                    Regex mPUser     = new Regex(@"(Post)\s(Users)");
                    Regex mPBranches = new Regex(@"(Post)\s(Branches)");
                    Regex mPTasks    = new Regex(@"(Post)\s(Tasks)");

                    Match mUg = mGUser.Match(update.message.text);
                    Match mBg = mGBranches.Match(update.message.text);
                    Match mTg = mGTasks.Match(update.message.text);
                    Match mUp = mPUser.Match(update.message.text);
                    Match mBp = mPBranches.Match(update.message.text);
                    Match mTp = mPTasks.Match(update.message.text);

                    if (mUg.Success)
                    {
                        Logic.isGetUsers = true;
                    }
                    else if (mBg.Success)
                    {
                        Logic.isGetBranches = true;
                    }
                    else if (mTg.Success)
                    {
                        Logic.isGetTasks = true;
                    }
                    if (mUg.Success || mBg.Success || mTg.Success)
                    {
                        Logic.isGet = true;
                        SendMessage(update.sender.id, "Print All to get all data from table, print Filter to start filtering, print Back to return ");
                        return("");
                    }
                    else if (mUp.Success || mBp.Success || mTp.Success)
                    {
                        Logic.isPost = true;
                        return("");
                    }
                    else
                    {
                        SendMessage(update.sender.id, "If you want to get data from database, print Get + Users|Branches|Tasks; " + "\\n"
                                    + "if you want to Post new data into database, print Post + Users|Branches|Tasks; " + "\\n"
                                    + "if you need help, print Help; ");
                    }
                    return("");
                }
                else
                {
                    return("");
                }

                //else SendMessage(update.sender.id, "Wrong command, please, print HELP to get info about posible actions. ");
            }
            #endregion Message
            else
            {
            }

            return("");
        }