Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("[Reminder Notifier] starting...");

            var storage = new ReminderStorage();
            var service = new ReminderService(storage);

            service.ItemNotified += OnReminderItemFired;
            service.Create(
                new CreateReminderModel(
                    "ContactId",
                    "First",
                    DateTimeOffset.UtcNow.AddSeconds(3)
                    )
                );
            service.Create(
                new CreateReminderModel(
                    "ContactId",
                    "Second",
                    DateTimeOffset.UtcNow.AddMinutes(1)
                    )
                );

            Console.ReadKey();
        }
Пример #2
0
        public ActionResult NewGeneralReminder(GeneralRemindersViewModel reminder)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //The model is valid - insert the reminder and redisplay the grid.

                    reminder.CreatedOn = DateTime.Now;
                    reminder.CreatedBy = 1;

                    ReminderService.Create(reminder);

                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    RouteValueDictionary routeValues = this.GridRouteValues();

                    return(RedirectToAction("Index", routeValues));
                }

                //The model is invalid - render the current view to show any validation errors
                return(View());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public ActionResult NewEmployeeReminder(EmployeeRemindersViewModel reminder)
        {
            List <string> Errors = new List <string>();

            bool isvalid = false;

            if (ModelState.IsValid)
            {
                reminder.CreatedOn = DateTime.Now;
                reminder.CreatedBy = 1;
                ReminderService.Create(reminder);


                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                RouteValueDictionary routeValues = this.GridRouteValues();

                return(RedirectToAction("Index", routeValues));
            }
            else
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        Errors.Add(error.ErrorMessage);
                    }
                }
            }
            //TempData["isvalid"] = isvalid;

            return(View());
        }
        public void WhenCreate_IfNewItemCreated_ShouldSendItemOnDate()
        {
            //Arrange
            var result  = false;
            var service = new ReminderService(new ReminderStorage());

            //Act
            service.ItemSent += (sender, e) => result = true;
            service.Create(new CreateReminderModel("contact", "message", DateTimeOffset.Now));
            Thread.Sleep(3000);

            //Assert
            Assert.IsTrue(result);
        }
Пример #5
0
        private async Task <string> CreateReminder(ICommandContext context, string message)
        {
            try
            {
                var result = FuzzyParsing.Moment(message);

                string error = null;
                if (!result.IsValid)
                {
                    error = result.ErrorMessage;
                }
                else if (result.Value < DateTime.UtcNow)
                {
                    error = PastValueErrorMessage.Replace("$moment$", result.Value.ToString(CultureInfo.InvariantCulture));
                }

                if (error != null)
                {
                    return(error);
                }
                else
                {
                    var triggerTime = result.Value;
                    var duration    = triggerTime - DateTime.UtcNow;

                    //Add some context to the message
                    var prelude = $"{context.Message.Author.Mention} Reminder from {DateTime.UtcNow.Humanize(dateToCompareAgainst: triggerTime, culture: CultureInfo.GetCultureInfo("en-gn"))}...";
                    var msg     = $"remind me {message}";

                    //Save to database
                    var n = await _reminder.Create(triggerTime, prelude, msg, context.Message.Channel.Id, context.User.Id);

                    return($"I will remind you in {duration.Humanize(2, maxUnit: TimeUnit.Year, minUnit: TimeUnit.Second, toWords: true)} (id: `{n.ID}`)");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }