Пример #1
0
        public async Task Publish(DomainEvent domainEvent)
        {
            var currentUser = await _currentUserService.CurrentUser();

            var notificationType = typeof(DomainEventNotification <>);

            Type[] notificationArgs  = { domainEvent.GetType() };
            var    notificationBuild = notificationType.MakeGenericType(notificationArgs);
            var    notification      = Activator.CreateInstance(notificationBuild, domainEvent, currentUser) !;

            await _mediator.Publish(new DomainEventNotification <DomainEvent>(domainEvent, currentUser));

            await _mediator.Publish(notification);
        }
Пример #2
0
        public async Task <DeliveryModel> AddOrUpdateDelivery([FromBody] AddOrEditDeliveryModel dm)
        {
            var currentUser = await currentUserService.CurrentUser();

            var delivery = await context.Delivery
                           .FirstOrDefaultAsync(d => d.Id == dm.Id);

            if (delivery == null)
            {
                delivery = new Delivery
                {
                    Address                = dm.Address,
                    Courier                = await context.Users.FirstOrDefaultAsync(u => u.Id == dm.CourierId),
                    CourierService         = await context.Users.FirstOrDefaultAsync(u => u.Id == currentUser.Id),
                    Description            = dm.Description,
                    EstimatedDeliveryEnd   = dm.EstimatedDeliveryEnd,
                    EstimatedDeliveryStart = dm.EstimatedDeliveryStart,
                    PackageId              = Convert.ToBase64String((Guid.NewGuid().ToByteArray())).Replace('/', 'S'),
                    PaymentInfo            = dm.PaymentInfo,
                    RecipientEmailAddress  = dm.RecipientEmailAddress,
                    RecipientName          = dm.RecipientName,
                    RecipientPhoneNumber   = dm.RecipientPhoneNumber,
                    SenderEmailAddress     = currentUser.Email,
                    SenderName             = currentUser.DisplayName,
                    SenderPhoneNumber      = currentUser.PhoneNumber,
                    State = dm.State
                };
                context.Delivery.Add(delivery);
            }
            else
            {
                delivery.Address = dm.Address;
                delivery.Courier = await context.Users.FirstOrDefaultAsync(u => u.Id == dm.CourierId);

                delivery.Description            = dm.Description;
                delivery.EstimatedDeliveryEnd   = dm.EstimatedDeliveryEnd;
                delivery.EstimatedDeliveryStart = dm.EstimatedDeliveryStart;
                delivery.PaymentInfo            = dm.PaymentInfo;
                delivery.RecipientEmailAddress  = dm.RecipientEmailAddress;
                delivery.RecipientName          = dm.RecipientName;
                delivery.RecipientPhoneNumber   = dm.RecipientPhoneNumber;
                delivery.State = dm.State;
            }

            await context.SaveChangesAsync();

            return(delivery.ToDto());
        }
Пример #3
0
        protected async Task <UserData> UserData()
        {
            try
            {
                var currentUser = await CurrentUserService.CurrentUser();

                return(currentUser != null ? new UserData()
                {
                    UserId = currentUser.Id, TenantId = currentUser.Tenant.Id
                }
                    : new UserData());
            }
            catch (Exception)
            {
                return(new UserData());
            }
        }
Пример #4
0
        public async Task Handle(DomainEventNotification <MaxLoginAttemptsReached> notification, CancellationToken cancellationToken)
        {
            var user = notification.DomainEvent.User;

            _logger.LogInformation($"User {user.Name} reached max login attempts");

            var currentUserId = (await _currentUserService.CurrentUser())?.Id ?? user.Id;
            var command       = new DisableUserCommand()
            {
                DisablementTypeId = GeneralConstants.DisablementBlockedByLoginTriesId,
                Observation       = "",
                ToDisableId       = user.Id,
                DisabledById      = currentUserId
            };

            await _mediator.Send(command, cancellationToken);
        }
Пример #5
0
        private async Task <GrpcChannel> CreateServiceChannel()
        {
            var address = _config["Api:Chat"];
            var user    = await _currentUserService.CurrentUser();

            var credentials = CallCredentials.FromInterceptor((context, metadata) =>
            {
                if (!string.IsNullOrEmpty(user.AccessToken))
                {
                    metadata.Add("Authorization", $"Bearer {user.AccessToken}");
                }
                return(Task.CompletedTask);
            });
            var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
            {
                Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
            });

            return(channel);
        }
Пример #6
0
        public void ProcessPayment(PaymentModel model)
        {
            var user    = currentUserService.CurrentUser();
            var userDto = Context.Users.FirstOrDefault(x => x.Id == user.Id);
            var plan    = stripeService.GetPlans().FirstOrDefault(x => x.Id == model.PlanId);


            if (userDto.StripeId == null)
            {
                var customer = stripeService.CreateCustomer(model.Token.email, model.Token.id);
                userDto.StripeId = customer.Id;
                Context.SaveChanges();
            }
            else
            {
                var currentSub = stripeService.CurrentSubForCustomer(userDto.StripeId);
                if (currentSub != null)
                {
                    stripeService.CancelSub(currentSub.Id);
                }
            }
            stripeService.CreateSubscription(plan.Id, userDto.StripeId);
        }
Пример #7
0
 public async Task <CourierServiceModel> Me()
 {
     return((await currentUserService.CurrentUser()).ToDto());
 }
Пример #8
0
        public async Task <IActionResult> Handle()
        {
            var currentUser = await _currentUserService.CurrentUser();

            return(Ok(currentUser));
        }