Пример #1
0
        public PlaceInputGroupGraphType(IPlaceRepository placeRepository)
        {
            FieldAsync <NonNullGraphType <PlaceType> >(
                "insert",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <PlaceInsertInputType> > {
                Name = "place"
            }),
                resolve: async(context) =>
            {
                var place = context.GetArgument <Place>("place");
                await placeRepository.InsertAsync(place);
                return(place);
            });

            FieldAsync <PlaceType>(
                "update",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <PlaceUpdateInputType> > {
                Name = "place"
            }),
                resolve: async(context) =>
            {
                var place = context.GetArgument <Place>("place");
                await placeRepository.UpdateAsync(place);
                return(place);
            });

            FieldAsync <PlaceType>(
                "partialUpdate",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <PlacePartialUpdateInputType> > {
                Name = "place"
            }),
                resolve: async(context) =>
            {
                var values = context.Arguments["place"] as IDictionary <string, object>;

                context.AddErrorWhenSemiMandatoryFieldNull(values, nameof(Place.Name));
                context.AddErrorWhenSemiMandatoryFieldNull(values, nameof(Place.PostCode));
                context.AddErrorWhenSemiMandatoryFieldNull(values, nameof(Place.LatLong));
                context.AddErrorWhenSemiMandatoryFieldNull(values, nameof(Place.CommunityId));

                if (context.Errors.Any())
                {
                    return(null);
                }

                return(await placeRepository.PartiallyUpdateAsync(values));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "delete",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = nameof(Place.Id).Camelize()
            }),
                resolve: async(context) =>
            {
                var id = context.GetArgument <int>(nameof(Place.Id).Camelize());
                return(await placeRepository.DeleteAsync(id));
            });
        }
Пример #2
0
        public async Task <bool> DeleteAsync(int id, int clientId, int userId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanDeletePlace))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            return(await _placeRepository.DeleteAsync(id));
        }
Пример #3
0
            public async Task <Result <int> > Handle(DeletePlaceCommand command, CancellationToken cancellationToken)
            {
                var item = await _repository.GetByIdAsync(command.Id);

                await _repository.DeleteAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
Пример #4
0
        public async Task DeletePlace(int id)
        {
            var place = await _placeRepository.GetPlaceById(id);

            if (place == null)
            {
                throw new NotFoundException("No place found");
            }
            await _placeRepository.DeleteAsync(place);
        }
        public async Task <Unit> Handle(DeletePlaceCommand request, CancellationToken cancellationToken)
        {
            await _placeRepository.DeleteAsync(request.PlaceId);

            return(Unit.Value);
        }
Пример #6
0
 public async Task DeletePlaceAsync(long id)
 {
     await repository.DeleteAsync(id);
 }