Example #1
0
        public void Count_Users_Storage_InMemory_Tests_Method()
        {
            InMemoryStorage inMemoryStorage = new InMemoryStorage();

            DomainUserItem user = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = DateTimeOffset.Now,
                FirstName          = "Null",
                Id      = Guid.NewGuid(),
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user);
            List <IDomainUserItem> userItems = inMemoryStorage.GetUsers();

            Assert.AreEqual(1, userItems.Count);

            DomainUserItem user_2 = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = DateTimeOffset.Now,
                FirstName          = "Null",
                Id      = Guid.NewGuid(),
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user_2);
            userItems = inMemoryStorage.GetUsers();

            Assert.AreEqual(2, userItems.Count);
        }
Example #2
0
        public void Add_User_Storage_InMemory_Tests_Method()
        {
            InMemoryStorage inMemoryStorage = new InMemoryStorage();

            Guid           guid = Guid.NewGuid();
            DateTimeOffset date = DateTimeOffset.Now;
            DomainUserItem user = new DomainUserItem()
            {
                ChatId             = 12345678,
                DateOfRegistration = date,
                FirstName          = "Null",
                Id      = guid,
                Message = "Null",
                Status  = StatusEnum.Null
            };

            inMemoryStorage.AddUser(user);

            List <IDomainUserItem> userItems = inMemoryStorage.GetUsers();

            Assert.AreEqual(1, userItems.Count);

            foreach (var item in userItems)
            {
                Assert.AreEqual(item, user);
            }
            Assert.AreEqual(1, inMemoryStorage.Count);
        }
        public DomainUserItem PanelAdminMessage(InMemoryStorage storage)
        {
            switch (_userItem.DomainStatus)
            {
            case DomainStatusEnum.Admin_Greeteng_Notification:
                _sender.SendMessage(_userItem.ChatId, "Admin.", MainWindow);
                _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                break;

            case DomainStatusEnum.Admin_Greeteng:
                if (_userItem.Message != null)
                {
                    if (_userItem.Message.Equals("Отправить сообщение \U00002709"))
                    {
                        _sender.SendMessage(_userItem.ChatId, "Отправить сообщениe :", MessageSend);
                        _userItem.DomainStatus = DomainStatusEnum.Admin_MessageSend;
                    }
                    else if (_userItem.Message.Equals("Статус пользователя \U00002755"))
                    {
                        _sender.SendMessage(_userItem.ChatId, "Имя пользователя :", null);
                        _userItem.DomainStatus = DomainStatusEnum.Admin_UpdateStatus_InputName;
                    }
                    else
                    {
                        _sender.SendMessage(_userItem.ChatId, "Я не знаю такой команды.", MainWindow);
                    }
                }
                else
                {
                    _sender.SendMessage(_userItem.ChatId, "Я не знаю такой команды.", MainWindow);
                }
                break;

            case DomainStatusEnum.Admin_UpdateStatus_InputName:
                _userItem.Admin_InputName = _userItem.Message;
                int r = 0;
                foreach (var item in storage.GetUsers())
                {
                    if (item.FirstName == _userItem.Message)
                    {
                        r++;
                    }
                }
                if (r >= 1)
                {
                    _userItem.DomainStatus = DomainStatusEnum.Admin_UpdateStatus_RepairStatus;
                    _sender.SendMessage(_userItem.ChatId, $"{_userItem.Admin_InputName} найден. \U00002705", null);
                    _sender.SendMessage(_userItem.ChatId, "Cтатус : ", RepairStatusBar);
                }
                else if (r.Equals(0))
                {
                    _sender.SendMessage(_userItem.ChatId, "Пользователя с данным именем не найдено \U0000274C", MainWindow);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                }
                break;

            case DomainStatusEnum.Admin_UpdateStatus_RepairStatus:
                if (_userItem.Message.Equals("User") || _userItem.Message.Equals("@WeatherConditions_bot User"))
                {
                    foreach (var item in storage.GetUsers())
                    {
                        if (item.FirstName.Equals(_userItem.Admin_InputName))
                        {
                            if (item.ChatId == _userItem.ChatId)
                            {
                                _userItem.Status       = StatusEnum.User;
                                _userItem.DomainStatus = DomainStatusEnum.Null;
                                userStorage.UpdateStatus(new Telegram.Storage.Core.UserItem()
                                {
                                    ChatId = _userItem.ChatId, Status = StatusEnum.User, Id = _userItem.Id, FirstName = _userItem.FirstName, DateOfRegistration = _userItem.DateOfRegistration
                                });
                                _sender.SendMessage(_userItem.ChatId, $"{_userItem.FirstName} : User", null);
                            }
                            else
                            {
                                item.Status       = StatusEnum.User;
                                item.DomainStatus = DomainStatusEnum.Null;
                                userStorage.UpdateStatus(new Telegram.Storage.Core.UserItem()
                                {
                                    ChatId = item.ChatId, Status = StatusEnum.User, Id = item.Id, FirstName = item.FirstName, DateOfRegistration = item.DateOfRegistration
                                });
                                _sender.SendMessage(_userItem.ChatId, $"{item.FirstName} : User", MainWindow);
                                _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                            }
                        }
                    }
                }
                else if (_userItem.Message.Equals("Mut") || _userItem.Message.Equals("@WeatherConditions_bot Mut"))
                {
                    foreach (var item in storage.GetUsers())
                    {
                        if (item.FirstName.Equals(_userItem.Admin_InputName))
                        {
                            if (item.ChatId == _userItem.ChatId)
                            {
                                _sender.SendMessage(_userItem.ChatId, "Вы не можете себе изменить статус на Мут \U0000274C", null);
                            }
                            else
                            {
                                item.Status       = StatusEnum.Ban;
                                item.DomainStatus = DomainStatusEnum.Null;
                                userStorage.UpdateStatus(new Telegram.Storage.Core.UserItem()
                                {
                                    ChatId = item.ChatId, Status = StatusEnum.Ban, Id = item.Id, FirstName = item.FirstName, DateOfRegistration = item.DateOfRegistration
                                });
                                _sender.SendMessage(item.ChatId, $"{item.FirstName} : Мут", PanelAdmin.MainWindow);
                                _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                            }
                        }
                    }
                }
                else if (_userItem.Message.Equals("Отмена") || _userItem.Message.Equals("@WeatherConditions_bot Back"))
                {
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                    _sender.SendMessage(_userItem.ChatId, "Отмена. \U0001F519", MainWindow);
                }
                break;

            case DomainStatusEnum.Admin_MessageSend:
                if (_userItem.Message.Equals("@WeatherConditions_bot All") || _userItem.Message.Equals("All"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Cообщение :", null);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_MessageSend_All_InputMessage;
                }
                else if (_userItem.Message.Equals("@WeatherConditions_bot User"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Имя пользователя :", null);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_MessageSend_User_InputNick;
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_User_InputNick:
                _userItem.Admin_InputName = _userItem.Message;
                int i = 0;
                foreach (var item in storage.GetUsers())
                {
                    if (item.FirstName == _userItem.Message)
                    {
                        i++;
                    }
                }
                if (i.Equals(1))
                {
                    _userItem.DomainStatus = DomainStatusEnum.Admin_MessageSend_User_InputMessage;
                    _sender.SendMessage(_userItem.ChatId, "Cообщение :", null);
                }
                else if (i.Equals(0))
                {
                    _sender.SendMessage(_userItem.ChatId, "Пользователя с данным именем не найдено \U0000274C", MainWindow);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_User_InputMessage:
                _userItem.Admin_Photo       = _userItem.Photo;
                _userItem.Admin_Caption     = _userItem.Caption;
                _userItem.Admin_MessageSend = _userItem.Message;
                _userItem.DomainStatus      = DomainStatusEnum.Admin_MessageSend_User_MainPage;
                if (_userItem.Message != null)
                {
                    _sender.SendMessage(_userItem.ChatId, $"Ваше сообщение :\n\n {_userItem.Message}", MessageSendAll);
                }
                else if (_userItem.Photo != null)
                {
                    _sender.SendMessage(_userItem.ChatId, $"Ваше сообщение :\n\n", null);
                    _sender.SendPhoto(_userItem.ChatId, _userItem.Photo, _userItem.Caption, MessageSendAll);
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_User_MainPage:
                if (_userItem.Message.Equals("Отправить"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Отправка...", null);
                    foreach (var item in storage.GetUsers())
                    {
                        if (item.FirstName.Equals(_userItem.Admin_InputName))
                        {
                            if (_userItem.Admin_MessageSend != null)
                            {
                                _sender.SendMessage(item.ChatId, _userItem.Admin_MessageSend, null);
                            }
                            else if (_userItem.Admin_Photo != null)
                            {
                                _sender.SendPhoto(item.ChatId, _userItem.Admin_Photo, _userItem.Admin_Caption, null);
                            }
                        }
                    }
                    _sender.SendMessage(_userItem.ChatId, "Отправлено. \U00002705", MainWindow);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                }
                else if (_userItem.Message.Equals("Отправить себе"))
                {
                    if (_userItem.Admin_MessageSend != null)
                    {
                        _sender.SendMessage(_userItem.ChatId, _userItem.Admin_MessageSend, null);
                    }
                    else if (_userItem.Admin_Photo != null)
                    {
                        _sender.SendPhoto(_userItem.ChatId, _userItem.Admin_Photo, _userItem.Admin_Caption, null);
                    }
                }
                else if (_userItem.Message.Equals("Отмена"))
                {
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                    _sender.SendMessage(_userItem.ChatId, "Отмена. \U0001F519", MainWindow);
                }
                else if (_userItem.Message.Equals("Изменить сообщение"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Вводите сообщение.", null);
                    _userItem.Admin_MessageSend = null;
                    _userItem.Admin_Photo       = null;
                    _userItem.Admin_Caption     = null;
                    _userItem.DomainStatus      = DomainStatusEnum.Admin_MessageSend_User_InputMessage;
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_All_InputMessage:
                _userItem.Admin_Photo       = _userItem.Photo;
                _userItem.Admin_Caption     = _userItem.Caption;
                _userItem.Admin_MessageSend = _userItem.Message;
                _userItem.DomainStatus      = DomainStatusEnum.Admin_MessageSend_All;
                if (_userItem.Message != null)
                {
                    _sender.SendMessage(_userItem.ChatId, $"Ваше сообщение :\n\n {_userItem.Message}", MessageSendAll);
                }
                else if (_userItem.Photo != null)
                {
                    _sender.SendMessage(_userItem.ChatId, $"Ваше сообщение :\n\n", null);
                    _sender.SendPhoto(_userItem.ChatId, _userItem.Photo, _userItem.Caption, MessageSendAll);
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_All:
                if (_userItem.Message.Equals("Изменить сообщение"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Вводите сообщение.", null);
                    _userItem.Admin_MessageSend = null;
                    _userItem.Admin_Photo       = null;
                    _userItem.Admin_Caption     = null;
                    _userItem.DomainStatus      = DomainStatusEnum.Admin_MessageSend_All_InputMessage;
                }
                else if (_userItem.Message.Equals("Отправить себе"))
                {
                    if (_userItem.Admin_MessageSend != null)
                    {
                        _sender.SendMessage(_userItem.ChatId, _userItem.Admin_MessageSend, null);
                    }
                    else if (_userItem.Admin_Photo != null)
                    {
                        _sender.SendPhoto(_userItem.ChatId, _userItem.Admin_Photo, _userItem.Admin_Caption, null);
                    }
                }
                else if (_userItem.Message.Equals("Отправить"))
                {
                    _sender.SendMessage(_userItem.ChatId, "Отправка...", null);
                    foreach (var item in storage.GetUsers())
                    {
                        if (item.Status.Equals(StatusEnum.User))
                        {
                            if (_userItem.Admin_MessageSend != null)
                            {
                                _sender.SendMessage(item.ChatId, _userItem.Admin_MessageSend, null);
                            }
                            else if (_userItem.Admin_Photo != null)
                            {
                                _sender.SendPhoto(item.ChatId, _userItem.Admin_Photo, _userItem.Admin_Caption, null);
                            }
                        }
                    }
                    _sender.SendMessage(_userItem.ChatId, "Отправлено. \U00002705", MainWindow);
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                }
                else if (_userItem.Message.Equals("Отмена"))
                {
                    _userItem.DomainStatus = DomainStatusEnum.Admin_Greeteng;
                    _sender.SendMessage(_userItem.ChatId, "Отмена. \U0001F519", MainWindow);
                }
                break;

            case DomainStatusEnum.Admin_MessageSend_User:
                break;
            }

            return(_userItem);
        }