コード例 #1
0
        public async Task <int> Handle(AddItemCommand request, CancellationToken cancellationToken)
        {
            // auth user id, later with service
            var authUserId = request.UserId;

            // only valid members can add items to a shopping trip
            if (!await _repository.HasAccessToShoppingTrip(authUserId, request.ShoppingTripId, cancellationToken))
            {
                throw new NoAccessToShoppingTripException();
            }

            // attach shopping trip
            var shoppingTrip = new ShoppingTrip {
                Id = request.ShoppingTripId
            };

            _repository.ShoppingTrips.Attach(shoppingTrip);

            // map to shopping trip item and add to trip
            var shoppingTripItem = _mapper.Map <ShoppingTripItem>(request);

            shoppingTrip.Items.Add(shoppingTripItem);

            await _repository.SaveChangesAsync(cancellationToken);

            return(shoppingTripItem.Id);
        }
コード例 #2
0
        public async Task <Unit> Handle(ChangeShoppingTripInfoCommand request, CancellationToken cancellationToken)
        {
            // auth user id, later with service
            var authUserId = request.UserId;

            // check if the user is the creator of the shopping trip that exists in a group
            if (!await _repository.IsCreatorOfShoppingTrip(authUserId, request.GroupId, request.ShoppingTripId, cancellationToken))
            {
                throw new NotCreatorOfShoppingTripException();
            }

            // attach shopping trip
            var shoppingTrip = new ShoppingTrip {
                Id = request.ShoppingTripId
            };

            _repository.ShoppingTrips.Attach(shoppingTrip);

            // change base information
            shoppingTrip.Name   = request.Name;
            shoppingTrip.Reason = request.Reason;

            await _repository.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(ChangeShoppingTripPlanningCommand request, CancellationToken cancellationToken)
        {
            // auth user id, later with service
            var authUserId = request.UserId;

            // check if the user is the creator of the shopping trip that exists in a group
            if (!await _repository.IsCreatorOfShoppingTrip(authUserId, request.GroupId, request.ShoppingTripId, cancellationToken))
            {
                throw new NotCreatorOfShoppingTripException();
            }

            // attach shopping trip with location
            var shoppingTrip = new ShoppingTrip {
                Id = request.ShoppingTripId, Location = new Location {
                    ShoppingTripId = request.ShoppingTripId
                }
            };

            _repository.ShoppingTrips.Attach(shoppingTrip);

            // change information shopping trip
            shoppingTrip.StartTime      = request.StartTime;
            shoppingTrip.Transportation = request.Transportation;
            shoppingTrip.Location       = _mapper.Map <Location>(request.Location);

            await _repository.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }