Beispiel #1
0
        public async Task <IActionResult> CreateIncomeCategory(IncomeCategoryDTO incomeCategoryDTO)
        {
            var incomeCategory    = _mapper.Map <IncomeCategory>(incomeCategoryDTO);
            var newIncomeCategory = await _incomeCategoryService.CreateIncomeCategoryAsync(incomeCategory);

            if (newIncomeCategory == null)
            {
                return(BadRequest(new { message = "Category is already exist!" }));
            }
            return(Ok());
        }
Beispiel #2
0
        public async Task <IncomeCategory> UpdateIncomeCategoryAsync(IncomeCategoryDTO incomeCategoryDTO)
        {
            var upToDateIncomeCategory = await _unitOfWork.IncomeCategoryRepository.SingleOrDefaultAsync(u => u.Id == incomeCategoryDTO.Id);

            if (incomeCategoryDTO == null)
            {
                return(null);
            }
            _mapper.Map(incomeCategoryDTO, upToDateIncomeCategory);
            await _unitOfWork.Complete();

            return(upToDateIncomeCategory);
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateIncomeCategory(int id, IncomeCategoryDTO incomeCategoryDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var incomeCategory = await _incomeCategoryService.UpdateIncomeCategoryAsync(incomeCategoryDTO);

            if (incomeCategory == null)
            {
                return(BadRequest(new { message = "Category Id is incorrect!" }));
            }
            return(Ok());
        }
Beispiel #4
0
 public void CreateIncomeCategory(IncomeCategoryDTO incomeCategory)
 {
     db.IncomeCategories.Create(mapper.Map <IncomeCategoryDTO, IncomeCategory>(incomeCategory));
     db.Save();
 }