예제 #1
0
 public TelegramMessageHandler(TelegramApi telegramApi, Birthdays birthdays, IAdminManager adminManager)
 {
     _storedIds    = JsonHelper.DeserializeFile("messages.json", new LimitedStore <int>(25));
     _telegramApi  = telegramApi;
     _birthdays    = birthdays;
     _adminManager = adminManager;
 }
예제 #2
0
        private void InsertRow()
        {
            var item = new Birthday();

            Birthdays = Birthdays == null ? new ObservableCollection <Birthday>() : Birthdays;
            Birthdays.Add(item);
        }
예제 #3
0
        private void Sort_Callback()
        {
            var sorted = Birthdays
                         .OrderBy(b => b.BirthDay.Month)
                         .ThenBy(b => b.BirthDay.Day);

            Birthdays = new ObservableCollection <Birthday>(sorted);
        }
예제 #4
0
        public ActionResult Delete(int id)
        {
            Birthdays n = _db.Birthdays.Find(id);

            _db.Birthdays.Remove(n);
            _db.SaveChanges();
            return(RedirectToAction("List"));
        }
 private void Refresh()
 {
     IsRefreshing = true;
     Birthdays.ReplaceRangeWithoutUpdating(BirthdaysRepository
                                           .GetAll()
                                           .ToAchievementStepViewModels()
                                           .OrderBy(x => x.BirthDayDate));
     Birthdays.RaiseCollectionChanged();
     IsRefreshing = false;
 }
예제 #6
0
        public void AddingSomeoneElsesBirthdayWhileNotAnAdminDoesNotAddBirthday()
        {
            var api       = new TelegramApi("", "");
            var birthdays = new Birthdays(new List <Birthday>(), api, Mock.Of <IFileWriter>());
            var sut       = new TelegramMessageHandler(api, birthdays, new AdminManager());

            var json = CreateTelegramUpdateDto("/birthadd tempo 01-01", "EriK", "AnyChat", 139);

            sut.HandleMessage(json);
            Assert.Empty(birthdays);
        }
예제 #7
0
        public void AddingYourOwnBirthdayDoesNotRequireBeingAnAdmin()
        {
            var api       = new TelegramApi("", "");
            var birthdays = new Birthdays(new List <Birthday>(), api, Mock.Of <IFileWriter>());
            var sut       = new TelegramMessageHandler(api, birthdays, new AdminManager());

            var json = CreateTelegramUpdateDto("/birthadd erik 01-01", "EriK", "EriK", 139);

            sut.HandleMessage(json);
            Assert.Contains(birthdays, b =>
                            b.Human.Equals("erik", StringComparison.InvariantCultureIgnoreCase) &&
                            b.Date.Day == 1 &&
                            b.Date.Month == 1);
        }
예제 #8
0
 public ActionResult Add(Birthdays model)
 {
     if (ModelState.IsValid)
     {
         //model.NewsedDate = DateTime.Now;
         this._db.Birthdays.Add(model);
         this._db.SaveChanges();
         TempData["message"] = "Dodano informacje o urodzinach użytkownika!";
         return(RedirectToAction("list"));
     }
     else
     {
         return(View(model));
     }
 }
        public void AddTest()
        {
            Birthdays birthdays = new Birthdays(new List <BirthDay>()
            {
                new BirthDay {
                    Surname = "Alex", Name = "Text", Birthday = new DateTime(1980, 1, 1)
                },
            });
            BirthDay test = new BirthDay {
                Surname = "Test", Name = "Test", Birthday = new DateTime(1981, 1, 1)
            };

            birthdays.Add(test.Surname, test.Name, test.Birthday);
            Assert.AreEqual(2, birthdays.Count);
            Assert.AreEqual(test, birthdays[1]);
        }
예제 #10
0
        private void doData(string JSON)
        {
            var random = JsonConvert.DeserializeObject <ZModelHomepage>(JSON).RandomQuotes;

            if (random != null)
            {
                foreach (var item in random)
                {
                    item.Text = HtmlRemoval.StripTagsRegex(item.Text);
                    RandomQuotes.Add(item);
                    break;
                }
            }

            var birthers = JsonConvert.DeserializeObject <ZModelHomepage>(JSON).Births;

            if (birthers != null)
            {
                foreach (var item in birthers)
                {
                    item.imageSrc = ZModelAuthor.getImage(item.image);
                    Birthdays.Add(item);
                }
            }

            var diers = JsonConvert.DeserializeObject <ZModelHomepage>(JSON).Deaths;

            if (diers != null)
            {
                foreach (var item in diers)
                {
                    item.imageSrc = ZModelAuthor.getImage(item.image);
                    Deathdays.Add(item);
                }
            }

            var authors = JsonConvert.DeserializeObject <ZModelHomepage>(JSON).PopularAuthors;

            if (authors != null)
            {
                foreach (var item in authors)
                {
                    item.imageSrc = ZModelAuthor.getImage(item.image);
                    PopularAuthors.Add(item);
                }
            }
        }
        public void EditTest()
        {
            Birthdays birthdays = new Birthdays(new List <BirthDay>()
            {
                new BirthDay {
                    Surname = "Alex", Name = "Text", Birthday = new DateTime(1980, 1, 1)
                },
            });
            BirthDay test = new BirthDay {
                Surname = "Test", Name = "Test", Birthday = new DateTime(1981, 1, 1)
            };

            birthdays.Edit(0, test.Surname, test.Name, test.Birthday);
            Assert.AreEqual(1, birthdays.Count);
            Assert.AreEqual(test, birthdays[0]);
            Assert.ThrowsException <ApplicationException>(() => birthdays.Edit(2, test.Surname, test.Name, test.Birthday));
        }
예제 #12
0
        public void CreateBirthdayMessages()
        {
            DateTime today = new DateTime(1985, 03, 16);
            var      john  = TestEmployees.John.WasBorn(today);

            List <Employee> employees = new List <Employee>
            {
                john, TestEmployees.Mary
            };

            List <BirthdayMessage> expectedMessages = new List <BirthdayMessage>
            {
                new BirthdayMessage(john.Name)
            };

            Assert.Equal(expectedMessages, Birthdays.Of(employees, today));
        }
예제 #13
0
 public ActionResult Edit(Birthdays model)
 {
     if (ModelState.IsValid)
     {
         int       id        = (int)model.Id;
         Birthdays Birthdays = this._db.Birthdays.Find(id);
         _db.Birthdays.Remove(Birthdays);
         this._db.Birthdays.Add(model);
         this._db.SaveChanges();
         TempData["message"] = "Urodziny edytowane!";
         return(RedirectToAction("list"));
     }
     else
     {
         return(View(model));
     }
 }
예제 #14
0
        public void AddingSomeoneElsesBirthdayWhileAnAdminDoesAddBirthday()
        {
            var api          = new TelegramApi("", "");
            var birthdays    = new Birthdays(new List <Birthday>(), api, Mock.Of <IFileWriter>());
            var adminManager = new AdminManager(new List <string> {
                "erik"
            });
            var sut = new TelegramMessageHandler(api, birthdays, adminManager);

            var json = CreateTelegramUpdateDto("/birthadd tempo 12-15", "EriK", "AnyChat", 139);

            sut.HandleMessage(json);
            Assert.Contains(birthdays, b =>
                            b.Human.Equals("tempo", StringComparison.InvariantCultureIgnoreCase) &&
                            b.Date.Day == 15 &&
                            b.Date.Month == 12);
        }
        public void DeleteTest()
        {
            BirthDay test = new BirthDay {
                Surname = "Max", Name = "Faq", Birthday = new DateTime(1980, 1, 1)
            };
            Birthdays birthdays = new Birthdays(new List <BirthDay>()
            {
                new BirthDay {
                    Surname = "Alex", Name = "Text", Birthday = new DateTime(1980, 1, 1)
                },
                test,
            });

            birthdays.Delete(0);
            Assert.AreEqual(1, birthdays.Count);
            Assert.AreEqual(test, birthdays[0]);
            Assert.ThrowsException <ApplicationException>(() => birthdays.Delete(2));
        }
        private async Task DeleteBirthday(BirthdayViewModel viewModel)
        {
            bool result = await UserDialogs.Instance.ConfirmAsync(
                ConstantsHelper.BirthdaysDeleteMessage,
                ConstantsHelper.Warning,
                ConstantsHelper.Ok,
                ConstantsHelper.Cancel);

            if (result)
            {
                Birthdays.Remove(viewModel);
                var modelToDelete = BirthdaysRepository.GetBirthdayAsync(viewModel.Id);
                if (modelToDelete != null)
                {
                    BirthdaysRepository.DeleteBirthday(modelToDelete);
                }
            }
        }
        /// <summary>
        /// Removes English text with appropriate local language from Birthday
        /// </summary>
        /// <param name="birthdays">The list of recent and all birthdays</param>
        private static void LocalizeBirthdayText(Birthdays birthdays)
        {
            foreach (var birthday in birthdays.AllBirthdays)
            {
                birthday.BirthdayText = birthday.BirthdayText.Replace(Labels.BirthdayLabel, AppResources.BirthdayLabel);
                birthday.BirthdayText = birthday.BirthdayText.Replace(Labels.NotKnownLabel, AppResources.NotKnownLabel);
                birthday.BirthdayText = birthday.BirthdayText.Replace(Labels.TodayLabel, AppResources.TodayLabel);
                birthday.BirthdayText = birthday.BirthdayText.Replace(Labels.TomorrowLabel, AppResources.TomorrowLabel);
                birthday.BirthdayText = birthday.BirthdayText.Replace(Labels.LaterThisWkLabel, AppResources.LaterThisWkLabel);
            }

            foreach (var birthday in birthdays.RecentBirthdays)
            {
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.BirthdayLabel, AppResources.BirthdayLabel);
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.NotKnownLabel, AppResources.NotKnownLabel);
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.TodayLabel, AppResources.TodayLabel);
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.TomorrowLabel, AppResources.TomorrowLabel);
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.LaterThisWkLabel, AppResources.LaterThisWkLabel);
                birthday.TimeToEventText = birthday.TimeToEventText.Replace(Labels.DaysLabel, AppResources.DaysLabel);
            }
        }
        public void GetStringsTest()
        {
            Birthdays birthdays = new Birthdays(new List <BirthDay>()
            {
                new BirthDay {
                    Surname = "Alex", Name = "Text", Birthday = new DateTime(1980, 1, 1)
                },
                new BirthDay {
                    Surname = "Max", Name = "Faq", Birthday = new DateTime(1980, 1, 1)
                },
                new BirthDay {
                    Surname = "Sax", Name = "Faq", Birthday = new DateTime(1980, 1, 1)
                },
            });

            string[] expected = { "Alex Text 1 января 1980 г.", "Max Faq 1 января 1980 г.", "Sax Faq 1 января 1980 г." };
            string[] test     = birthdays.GetStrings();
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], test[i]);
            }
        }
예제 #19
0
        public List <BirthdayMessage> CreateMessages(DateTime today)
        {
            List <Employee> employees = _employeesRepository.ReadAll();

            return(Birthdays.Of(employees, today));
        }
예제 #20
0
        public ActionResult Edit(int id)
        {
            Birthdays Birthdays = _db.Birthdays.Find(id);

            return(View(Birthdays));
        }