Ejemplo n.º 1
0
 public CostItemsController(
     ICostItemsRepository costItemsRepository,
     ICostTypesRepository costTypesRepository)
 {
     _costItemsRepository = costItemsRepository;
     _costTypesRepository = costTypesRepository;
 }
Ejemplo n.º 2
0
        private void SetUpCostItemQueries(ICostItemsRepository costItemsRepository, ICostTypesRepository costTypesRepository)
        {
            FieldAsync <CostItemType>(
                "costItem",
                arguments: new QueryArguments(
                    new QueryArgument <GuidGraphType>
            {
                Name = "id"
            }
                    ),
                resolve: async(context) =>
            {
                var costItemId = context.GetArgument <Guid?>("id");

                var costItem = await costItemsRepository.GetById(costItemId.Value);
                var costType = await costTypesRepository.GetById(costItem.CostTypeId);

                return(new CostItemViewModel
                {
                    CostItemId = costItem.CostItemId,
                    ItemName = costItem.ItemName,
                    CostType = ConvertEntityToViewModel(costType),
                    Amount = costItem.Amount,
                    DateUsed = costItem.DateUsed
                });
            });

            FieldAsync <ListGraphType <CostItemType> >(
                "costItems",
                arguments: new QueryArguments(new List <QueryArgument>
            {
                new QueryArgument <IntGraphType>
                {
                    Name = "year"
                },
                new QueryArgument <IntGraphType>
                {
                    Name = "month"
                }
            }),
                resolve: async(context) =>
            {
                var year  = context.GetArgument <int?>("year");
                var month = context.GetArgument <int?>("month");

                if (year.HasValue && month.HasValue)
                {
                    var results = await costItemsRepository.GetRecordsByFilter(year.Value, month.Value);

                    var costTypes = (await costTypesRepository.GetAll()).ToList();

                    return(results.Select(x => ConvertEntityToViewModel(x, costTypes)).OrderByDescending(x => x.DateUsed));
                }

                //throw new ExecutionError("year and month must be provided");

                context.Errors.Add(new ExecutionError($"{string.Join('/', context.Path)}: year and month must be provided"));
                return(new List <CostItemType>());
            });
        }
Ejemplo n.º 3
0
 public CostTypesController(IUnitOfWork unitOfWork, ICostTypesRepository costTypesRepository, IRedisConnectionFactory cache, IMediator mediator)
 {
     _unitOfWork          = unitOfWork;
     _costTypesRepository = costTypesRepository;
     _cache    = cache;
     _mediator = mediator;
 }
Ejemplo n.º 4
0
        public RootMutation(
            ICostTypesRepository costTypesRepository,
            ICostItemsRepository costItemsRepository)
        {
            Name = "Mutation";

            SetUpCostItemMutations(costItemsRepository, costTypesRepository);
        }
Ejemplo n.º 5
0
        public RootQuery(
            ICostTypesRepository costTypesRepository,
            ICostItemsRepository costItemsRepository)
        {
            Name = "Query";

            SetUpCostTypeQueries(costTypesRepository);
            SetUpCostItemQueries(costItemsRepository, costTypesRepository);
            SetUpSecuredQueries();
        }
Ejemplo n.º 6
0
 public CostTypesCommandsHandler(
     ILogger <CostTypesCommandsHandler> logger,
     IIdentityService identityService,
     IUnitOfWork unitOfWork,
     IMapper mapper,
     ICostTypesRepository costTypesConfigurationRepository)
 {
     _unitOfWork          = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
     _logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     _identityService     = identityService ?? throw new ArgumentNullException(nameof(identityService));
     _mapper              = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _costTypesRepository = costTypesConfigurationRepository ?? throw new ArgumentNullException(nameof(costTypesConfigurationRepository));
 }
Ejemplo n.º 7
0
        private void SetUpCostTypeQueries(ICostTypesRepository costTypesRepository)
        {
            FieldAsync <CostTypeType>(
                "costType",
                arguments: new QueryArguments(
                    new QueryArgument <GuidGraphType>
            {
                Name = "id"
            }
                    ),
                resolve: async(context) =>
            {
                var costTypeId = context.GetArgument <Guid?>("id");

                return(ConvertEntityToViewModel(await costTypesRepository.GetById(costTypeId.Value)));
            });

            FieldAsync <ListGraphType <CostTypeType> >(
                "costTypes",
                arguments: new QueryArguments(
                    new QueryArgument <GuidGraphType>
            {
                Name = "id"
            }
                    ),
                resolve: async(context) =>
            {
                var costTypeId = context.GetArgument <Guid?>("id");

                if (costTypeId.HasValue)
                {
                    var costType = await costTypesRepository.GetById(costTypeId.Value);

                    var costTypes = new List <CostType>();

                    if (costType != null)
                    {
                        costTypes.Add(costType);
                    }

                    return(costTypes.Select(ConvertEntityToViewModel));
                }

                return((await costTypesRepository.GetAll()).Select(ConvertEntityToViewModel));
            });
        }
Ejemplo n.º 8
0
 public CostTypesController(ICostTypesRepository costTypesRepository)
 {
     _costTypesRepository = costTypesRepository;
 }
Ejemplo n.º 9
0
        private void SetUpCostItemMutations(ICostItemsRepository costItemsRepository, ICostTypesRepository costTypesRepository)
        {
            FieldAsync <GuidGraphType>(
                "addCostItem",
                "Add Cost Item to the database.",
                new QueryArguments(
                    new QueryArgument <NonNullGraphType <CostItemInputType> >
            {
                Name        = "input",
                Description = "Cost item detail"
            }),
                async(context) =>
            {
                var costItem = context.GetArgument <CostItem>("input");

                var costType = await costTypesRepository.GetById(costItem.CostTypeId);

                if (costType == null)
                {
                    context.Errors.Add(new ExecutionError($"cost Type {costItem.CostTypeId}: not found"));
                    return(null);
                }

                if (await costItemsRepository.GetById(costItem.CostItemId) != null)
                {
                    context.Errors.Add(new ExecutionError($"cost Item Id {costItem.CostItemId}: already exists.  Please provide a new Unique Id"));
                    return(null);
                }

                return((await costItemsRepository.Add(costItem)).CostItemId);
            });
        }