public async Task <IHttpActionResult> CreateAsync([FromBody] TransactionCategoryInputModel inputModel)
        {
            var category = AutoMapper.Mapper.Map <TransactionCategory>(inputModel);
            await _service.AddAsync(category);

            var url = Url.LinkController("transaction-categories", category.Id);

            return(Created(url, category));
        }
Ejemplo n.º 2
0
        private async Task <TransactionCategory> GetCategoryAsync(int?categoryId, string categoryName, TransactionType type)
        {
            TransactionCategory category = null;

            if (categoryId.HasValue)
            {
                category = await _categoriesService.GetAsync(categoryId.Value);
            }

            if (category == null && !string.IsNullOrEmpty(categoryName))
            {
                category = _categoriesService.GetCategory(categoryName, type);

                if (category == null)
                {
                    category = await _categoriesService.AddAsync(new TransactionCategory { Name = categoryName, Type = type });
                }
            }

            return(category);
        }