Exemple #1
0
        private void CheckRecordExistance(List <Record> records, PeriodFilterType period, RecordType recordType, bool includeWithoutCategory, List <int> categoryIds = null)
        {
            var service    = (IRecordService)serviceIdManageable;
            var allRecords = service.GetListForUser(user.Id);

            var entityFetched = service.Get(user.Id, period, recordType, includeWithoutCategory, categoryIds);

            //entityFetched.Count.ShouldBeEquivalentTo(records.Count);

            foreach (var record in records)
            {
                entityFetched.FirstOrDefault(_ => _.Id == record.Id).Should().NotBeNull();
            }
        }
Exemple #2
0
        private Tuple <DateTime, DateTime> GetPeriod(PeriodFilterType period)
        {
            var settingsService = new GeneralSettingService(App.Db);
            var firstDayOfWeek  = settingsService.GetForUser(user.Id).FirstDayOfWeek;

            DateTime from, until;
            int      tmp1, tmp2;

            switch (period)
            {
            case PeriodFilterType.Today:
                from  = DateTime.Today;
                until = DateTime.Today.AddDays(1).AddMinutes(-1);
                break;

            case PeriodFilterType.Yesterday:
                from  = DateTime.Today.AddDays(-1);
                until = DateTime.Today.AddMinutes(-1);
                break;

            case PeriodFilterType.ThisWeek:
                tmp1 = (int)DateTime.Today.DayOfWeek;
                tmp2 = 0;
                while (tmp1 != (int)firstDayOfWeek)
                {
                    if (tmp1 == 0)
                    {
                        tmp1 = (int)DayOfWeek.Saturday;
                    }
                    else
                    {
                        tmp1--;
                    }
                    tmp2++;
                }

                from  = DateTime.Today.AddDays(-tmp2);
                until = DateTime.Today.AddDays(7 - tmp2).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousWeek:
                tmp1 = (int)DateTime.Today.DayOfWeek;
                tmp2 = 0;
                while (tmp1 != (int)firstDayOfWeek)
                {
                    if (tmp1 == 0)
                    {
                        tmp1 = (int)DayOfWeek.Saturday;
                    }
                    else
                    {
                        tmp1--;
                    }
                    tmp2++;
                }

                from  = DateTime.Today.AddDays(-tmp2 - 7);
                until = DateTime.Today.AddDays(-tmp2).AddMinutes(-1);
                break;

            case PeriodFilterType.ThisMonth:
                from  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                until = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)).AddDays(1).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousMonth:
                tmp1 = DateTime.Today.Month > 1 ? DateTime.Today.Year : DateTime.Today.Year - 1;
                tmp2 = DateTime.Today.Month > 1 ? DateTime.Today.Month - 1 : 12;

                from  = new DateTime(tmp1, tmp2, 1);
                until = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMinutes(-1);
                break;

            case PeriodFilterType.ThisYear:
                from  = new DateTime(DateTime.Today.Year, 1, 1);
                until = new DateTime(DateTime.Today.Year + 1, 1, 1).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousYear:
                from  = new DateTime(DateTime.Today.Year - 1, 1, 1);
                until = new DateTime(DateTime.Today.Year, 1, 1).AddMinutes(-1);
                break;

            default:
                var rand = new Random();
                from  = DateTime.Today.AddDays(-rand.Next(365));
                until = DateTime.Today.AddDays(rand.Next(365));
                break;
            }

            return(new Tuple <DateTime, DateTime>(from, until));
        }
Exemple #3
0
        private List <Record> CreateRecords(PeriodFilterType period, RecordType recordType, Action <Record> overrides = null)
        {
            var settingsService = new GeneralSettingService(App.Db);
            var firstDayOfWeek  = settingsService.GetForUser(user.Id).FirstDayOfWeek;

            DateTime from, until;
            int      tmp1, tmp2;

            switch (period)
            {
            case PeriodFilterType.Today:
                from  = DateTime.Today;
                until = DateTime.Today.AddDays(1).AddMinutes(-1);
                break;

            case PeriodFilterType.Yesterday:
                from  = DateTime.Today.AddDays(-1);
                until = DateTime.Today.AddMinutes(-1);
                break;

            case PeriodFilterType.ThisWeek:
                tmp1 = (int)DateTime.Today.DayOfWeek;
                tmp2 = 0;
                while (tmp1 != (int)firstDayOfWeek)
                {
                    tmp1--; tmp2++;
                }

                from  = DateTime.Today.AddDays(-tmp2);
                until = DateTime.Today.AddDays(7 - tmp2).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousWeek:
                tmp1 = (int)DateTime.Today.DayOfWeek;
                tmp2 = 0;
                while (tmp1 != (int)firstDayOfWeek)
                {
                    tmp1--; tmp2++;
                }

                from  = DateTime.Today.AddDays(-tmp2 - 7);
                until = DateTime.Today.AddDays(-tmp2).AddMinutes(-1);
                break;

            case PeriodFilterType.ThisMonth:
                from  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                until = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)).AddDays(1).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousMonth:
                tmp1 = DateTime.Today.Month > 1 ? DateTime.Today.Year : DateTime.Today.Year - 1;
                tmp2 = DateTime.Today.Month > 1 ? DateTime.Today.Month - 1 : 12;

                from  = new DateTime(tmp1, tmp2, 1);
                until = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMinutes(-1);
                break;

            case PeriodFilterType.ThisYear:
                from  = new DateTime(DateTime.Today.Year, 1, 1);
                until = new DateTime(DateTime.Today.Year + 1, 1, 1).AddMinutes(-1);
                break;

            case PeriodFilterType.PreviousYear:
                from  = new DateTime(DateTime.Today.Year - 1, 1, 1);
                until = new DateTime(DateTime.Today.Year, 1, 1).AddMinutes(-1);
                break;

            default:
                var rand = new Random();
                from  = DateTime.Today.AddDays(-rand.Next(365));
                until = DateTime.Today.AddDays(rand.Next(365));
                break;
            }

            return(App.Factory.CreateRecords(user.Id, from, until, record =>
            {
                record.RecordType = recordType;
                overrides?.Invoke(record);
            }));
        }