public async Task <int> Create(Meso meso)
        {
            meso.UserId = _identity.GetUserId();
            _context.Add(meso);
            await _context.SaveChangesAsync();

            return(meso.Id);
        }
Esempio n. 2
0
        protected override async Task Handle(AddOpinionForDriverCommand request, CancellationToken cancellationToken)
        {
            var driver = await _driversRepository.GetByIdAsync(request.DriverId);

            driver.AddOpinion(request.Value, request.Description, _identityProvider.GetUserId());
            await _unitOfWork.SaveAsync();
        }
Esempio n. 3
0
        public override Task OnConnectedAsync()
        {
            Groups.AddToGroupAsync(Context.ConnectionId, _identityProvider.GetRole());
            Groups.AddToGroupAsync(Context.ConnectionId, _identityProvider.GetUserId());

            return(base.OnConnectedAsync());
        }
Esempio n. 4
0
        protected override async Task Handle(SetDefaultPaymentMethodCommand request, CancellationToken cancellationToken)
        {
            var customer = await _customersRepository.GetAsync(_identityProvider.GetUserId());

            customer.SetDefaultPaymentMethod(request.PaymentMethodId);

            await _unitOfWork.SaveAsync();
        }
Esempio n. 5
0
        public async Task <RideDto> Handle(GetCurrentRideQuery request, CancellationToken cancellationToken)
        {
            var ride = await _ridesRepository.GetCurrentCustomerRideAsync(_identityProvider.GetUserId());

            if (ride is null)
            {
                throw new ResourceDoesNotExistException(typeof(Ride));
            }

            return(_mapper.Map <RideDto>(ride));
        }
        public async Task <Guid> Handle(AddPaymentMethodCommand request, CancellationToken cancellationToken)
        {
            var customer = await _customersRepository.GetAsync(_identityProvider.GetUserId());

            var paymentMethod = _mapper.Map <PaymentMethod>(request);

            customer.AddPaymentMethod(paymentMethod);

            await _unitOfWork.SaveAsync();

            return(paymentMethod.Id);
        }
Esempio n. 7
0
        public async Task <Guid> Handle(OrderRideCommand request, CancellationToken cancellationToken)
        {
            var userId = _identityProvider.GetUserId();
            var ride   = await _rideFactory.CreateRideAsync(userId, request.Address, request.Latitude, request.Longitude,
                                                            request.CouponCode);

            await _ridesRepository.AddRideAsync(ride);

            await _unitOfWork.SaveAsync();

            return(ride.Id);
        }
Esempio n. 8
0
        protected override async Task Handle(PickUpRideCommand request, CancellationToken cancellationToken)
        {
            var userId = _identityProvider.GetUserId();

            var driver = await _driversRepository.GetByIdAsync(userId);

            var ride = await _ridesRepository.GetByIdAsync(request.RideId);

            ride.AssignDriver(driver);

            ride.Version = request.Version;
            await _unitOfWork.SaveAsync();
        }
 public virtual Task InsertAsync(TCollection document)
 {
     document.UserId = _identityProvider.GetUserId();
     return(Collection.InsertOneAsync(document));
 }
        public async Task <IEnumerable <PaymentMethodDto> > Handle(GetPaymentMethodsQuery request, CancellationToken cancellationToken)
        {
            var customer = await _customersRepository.GetAsync(_identityProvider.GetUserId());

            return(_mapper.Map <IEnumerable <PaymentMethodDto> >(customer.PaymentMethods));
        }
Esempio n. 11
0
        public async Task <IEnumerable <RideDto> > Handle(GetUnpaidRidesQuery request, CancellationToken cancellationToken)
        {
            var unpaidRides = await _customersRepository.GetUnpaidRidesAsync(_identityProvider.GetUserId());

            return(_mapper.Map <IEnumerable <RideDto> >(unpaidRides));
        }
 private static void AppendUserInfoToRequest(DownstreamRequest request, IIdentityProvider identityProvider)
 {
     request.Headers.Add(Constants.UserIdHeaderKey, identityProvider.GetUserId().ToString());
     request.Headers.Add(Constants.UsernameHeaderKey, identityProvider.getUsername());
 }
Esempio n. 13
0
 protected Guid UserId()
 {
     return(_identityProvider.GetUserId());
 }
Esempio n. 14
0
        public async Task <dynamic> GetMuscleGroupBreakdown(int mesoId)
        {
            var muscleGroupsWithCount = await _context.MuscleGroupCount.FromSql($"SELECT MuscleGroupId, COUNT(*) AS Count FROM Exercises e INNER JOIN Mesocycles m ON e.MesoId = m.Id WHERE m.UserId = '{_identity.GetUserId()}' AND m.Id = {mesoId} GROUP BY MuscleGroupId").ToListAsync();

            var allMuscleGroups = (int[])Enum.GetValues(typeof(MuscleGroup));

            muscleGroupsWithCount.AddRange(allMuscleGroups.
                                           Where(x => !muscleGroupsWithCount.Any(y => y.MuscleGroupId == x))
                                           .Select(z => new MuscleGroupCount {
                MuscleGroupId = z, Count = 0
            }));

            return(muscleGroupsWithCount.Select(x => new { Name = Enum.GetName(typeof(MuscleGroup), x.MuscleGroupId), x.Count }).ToList());
        }