示例#1
0
        public async Task <IEnumerable <GetUserNotificationsQueryResult> > GetActiveUserNotifications()
        {
            var userNotifications = NotificationProcessor.GetNotifications();

            var notHiddenNotifications =
                QueryProcessor.Execute(new GetUserNotificationsQuery(GetUserNotificationsType.Visible));

            if (userNotifications.Any())
            {
                await Task.Run(
                    () => CommandProcessor.Execute(new AddUserNotificationCommand(userNotifications))
                    ).ConfigureAwait(true);
            }

            return
                (userNotifications
                 .Select(notification => new GetUserNotificationsQueryResult
            {
                Key = notification.Key,
                Text = notification.Text,
                Title = notification.Title,
                CreatedAt = notification.CreatedAt,
                Type = Enum.GetName(typeof(UserNotificationType), notification.Type)
            })
                 .Union(notHiddenNotifications)
                 .OrderBy(x => x.CreatedAt));
        }
示例#2
0
        public override void Handle(RecalculateDiffCommand command)
        {
            var specification = command.ForAll
                ? new CommonSpecification <MeterMeasurement>(x => true)
                : new MeterMeasurementSpec.WithoutDiff() as Specification <MeterMeasurement>;

            var measurementItems = Repository.Where(specification).ToList();
            var warnings         = new List <string>();

            foreach (var measurementItem in measurementItems)
            {
                var previousItem = QueryProcessor.Execute(new GetSiblingMeasurementQuery(measurementItem.MeterMeasurementTypeId, measurementItem.Date, GetSiblingMeasurementDirection.Previous));

                if (previousItem != null)
                {
                    if (previousItem.Measurement >= measurementItem.Measurement)
                    {
                        warnings.Add($"[{measurementItem.MeasurementType.Name} - {measurementItem.Date:MMMM yyyy}]: Value is less than previous one");
                    }
                    else
                    {
                        measurementItem.Diff = Math.Abs(previousItem.Measurement - measurementItem.Measurement);
                    }
                }
                else
                {
                    warnings.Add($"[{measurementItem.MeasurementType.Name} - {measurementItem.Date:MMMM yyyy}]: Previous measurement not found");
                }
            }

            if (warnings.Any())
            {
                command.Warnings = warnings;
            }
        }
示例#3
0
        public GetMeterMeasurementTypeResponse GetMeasurementType(long?id)
        {
            if (!id.HasValue || id.Value == default)
            {
                throw new ArgumentNullException(nameof(id));
            }

            return(QueryProcessor.Execute(new GetMeterMeasurementTypeQuery(id.Value)));
        }
示例#4
0
        public GetPaymentResponse GetPayment(long?id)
        {
            if (!id.HasValue || id.Value == default)
            {
                throw new ArgumentNullException(nameof(id));
            }

            return(QueryProcessor.Execute(new GetPaymentQuery(id.Value)));
        }
        public GetMeasurementStatisticsQueryResponse GetMeasurementStatistics([FromQuery] GetMeasurementStatisticsRequest request)
        {
            if (request == null)
            {
                throw new Exception("Year and Measurement type must be specified.");
            }

            return(QueryProcessor.Execute(new GetMeasurementStatisticsQuery(request.From, request.To, request.MeasurementTypeId)));
        }
示例#6
0
        public IEnumerable <GetMeterMeasurementsResponse> GetMeasurements([FromQuery] GetMeterMeasurementRequest filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            return(QueryProcessor.Execute(
                       new GetMeterMeasurementsQuery(filter.Month, filter.MeasurementTypeId, filter.Year)));
        }
示例#7
0
        public IEnumerable <GetPaymentsResponse> GetPayments([FromQuery] GetPaymentsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(QueryProcessor.Execute(
                       new GetPaymentsQuery(request.Month, request.Year, request.PaymentTypeId,
                                            request.Amount?.Exact, request.Amount?.Min, request.Amount?.Max)));
        }
示例#8
0
        public async Task OnTurn(ITurnContext context)
        {
            if (context.Activity.Type == ActivityTypes.Message)
            {
                var state = context.GetConversationState <SearchState>();

                var processor = new QueryProcessor();

                var text = await processor.Execute(context.Activity.Text);

                await context.SendActivity($"### Found the following:\r\n{text}");
            }
        }
示例#9
0
        private void Validate(MeterMeasurement measurement, UpdateMeterMeasurementCommand command)
        {
            if (measurement == null)
            {
                throw new ArgumentException($"Measurement with id {command.Id} doesn't exist.");
            }

            if (command.Measurement <= 0)
            {
                throw new ArgumentException($"Value must be greater than 0.");
            }

            var meterMeasurementType =
                MeterMeasurementTypeRepository.Get(command.MeterMeasurementTypeId);

            if (meterMeasurementType == null)
            {
                throw new ArgumentException($"Measurement type with id \"{command.MeterMeasurementTypeId}\" doesn't exist");
            }

            var measurementOnSpecifiedMonth =
                Repository.Where(new CommonSpecification <MeterMeasurement>(x =>
                                                                            x.Date.Date == command.Date &&
                                                                            x.MeterMeasurementTypeId == command.MeterMeasurementTypeId &&
                                                                            x.Id != command.Id))
                .FirstOrDefault();

            if (measurementOnSpecifiedMonth != null)
            {
                throw new ArgumentException($"Measurement record for {measurementOnSpecifiedMonth.MeasurementType.Name} {command.Date:MMMM yyyy} is already exist.");
            }

            var previousTypeValue =
                QueryProcessor.Execute(new GetSiblingMeasurementQuery(command.MeterMeasurementTypeId, command.Date, GetSiblingMeasurementDirection.Previous));

            if (previousTypeValue != null && command.Measurement < previousTypeValue.Measurement)
            {
                throw new ArgumentException($"Measurement value \"{command.Measurement}\" must be greater than previous \"{previousTypeValue.Measurement}\".");
            }

            var closestNextMeasurement =
                QueryProcessor.Execute(new GetSiblingMeasurementQuery(command.MeterMeasurementTypeId, command.Date, GetSiblingMeasurementDirection.Next));

            if (closestNextMeasurement != null && command.Measurement >= closestNextMeasurement.Measurement)
            {
                throw new ArgumentException($"Measurement value \"{command.Measurement}\" must be less than next \"{closestNextMeasurement.Measurement}\".");
            }
        }
        public override IEnumerable <UserNotification> GetNotifications()
        {
            var today = DateTime.Today;

            var displayNotificationSetting      = QueryProcessor.Execute(new GetNamedUserSettingQuery(DefaultUserSettings.DisplayMeasurementsNotification.ToString()));
            var displayNotificationSettingValue = UserSettingUtilities.GetTypedSettingValue <Boolean>(displayNotificationSetting);

            if (displayNotificationSettingValue && today.Day >= 20)
            {
                var wasNotificationFormed = CheckWasNotificationFormed($"MeasurementNotificationFor{today.Year}{today.Month}");

                if (!wasNotificationFormed)
                {
                    var measurements =
                        QueryProcessor.Execute(
                            new GetMeterMeasurementsQuery((byte?)today.Month, year: today.Year)
                            )
                        .SelectMany(x => x.Measurements.Select(y => y.MeterMeasurementTypeId))
                        .Distinct();

                    var measurementTypes =
                        QueryProcessor.Execute(new GetMeterMeasurementTypesQuery());

                    if (measurementTypes.Count() != measurements.Count())
                    {
                        var notFilledIds =
                            measurementTypes
                            .Select(x => x.Id)
                            .Except(measurements)
                            .ToArray();

                        var measurementTypesWithoutMeasurement =
                            measurementTypes.Where(x => notFilledIds.Contains(x.Id)).Select(x => x.Name);

                        var type = today.Day <= 23 ? UserNotificationType.Info : UserNotificationType.Warning;

                        yield return(new UserNotification
                        {
                            Type = (short)type,
                            Title = "Measurement not added",
                            Key = $"MeasurementNotificationFor{today.Year}{today.Month}",
                            Text = $"Measurenemt for [{today.ToString("MMMM yyyy")}] not added for next types: {string.Join(", ", measurementTypesWithoutMeasurement)}"
                        });
                    }
                }
            }
        }
        private void ValidateSignOver(ActionExecutingContext filterContext)
        {
            // do not validate unless this is the sign-over page
            if (!IsSignOver)
            {
                return;
            }

            // must be impersonating to undo
            var wasSignedInAs = filterContext.HttpContext.Session.WasSignedInAs();

            if (IsSignOverUndo && string.IsNullOrWhiteSpace(wasSignedInAs))
            {
                filterContext.Result = new HttpNotFoundResult();
                return;
            }

            // candidate principal may already be impersonating
            var userName = wasSignedInAs ??
                           filterContext.HttpContext.User.Identity.Name;

            // username must have value
            if (!string.IsNullOrWhiteSpace(userName))
            {
                var user = QueryProcessor.Execute(
                    new GetUserByNameQuery
                {
                    Name      = userName,
                    EagerLoad = new Expression <Func <User, object> >[]
                    {
                        u => u.Grants.Select(g => g.Role)
                    },
                }
                    );

                // valid when user is in the authentication agent role
                if (user != null && user.IsInRole(RoleName.AuthenticationAgent))
                {
                    return;
                }
            }

            // set the result and return
            filterContext.Result = new HttpNotFoundResult();
        }
示例#12
0
        public void SendMeasurements([FromBody] IEnumerable <long> measurementIdentifiers)
        {
            if (!measurementIdentifiers.Any())
            {
                throw new ArgumentException("No measurement identifiers not specified");
            }

            var recipientEmail = QueryProcessor.Execute(new GetNamedUserSettingQuery(DefaultUserSettings.EmailToSendMeasurements.ToString()));

            var isValidEmail = Validate.Email(recipientEmail.RawValue);

            if (!isValidEmail)
            {
                throw new ArgumentException($"User setting \"{recipientEmail.RawValue}\" isn't recognized as email.");
            }

            CommandProcessor.Execute(new SendMeasurementsCommand(recipientEmail.RawValue, measurementIdentifiers));
        }
        private void Validate(AddMeasurementGroupCommand command)
        {
            var notValidMeasurements = command.Measurements.Where(x => x.Measurement <= 0);

            if (notValidMeasurements.Any())
            {
                throw new ArgumentException($"Measurement value must be greater than 0.");
            }

            var hasDuplicateTypes =
                new HashSet <long>(command.Measurements.Select(x => x.MeasurementTypeId)).Count != command.Measurements.Count();

            if (hasDuplicateTypes)
            {
                throw new ArgumentException("Cannot add measurements with duplicate types.");
            }

            var notValidTypes =
                command.Measurements
                .Where(x => MeterMeasurementTypeRepository.Get(x.MeasurementTypeId) == null)
                .Select(x => x.MeasurementTypeId);

            if (notValidTypes.Any())
            {
                throw new CommandExecutionException(CommandType, $"Measurement types with ids [{string.Join(",", notValidTypes)}] doesn't exist.");
            }

            var measurementsOnSpecifiedMonth =
                Repository.Where(new CommonSpecification <MeterMeasurement>(x => x.Date.Date == command.Date))
                .ToList();

            var duplicateTypes =
                command.Measurements
                .Where(measurementData =>
                       measurementsOnSpecifiedMonth.FirstOrDefault(x => x.MeterMeasurementTypeId == measurementData.MeasurementTypeId) != null)
                .Select(x => new {
                TypeName = MeterMeasurementTypeRepository.Get(x.MeasurementTypeId).Name,
                x.Measurement
            }).Select(x => $"{x.TypeName} - {x.Measurement}");

            if (duplicateTypes.Any())
            {
                throw new ArgumentException($"Measurements for {command.Date:MMMM yyyy} is already exists for next types: {string.Join("; ", duplicateTypes)}.");
            }

            foreach (var measurementData in command.Measurements)
            {
                var previousTypeValue =
                    QueryProcessor.Execute(new GetSiblingMeasurementQuery(measurementData.MeasurementTypeId, command.Date, GetSiblingMeasurementDirection.Previous));

                if (previousTypeValue != null && measurementData.Measurement < previousTypeValue.Measurement)
                {
                    throw new ArgumentException($"Measurement value \"{measurementData.Measurement}\" must be greater than previous \"{previousTypeValue.Measurement}\".");
                }

                var closestNextMeasurement =
                    QueryProcessor.Execute(new GetSiblingMeasurementQuery(measurementData.MeasurementTypeId, command.Date, GetSiblingMeasurementDirection.Next));

                if (closestNextMeasurement != null && measurementData.Measurement >= closestNextMeasurement.Measurement)
                {
                    throw new ArgumentException($"Measurement value \"{measurementData.Measurement}\" must be less than next \"{closestNextMeasurement.Measurement}\".");
                }
            }
        }
示例#14
0
 public IEnumerable <GetMailMessageLogsQueryResult> GetMailMessageLogs()
 {
     return(QueryProcessor.Execute(new GetMailMessageLogsQuery()));
 }
示例#15
0
 public int GetMeasurementsWithoutDiff()
 {
     return(QueryProcessor.Execute(new GetMeasurementsWithoutDiffQuery()));
 }
示例#16
0
 public IEnumerable <GetPaymentTypesResponse> GetPaymentTypes()
 {
     return(QueryProcessor.Execute(new GetPaymentTypesQuery()));
 }
示例#17
0
 public GetPaymentAverageValueResponse GetAverageValues()
 {
     return(QueryProcessor.Execute(new GetPaymentAverageValueQuery()));
 }
示例#18
0
 public ActionResult Insert()
 {
     return(PartialView("Insert", QueryProcessor.Execute(new GetNewAlbumQuery())));
 }
示例#19
0
 public ActionResult Edit(GetAlbumsByIdQuery query)
 {
     return(PartialView("Edit", QueryProcessor.Execute(query)));
 }
示例#20
0
 public ActionResult Details(GetAlbumsByIdQuery query)
 {
     return(PartialView("Details", QueryProcessor.Execute(query)));
 }
示例#21
0
 public IEnumerable <GetUserNotificationsQueryResult> GetUserNotifications()
 {
     return(QueryProcessor.Execute(new GetUserNotificationsQuery(GetUserNotificationsType.All)));
 }
示例#22
0
 public IReadOnlyCollection <GetUserSettingsQueryResult> GetSettings()
 {
     return(QueryProcessor.Execute(new GetUserSettingsQuery()));
 }
示例#23
0
 public ActionResult Browse(GetAllAlbumsQuery query)
 {
     return(Json(QueryProcessor.Execute(query), JsonRequestBehavior.AllowGet));
 }