Пример #1
0
        private void SetMessageDetails(AppMessage message)
        {
            Title.SetText(message.Title);
            MessageTB.SetText(message.Quote);
            AuthorsTB.SetText(string.IsNullOrEmpty(message.Author) ? NO_AUTHORS : message.Author);
            SourcesTB.SetText(string.IsNullOrEmpty(message.Source) ? NO_SOURCES : message.Source);

            Date_Created.SetText(TimeAndDateUtility.ConvertDate_String(message.CreatedDate.Date, true));
            Time_Created.SetText(TimeAndDateUtility.ConvertTime_String(message.CreatedDate.Time));

            bool fullLastDisplayedDate = message.LastDisplayedDate == null || message.LastDisplayedDate.Date == null || message.LastDisplayedDate.Time == null;

            Last_Displayed_Date.SetText(fullLastDisplayedDate ?
                                        DASH : TimeAndDateUtility.ConvertDate_String(message.LastDisplayedDate.Date, true));

            Last_Displayed_Time.SetText(fullLastDisplayedDate ?
                                        DASH : TimeAndDateUtility.ConvertTime_String(message.LastDisplayedDate.Time));

            Status.SetText(message.Show ? ENABLE : DISABLE);
            Status.SetBackColor(message.Show ? Color.DarkGreen : Color.DarkRed);
            Status.SetForeColor(Color.WhiteSmoke);

            string preview = $"\"{MessageTB.Text}\"\r\n\r\n    - {AuthorsTB.Text}\r\n\r\nSources:\r\n    {SourcesTB.Text}";

            PreviewTB.SetText(preview);
        }
Пример #2
0
        public static DateAndTime TestDate(string dateAndTime)
        {
            string[] date_time =
                dateAndTime.Replace(Quotes, string.Empty)
                .Split(new[] { PlusSign }, StringSplitOptions.RemoveEmptyEntries);
            bool containsBoth =
                date_time.Length == 2 && !string.IsNullOrEmpty(date_time[0]) && !string.IsNullOrEmpty(date_time[1]);
            bool containsNone = date_time.Length == 0;

            if (!containsBoth && !containsNone)
            {
                throw new Exception("Missing data for Dates");
            }
            else if (containsBoth && !DateTime.TryParse($"{date_time[0]} {date_time[1]}", out DateTime testDate))
            {
                throw new Exception("Invalid data for Dates");
            }

            Date date = null;
            Time time = null;

            if (containsBoth)
            {
                date = TimeAndDateUtility.ConvertString_Date(date_time[0]);
                time = TimeAndDateUtility.ConvertString_Time(date_time[1]);
            }

            return(new DateAndTime(date, time));
        }
Пример #3
0
 /// <summary>
 /// Implements <see cref="IEventRepository.GetEvents(DateAndTime)" />
 /// </summary>
 public IEnumerable <SavedEvent> GetEvents(DateAndTime date)
 {
     return
         (SavedEvents.Where(x => TimeAndDateUtility.IsWithinRange(x.ActivationDate, date, x.DeactivationDate, false))
          .ToList()
          .AsReadOnly());
 }
Пример #4
0
        public void WhenDeletingTheMessage_HandlesInvalidId()
        {
            #region Data

            AppMessage actual1 = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "2",
                Title       = "2",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Quote test",
                Author      = "Author test",
                Show        = false,
                Source      = "Somewhere from"
            };

            #endregion Data

            bool testAdd    = repository.AddMessage(actual1);
            bool testDelete = repository.DeleteMessage(actual2.Id);

            Assert.IsTrue(testAdd);
            Assert.IsFalse(testDelete);
        }
Пример #5
0
        public void WhenGettingTheMessage_ReturnsValidMessage()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool       testAdd = repository.AddMessage(actual);
            AppMessage result  = repository.GetMessage(actual.Id);

            Assert.IsTrue(testAdd);
            Assert.AreEqual(actual.Id, result.Id);
            Assert.AreEqual(actual.Title, result.Title);
            Assert.AreEqual(
                actual.CreatedDate.Date,
                result.CreatedDate.Date
                );
            Assert.AreEqual(
                actual.CreatedDate.Time,
                result.CreatedDate.Time
                );
            Assert.AreEqual(actual.Quote, result.Quote);
            Assert.AreEqual(actual.Author, result.Author);
            Assert.AreEqual(actual.Source, result.Source);
        }
Пример #6
0
        public void SetValues(SavedEvent @event)
        {
            TitleTB.SetText(@event.Title);
            CommentTB.SetText(@event.Comment ?? string.Empty);
            DateTime now = DateTime.Now;

            DateTime start = TimeAndDateUtility.ConvertDateAndTime_DateTime(@event.ActivationDate);
            DateTime end   = TimeAndDateUtility.ConvertDateAndTime_DateTime(@event.DeactivationDate);

            StartPicker.SetDates(now > start ? start.Date : now.Date, start, DateTime.MaxValue);
            EndPicker.SetDates(now > end ? end.Date : now.Date, end, DateTime.MaxValue);

            if (start < now)
            {
                StartPicker.GetControl().Enabled = false;
            }

            if (end < now)
            {
                EndPicker.GetControl().Enabled = false;
            }

            if (!StartPicker.GetControl().Enabled&& !EndPicker.GetControl().Enabled)
            {
                TitleTB.GetControl().Enabled   = false;
                CommentTB.GetControl().Enabled = false;

                _purpose = CrudPurposes.None;
                SetTitle();
            }
        }
Пример #7
0
        public void WhenGettingTheMessages_HandlesInvalidSearchParam()
        {
            #region Data

            AppMessage actual1 = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "2",
                Title       = "2",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = false,
                Source      = "From somewhere"
            };

            #endregion Data

            bool testAdd             = repository.AddMessage(actual1) && repository.AddMessage(actual2);
            List <AppMessage> result = repository.GetMessages(null).ToList();

            Assert.IsTrue(testAdd);
            Assert.AreEqual(0, result.Count());
        }
Пример #8
0
        private void SetEventDetails(SavedEvent @event)
        {
            DateAndTime currDate       = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime());
            DateAndTime eventStartDate = @event.ActivationDate;
            DateAndTime eventEndDate   = @event.DeactivationDate;

            Exp_Start_Date.SetText(TimeAndDateUtility.ConvertDate_String(@event.ActivationDate.Date, true));
            Exp_Start_Time.SetText(TimeAndDateUtility.ConvertTime_String(@event.ActivationDate.Time));
            Exp_End_Date.SetText(TimeAndDateUtility.ConvertDate_String(@event.DeactivationDate.Date, true));
            Exp_End_Time.SetText(TimeAndDateUtility.ConvertTime_String(@event.DeactivationDate.Time));
            Created_Date.SetText(
                $"{TimeAndDateUtility.ConvertDate_String(@event.CreatedDate.Date, true)} {TimeAndDateUtility.ConvertTime_String(@event.CreatedDate.Time)}");

            Completion_Date.SetText(
                @event.Completed && @event.CompletedDate != null && @event.CompletedDate.Date != null && @event.CompletedDate.Time != null ?
                $"{TimeAndDateUtility.ConvertDate_String(@event.CompletedDate.Date, true)} {TimeAndDateUtility.ConvertTime_String(@event.CompletedDate.Time)}"
                    : DASH);

            Event_Status.SetText(
                @event.Completed ? "Complete"
                    : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ?
                "Upcoming"
                        : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ?
                "In Progress" : "Overdue");
            Event_Status.SetBackColor(
                @event.Completed ? Color.DarkGreen
                    : TimeAndDateUtility.IsBeforeRange(eventStartDate, currDate) ?
                Color.DarkGray
                        : TimeAndDateUtility.IsWithinRange(eventStartDate, currDate, eventEndDate) ?
                Color.DarkBlue : Color.DarkRed);

            User_Title.SetText(@event.Title);

            User_Comment.SetText(!string.IsNullOrEmpty(@event.Comment) ? @event.Comment : NO_COMMENT);
        }
Пример #9
0
        private void UpdateTodaysEvents(DateTime selectedDate)
        {
            DateAndTime date = TimeAndDateUtility.ConvertDateTime_DateAndTime(selectedDate);

            object[] eventList = _events.GetAll(date);

            Todays_Events.Update(eventList);
        }
Пример #10
0
 /// <summary>
 /// Gets all dates that have events
 /// </summary>
 /// <returns>A list of the dates where events occur</returns>
 public IEnumerable <DateTime> GetAllEventDates()
 {
     return
         (_eventRepo.GetEvents()
          .Select(x => TimeAndDateUtility.ConvertDateAndTime_DateTime(x.ActivationDate))
          .Distinct()
          .OrderBy(x => x));
 }
Пример #11
0
        /// <summary>
        /// Updates the views
        /// </summary>
        /// <param name="start">The start date</param>
        /// <param name="end">The end date</param>
        /// <param name="searchTerm">The search term</param>
        public void UpdateEvents(DateTime start, DateTime end, string searchTerm = null)
        {
            DateAndTime startDate = start == DateTime.MaxValue ? null : TimeAndDateUtility.ConvertDateTime_DateAndTime(start);
            DateAndTime endDate   = end == DateTime.MinValue ? null : TimeAndDateUtility.ConvertDateTime_DateAndTime(end);

            ClearEventDetails();
            UpdateTodaysEvents(startDate, endDate, searchTerm);
        }
Пример #12
0
 /// <summary>
 /// Implements <see cref="IEventRepository.GetEvents(DateAndTime, DateAndTime)" />
 /// </summary>
 public IEnumerable <SavedEvent> GetEvents(DateAndTime start, DateAndTime end)
 {
     return
         (SavedEvents.Where(x =>
                            TimeAndDateUtility.IsWithinRange(start, x.ActivationDate, end) ||
                            TimeAndDateUtility.IsWithinRange(start, x.DeactivationDate, end))
          .ToList()
          .AsReadOnly());
 }
Пример #13
0
        private void Confirm_Click(object sender, EventArgs e)
        {
            bool  error = false;
            Label title = Title.GetControl();

            if (TitleTB.Text == string.Empty)
            {
                Title.SetText(title.Text.Contains("*") ? title.Text : string.Format("{0}*", title.Text));
                error = true;
            }
            else
            {
                Title.SetText(title.Text.Contains("*") ? title.Text.Remove(title.Text.Length - 1) : title.Text);
            }

            Label start = Start.GetControl();
            Label end   = End.GetControl();

            if (CheckStartAndEndDate())
            {
                Start.SetText(start.Text.Contains("*") ? start.Text : string.Format("{0}*", start.Text));
                End.SetText(end.Text.Contains("*") ? end.Text : string.Format("{0}*", end.Text));
                error = true;
            }
            else if (CheckMinDate())
            {
                Start.SetText(start.Text.Contains("*") ? start.Text : string.Format("{0}*", start.Text));
                End.SetText(end.Text.Contains("*") ? end.Text : string.Format("{0}*", end.Text));
                error = true;
            }
            else
            {
                Start.SetText(start.Text.Contains("*") ? start.Text.Remove(start.Text.Length - 1) : start.Text);
                End.SetText(end.Text.Contains("*") ? end.Text.Remove(end.Text.Length - 1) : end.Text);
            }

            if (error)
            {
                Data.DialogResult = DialogResult.None;
                Data.Error        = true;
            }
            else
            {
                Data.DialogResult = DialogResult.OK;
                Data.Results      = new SavedEvent()
                {
                    Title            = TitleTB.Text,
                    Comment          = CommentTB.Text,
                    ActivationDate   = new DateAndTime(TimeAndDateUtility.ConvertString_Date(StartPicker.Date), TimeAndDateUtility.ConvertString_Time(StartPicker.Time)),
                    DeactivationDate = new DateAndTime(TimeAndDateUtility.ConvertString_Date(EndPicker.Date), TimeAndDateUtility.ConvertString_Time(StartPicker.Time))
                };

                Data.Error = false;

                ((Form)TopLevelControl).Close();
            }
        }
Пример #14
0
        /// <summary>
        /// Set the delay and date to start the delay
        /// </summary>
        /// <param name="delay">The amount of seconds to delay</param>
        /// <param name="date">The date to start the delay</param>
        public void SetDelay(int delay, DateAndTime date)
        {
            int delayTime = delay > 0 ? delay : 30;

            DateDelayed = date;
            DateTime continued = TimeAndDateUtility.ConvertDateAndTime_DateTime(date).AddSeconds(delayTime);

            DateContinued = TimeAndDateUtility.ConvertDateTime_DateAndTime(continued);
            Lock          = true;
        }
Пример #15
0
        internal void UpdateEventList()
        {
            ListViewItem[] events = _events.GetAll(EventListView.Groups);

            Time   time       = TimeAndDateUtility.GetCurrentTime();
            string timeString = TimeAndDateUtility.ConvertTime_String(time);
            string dateString = TimeAndDateUtility.GetCurrentDateString(true);

            EventLV.Update(events);
            Last_Updated.SetText($"Last Updated: {dateString} {timeString}");
        }
Пример #16
0
        /// <summary>
        /// Creates a messaage
        /// </summary>
        /// <param name="message">The message to create</param>
        /// <returns>Whether the message was created</returns>
        public bool CreateMessage(AppMessage message)
        {
            bool created = false;

            if (message != null)
            {
                message.CreatedDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime());
                created             = _messageRepo.AddMessage(message);
            }

            return(created);
        }
Пример #17
0
        public void WhenUpdatingTheMessage_UpdatesSuccessful()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            AppMessage actual2 = new AppMessage
            {
                Id          = "1",
                Title       = "2",
                CreatedDate = actual.CreatedDate,
                Quote       = "Quote test",
                Author      = "Author test",
                Show        = false,
                Source      = "Somewhere from"
            };

            #endregion Data

            bool testAdd = repository.AddMessage(actual);

            Assert.IsTrue(testAdd);

            bool testUpdate = repository.UpdateMessage(actual2);

            Assert.IsTrue(testUpdate);

            AppMessage result = repository.GetMessage(actual2.Id);

            Assert.AreEqual(actual2.Id, result.Id);
            Assert.AreEqual(actual2.Title, result.Title);
            Assert.AreEqual(
                actual2.CreatedDate.Date,
                result.CreatedDate.Date
                );
            Assert.AreEqual(
                actual2.CreatedDate.Time,
                result.CreatedDate.Time
                );
            Assert.AreEqual(actual2.Quote, result.Quote);
            Assert.AreEqual(actual2.Author, result.Author);
            Assert.AreEqual(actual2.Source, result.Source);
        }
Пример #18
0
        /// <summary>
        /// Gets all the items for the mothly glance list view
        /// </summary>
        /// <param name="groups">The groups to categorize events</param>
        /// <returns>The list of ListViewItem to display</returns>
        public ListViewItem[] GetAll(ListViewGroupCollection groups)
        {
            DateTime today     = DateTime.Now;
            int      maxDay    = DateTime.DaysInMonth(today.Year, today.Month);
            DateTime startDate = today.AddDays(-(today.Day - 1));
            DateTime endDate   = today.AddDays(maxDay - today.Day).AddHours(23 - today.Hour).AddMinutes(59 - today.Minute).AddSeconds(59 - today.Second);

            DateAndTime todaysDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(today);
            DateAndTime start      = TimeAndDateUtility.ConvertDateTime_DateAndTime(startDate);
            DateAndTime end        = TimeAndDateUtility.ConvertDateTime_DateAndTime(endDate);

            List <SavedEvent>   events = _eventController.GetEvents(start, end).ToList();
            List <ListViewItem> items  = new List <ListViewItem>();

            events.ForEach(x =>
            {
                string[] details = CalculateStatus(todaysDate, x, end);
                string date      = details[1];

                ListViewItem item = new ListViewItem(details)
                {
                    Group =
                        date.Contains(COMPLETED) ? groups["Complete"]
                                : (date.Contains(STARTS_IN) ? groups["Upcoming"]
                                    : (date.Contains(ENDS_IN) ? groups["HappeningNow"]
                                        : (date.Contains(OVERDUE_FROM) ? groups["Overdue"] : null)))
                };

                item.Tag        = x.Id;
                bool groupIsSet = item.Group != null && !string.IsNullOrEmpty(item.Group.Name);
                if (groupIsSet)
                {
                    string groupName = item.Group.Name;

                    int groupIndex =
                        groupName == "Complete" ? 1
                                : groupName == "Upcoming" ? 2
                                    : groupName == "HappeningNow" ? 3
                                        : groupName == "Overdue" ? 4 : -1;

                    SetVisualDetails(groupIndex, item);
                    item.Tag = x.Id;
                }

                items.Add(item);
            }
                           );

            return(items.ToArray());
        }
Пример #19
0
        public bool UpdateLastShown(string id)
        {
            bool       updated = false;
            AppMessage message = _messageController.GetMessage(id);

            if (message != null)
            {
                message.LastDisplayedDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime());

                updated = _messageController.EditMessage(message);
            }

            return(updated);
        }
Пример #20
0
        /// <summary>
        /// Unlocks delay if the current date is greater than continued date
        /// </summary>
        /// <param name="currDate">The current date</param>
        public void Unlock(DateAndTime currDate)
        {
            if (DateDelayed != null && DateContinued != null)
            {
                DateCompare compare = TimeAndDateUtility.ComputeDiff(DateDelayed, currDate, DateContinued).Comparison;
                Lock = compare != DateCompare.None;

                if (!Lock)
                {
                    DateDelayed   = null;
                    DateContinued = null;
                }
            }
        }
Пример #21
0
        private void MessageTicker_Tick(object sender, EventArgs e)
        {
            Time time = TimeAndDateUtility.GetCurrentTime();

            if (_delay.DateDelayed != null && _delay.DateContinued != null)
            {
                _delay.Unlock(new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime()));
            }

            if (!_delay.Lock && time.Seconds % 30 == 0)
            {
                TriggerDelayedRefresh();
            }
        }
Пример #22
0
        private IEnumerable <SavedEvent> GetDateRestrictedResults(DateAndTime start, DateAndTime end)
        {
            bool nullStart = start == null;
            bool nullEnd   = end == null;

            new List <SavedEvent>();
            DateAndTime min = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.MinValue);

            IEnumerable <SavedEvent> events = !nullEnd && !nullStart?
                                              _eventRepo.GetEvents(start, end).ToList() : (nullEnd && !nullStart ?
                                                                                           _eventRepo.GetEvents(start).ToList() : (nullStart && !nullEnd ?
                                                                                                                                   _eventRepo.GetEvents(min, end).ToList() : new List <SavedEvent>()));

            return(events);
        }
Пример #23
0
        private void TimeTicker_Tick(object sender, EventArgs e)
        {
            Time   time       = TimeAndDateUtility.GetCurrentTime();
            string timeString = TimeAndDateUtility.ConvertTime_String(time);

            User_Time.SetText(timeString);
            NextUpdateProgress.Value = time.Seconds % 15;

            if (time.Seconds % 15 == 0)
            {
                UpdateEventList();
            }

            if (time.Seconds % 5 == 0)
            {
                EIV.UpdateEventDetailView();
                SEIV.UpdateEventDetailView();
            }
        }
Пример #24
0
        private string[] CalculateStatus(DateAndTime start, SavedEvent @event, DateAndTime end)
        {
            (TimeSpan TimeDiff, DateCompare Comparison)diff =
                TimeAndDateUtility.ComputeDiff(start, (@event.ActivationDate, @event.DeactivationDate), end);

            DateCompare comparison = diff.Comparison;
            string      template   = string.Empty;

            if (@event.Completed)
            {
                template = COMPLETED;
            }
            else if (comparison == DateCompare.Before)
            {
                template = STARTS_IN;
            }
            else if (comparison == DateCompare.During)
            {
                template = ENDS_IN;
            }
            else if (comparison == DateCompare.After)
            {
                template = OVERDUE_FROM;
            }

            TimeSpan span = diff.TimeDiff;

            string days  = $"{span.Days}D";
            string hours = $"{span.Hours}H";
            string mins  = $"{span.Minutes}M";
            string secs  = $"{span.Seconds}S";

            string resultString =
                template == COMPLETED ?
                template
                    : template
                + (span.Days > 0 ? days + " " : string.Empty)
                + (span.Hours > 0 ? hours + " " : string.Empty)
                + (span.Minutes > 0 ? mins + " " : string.Empty)
                + (span.Seconds > 0 ? secs : string.Empty);

            return(new string[] { @event.Title, resultString.Trim() });
        }
Пример #25
0
        internal void TriggerDelayedRefresh()
        {
            MessageTicker.Stop();
            RefreshMessage.Enabled = false;
            CopyMessage.Enabled    = false;
            PromptUser.Visible     = true;
            int    i       = 0;
            string loading = "Loading\r\n";
            Timer  timer   = new Timer
            {
                Interval = 375
            };

            timer.Tick += (s, ee) =>
            {
                if (i % 2 == 0)
                {
                    PromptUser.Text = $"{loading}⏳";
                }
                else
                {
                    PromptUser.Text = $"{loading}⌛";
                }

                if (i == 7)
                {
                    PromptUser.Visible = false;
                    PromptUser.Text    = string.Empty;
                    RefreshMessageDisplay();
                    timer.Stop();
                    MessageTicker.Start();
                    RefreshMessage.Enabled = true;
                    CopyMessage.Enabled    = true;
                }

                i++;
            };

            _delay.SetDelay(30, new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime()));
            timer.Start();
        }
Пример #26
0
        public void WhenAddingTheMessage_AddsSuccessful()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool testAdd = repository.AddMessage(actual);

            Assert.IsTrue(testAdd);
        }
Пример #27
0
        private IEnumerable <SavedEvent> GetSearchResults(DateAndTime start, DateAndTime end, string searchTerm)
        {
            bool nullStart  = start == null;
            bool nullEnd    = end == null;
            bool nullSearch = string.IsNullOrEmpty(searchTerm);

            IEnumerable <SavedEvent> events = new List <SavedEvent>();
            DateAndTime min = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.MinValue);

            List <SavedEvent> searchEvents = _eventRepo.GetEvents(searchTerm).ToList();

            List <SavedEvent> dateEvents;

            if (!nullStart && !nullEnd)
            {
                dateEvents = _eventRepo.GetEvents(start, end).ToList();
            }
            else
            {
                dateEvents = nullEnd && !nullStart?
                             _eventRepo.GetEvents(start).ToList() : (nullStart && !nullEnd ?
                                                                     _eventRepo.GetEvents(min, end).ToList() : new List <SavedEvent>());
            }

            bool searchHasResults = searchEvents.Any();
            bool dateHasResults   = dateEvents.Any();

            if (searchHasResults && dateHasResults)
            {
                events = searchEvents.Concat(dateEvents).GroupBy(x => x.Id).Select(x => x.First());
            }
            else
            {
                events = searchHasResults ?
                         searchEvents : (dateHasResults ?
                                         dateEvents : new List <SavedEvent>());
            }

            return(events);
        }
Пример #28
0
        public void WhenGettingTheMessage_HandlesNullParam()
        {
            #region Data

            AppMessage actual = new AppMessage
            {
                Id          = "1",
                Title       = "1",
                CreatedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(DateTime.Today),
                Quote       = "Test quote",
                Author      = "Test author",
                Show        = true,
                Source      = "From somewhere"
            };

            #endregion Data

            bool       testAdd = repository.AddMessage(actual);
            AppMessage result  = repository.GetMessage(null);

            Assert.IsTrue(testAdd);
            Assert.IsNull(result);
        }
Пример #29
0
        /// <summary>
        /// Toggles the complete status on an event
        /// </summary>
        /// <param name="id">The id of the event to toggle</param>
        /// <returns>Whether the event was updated</returns>
        public bool ToggleStatus(string id)
        {
            SavedEvent @event = GetEvent(id);

            if (@event == null)
            {
                return(false);
            }

            if (@event.Completed)
            {
                @event.Completed     = false;
                @event.CompletedDate = null;
            }
            else
            {
                DateTime date = DateTime.Now;
                @event.Completed     = true;
                @event.CompletedDate = TimeAndDateUtility.ConvertDateTime_DateAndTime(date);
            }

            return(_eventRepo.UpdateEvent(@event));
        }
Пример #30
0
        private void UpdateEventDetails()
        {
            try
            {
                string id = ((SavedEvent)Todays_Events.SelectedIndex())?.Id;
                if (!string.IsNullOrEmpty(id))
                {
                    SavedEvent @event = _events.GetEvent(id);

                    if (@event != null)
                    {
                        DateAndTime currDate = new DateAndTime(TimeAndDateUtility.GetCurrentDate(), TimeAndDateUtility.GetCurrentTime());

                        SetEventDetails(@event);
                        ToggleViewButtons(true, TimeAndDateUtility.IsBeforeRange(@event.ActivationDate, currDate));
                    }
                }
            }
            catch (Exception)
            {
                // Log
            }
        }