private async Task <List <HandlerServiceResult> > ConfigureOperationDate(string answer, User user)
        {
            answer = answer.Trim();

            if (string.IsNullOrEmpty(answer))
            {
                return(new List <HandlerServiceResult> {
                    _resultService.BuildOperationInvalidDateErrorResult()
                });
            }

            DateTime date;

            if (answer.Equals("now"))
            {
                date = DateTime.Now;
            }
            else
            {
                var dayMonthYear = answer.Split('.');

                try
                {
                    date = new DateTime(int.Parse(dayMonthYear[2]), int.Parse(dayMonthYear[1]),
                                        int.Parse(dayMonthYear[0]));
                }
                catch (Exception)
                {
                    return(new List <HandlerServiceResult> {
                        _resultService.BuildOperationInvalidDateErrorResult()
                    });
                }
            }

            if (date > DateTime.Now)
            {
                return(new List <HandlerServiceResult>
                {
                    _resultService.BuildOperationInvalidDateErrorResult()
                });
            }

            var operation = await GetOrCreateOperationAsync(user);

            operation.Date       = date;
            operation.Configured = true;

            await _operationDocumentService.UpdateAsync(operation);

            user.Context = null;

            await _userDocumentService.UpdateAsync(user);

            return(new List <HandlerServiceResult> {
                _resultService.BuildFinishedConfiguringOperationResult()
            });
        }
        private async Task <List <HandlerServiceResult> > ConfigureCategoryDateRange(string answer, User user)
        {
            answer = answer.Trim();

            if (string.IsNullOrEmpty(answer))
            {
                return(new List <HandlerServiceResult>
                {
                    _resultService.BuildEmptyAnswerErrorResult()
                });
            }

            var category = await _categoryDocumentService.GetByIdAsync(user.Context.CategoryId);

            if (answer.Equals("All time"))
            {
                user.Context = null;

                await _userDocumentService.UpdateAsync(user);

                return(await _statsService.BuildStatistics(category));
            }

            try
            {
                var dateStrings = answer.Split('-');
                var from        = dateStrings[0].Split('.');
                var to          = dateStrings[1].Split('.');

                var fromDate = new DateTime(int.Parse(from[2]), int.Parse(from[1]), int.Parse(from[0]));
                var toDate   = new DateTime(int.Parse(to[2]), int.Parse(to[1]), int.Parse(to[0]));

                var operations = await _operationDocumentService.GetByCategoryId(category.Id);

                operations = operations.Where(o => o.Date >= fromDate && o.Date <= toDate).ToList();

                if (operations.Count == 0)
                {
                    return(new List <HandlerServiceResult>
                    {
                        _resultService.BuildStatsNoOperationsOnDateRangeErrorResult()
                    });
                }

                user.Context = null;
                await _userDocumentService.UpdateAsync(user);

                return(await _statsService.BuildStatistics(category, fromDate, toDate));
            }
            catch (Exception)
            {
                return(new List <HandlerServiceResult>
                {
                    _resultService.BuildOperationInvalidDateErrorResult()
                });
            }
        }